mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[hp|network] Add security group rules model, along with tests.
This commit is contained in:
parent
1b096dd4e7
commit
edb5bdc1b7
5 changed files with 120 additions and 0 deletions
35
lib/fog/hp/models/network/security_group_rule.rb
Normal file
35
lib/fog/hp/models/network/security_group_rule.rb
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
require 'fog/core/model'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module HP
|
||||||
|
class Network
|
||||||
|
|
||||||
|
class SecurityGroupRule < Fog::Model
|
||||||
|
identity :id
|
||||||
|
|
||||||
|
attribute :security_group_id
|
||||||
|
attribute :direction
|
||||||
|
attribute :protocol
|
||||||
|
attribute :port_range_min
|
||||||
|
attribute :port_range_max
|
||||||
|
attribute :remote_ip_prefix
|
||||||
|
attribute :ethertype
|
||||||
|
attribute :remote_group_id
|
||||||
|
attribute :tenant_id
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
requires :id
|
||||||
|
service.delete_security_group_rule(id)
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def save
|
||||||
|
raise Fog::Errors::Error.new('Resaving an existing object may create a duplicate') if persisted?
|
||||||
|
merge_attributes(service.create_security_group_rule(security_group_id, direction, attributes).body['security_group_rule'])
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
35
lib/fog/hp/models/network/security_group_rules.rb
Normal file
35
lib/fog/hp/models/network/security_group_rules.rb
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
require 'fog/core/collection'
|
||||||
|
require 'fog/hp/models/network/security_group_rule'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module HP
|
||||||
|
class Network
|
||||||
|
|
||||||
|
class SecurityGroupRules < Fog::Collection
|
||||||
|
|
||||||
|
attribute :filters
|
||||||
|
|
||||||
|
model Fog::HP::Network::SecurityGroupRule
|
||||||
|
|
||||||
|
def initialize(attributes)
|
||||||
|
self.filters ||= {}
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def all(filters = filters)
|
||||||
|
self.filters = filters
|
||||||
|
load(service.list_security_group_rules(filters).body['security_group_rules'])
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(sec_group_rule_id)
|
||||||
|
if sec_group_rule = service.get_security_group_rule(sec_group_rule_id).body['security_group_rule']
|
||||||
|
new(sec_group_rule)
|
||||||
|
end
|
||||||
|
rescue Fog::HP::Network::NotFound
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -22,6 +22,8 @@ module Fog
|
||||||
collection :routers
|
collection :routers
|
||||||
model :security_group
|
model :security_group
|
||||||
collection :security_groups
|
collection :security_groups
|
||||||
|
model :security_group_rule
|
||||||
|
collection :security_group_rules
|
||||||
model :subnet
|
model :subnet
|
||||||
collection :subnets
|
collection :subnets
|
||||||
|
|
||||||
|
|
25
tests/hp/models/network/security_group_rule_tests.rb
Normal file
25
tests/hp/models/network/security_group_rule_tests.rb
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
Shindo.tests('HP::Network | networking security group rule model', ['hp', 'networking', 'securitygroup']) do
|
||||||
|
|
||||||
|
@secgroup = HP[:network].security_groups.create({:name => 'fogsecgroup'})
|
||||||
|
|
||||||
|
attributes = {:security_group_id => @secgroup.id, :direction => 'ingress'}
|
||||||
|
model_tests(HP[:network].security_group_rules, attributes, true)
|
||||||
|
|
||||||
|
tests('success') do
|
||||||
|
|
||||||
|
tests('#create').succeeds do
|
||||||
|
attributes = {:security_group_id => @secgroup.id, :direction => 'ingress', :protocol => 'tcp',
|
||||||
|
:port_range_min => 22, :port_range_max => 22, :remote_ip_prefix => '0.0.0.0/0'}
|
||||||
|
@secgrouprule = HP[:network].security_group_rules.create(attributes)
|
||||||
|
@secgrouprule.wait_for { ready? } unless Fog.mocking?
|
||||||
|
!@secgrouprule.id.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
tests('#destroy').succeeds do
|
||||||
|
@secgrouprule.destroy
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
@secgroup.destroy
|
||||||
|
end
|
23
tests/hp/models/network/security_group_rules_tests.rb
Normal file
23
tests/hp/models/network/security_group_rules_tests.rb
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
Shindo.tests('HP::Network | networking security group rules collection', ['hp', 'networking', 'securitygroup']) do
|
||||||
|
|
||||||
|
@secgroup = HP[:network].security_groups.create({:name => 'my_secgroup'})
|
||||||
|
|
||||||
|
attributes = {:security_group_id => @secgroup.id, :direction => 'ingress'}
|
||||||
|
collection_tests(HP[:network].security_group_rules, attributes, true)
|
||||||
|
|
||||||
|
tests('success') do
|
||||||
|
|
||||||
|
attributes = {:security_group_id => @secgroup.id, :direction => 'ingress', :protocol => 'tcp',
|
||||||
|
:port_range_min => 22, :port_range_max => 22, :remote_ip_prefix => '0.0.0.0/0'}
|
||||||
|
@secgrouprule = HP[:network].security_group_rules.create(attributes)
|
||||||
|
|
||||||
|
tests('#all(filter)').succeeds do
|
||||||
|
secgrouprule = HP[:network].security_group_rules.all({:direction => 'ingress'})
|
||||||
|
secgrouprule.first.direction == 'ingress'
|
||||||
|
end
|
||||||
|
|
||||||
|
@secgrouprule.destroy
|
||||||
|
end
|
||||||
|
|
||||||
|
@secgroup.destroy
|
||||||
|
end
|
Loading…
Reference in a new issue