[hp|network] Add security group rules model, along with tests.

This commit is contained in:
Rupak Ganguly 2013-04-12 00:52:06 -04:00
parent 1b096dd4e7
commit edb5bdc1b7
5 changed files with 120 additions and 0 deletions

View 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

View 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

View File

@ -22,6 +22,8 @@ module Fog
collection :routers
model :security_group
collection :security_groups
model :security_group_rule
collection :security_group_rules
model :subnet
collection :subnets

View 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

View 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