diff --git a/lib/fog/hp/models/network/security_group.rb b/lib/fog/hp/models/network/security_group.rb new file mode 100644 index 000000000..6e20ecc10 --- /dev/null +++ b/lib/fog/hp/models/network/security_group.rb @@ -0,0 +1,30 @@ +require 'fog/core/model' + +module Fog + module HP + class Network + + class SecurityGroup < Fog::Model + identity :id + + attribute :name + attribute :description + attribute :security_group_rules + attribute :tenant_id + + def destroy + requires :id + service.delete_security_group(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(attributes).body['security_group']) + true + end + + end + end + end +end diff --git a/lib/fog/hp/models/network/security_groups.rb b/lib/fog/hp/models/network/security_groups.rb new file mode 100644 index 000000000..e53a723f6 --- /dev/null +++ b/lib/fog/hp/models/network/security_groups.rb @@ -0,0 +1,35 @@ +require 'fog/core/collection' +require 'fog/hp/models/network/security_group' + +module Fog + module HP + class Network + + class SecurityGroups < Fog::Collection + + attribute :filters + + model Fog::HP::Network::SecurityGroup + + def initialize(attributes) + self.filters ||= {} + super + end + + def all(filters = filters) + self.filters = filters + load(service.list_security_groups(filters).body['security_groups']) + end + + def get(security_group_id) + if security_group = service.get_security_group(security_group_id).body['security_group'] + new(security_group) + end + rescue Fog::HP::Network::NotFound + nil + end + + end + end + end +end diff --git a/lib/fog/hp/network.rb b/lib/fog/hp/network.rb index 75eeb5e36..613a8bf91 100644 --- a/lib/fog/hp/network.rb +++ b/lib/fog/hp/network.rb @@ -20,6 +20,8 @@ module Fog collection :ports model :router collection :routers + model :security_group + collection :security_groups model :subnet collection :subnets diff --git a/tests/hp/models/network/security_group_tests.rb b/tests/hp/models/network/security_group_tests.rb new file mode 100644 index 000000000..f9d5ed8b8 --- /dev/null +++ b/tests/hp/models/network/security_group_tests.rb @@ -0,0 +1,20 @@ +Shindo.tests('HP::Network | networking security group model', ['hp', 'networking', 'securitygroup']) do + + model_tests(HP[:network].security_groups, {:name => 'fogsecgroup'}, true) + + tests('success') do + + tests('#create').succeeds do + attributes = {:name => 'my_secgroup', :description => 'my sec group desc'} + @secgroup = HP[:network].security_groups.create(attributes) + @secgroup.wait_for { ready? } unless Fog.mocking? + !@secgroup.id.nil? + end + + tests('#destroy').succeeds do + @secgroup.destroy + end + + end + +end diff --git a/tests/hp/models/network/security_groups_tests.rb b/tests/hp/models/network/security_groups_tests.rb new file mode 100644 index 000000000..b3ddc9296 --- /dev/null +++ b/tests/hp/models/network/security_groups_tests.rb @@ -0,0 +1,20 @@ +Shindo.tests('HP::Network | networking security groups collection', ['hp', 'networking', 'securitygroup']) do + + attributes = {:name => 'my_secgroup', :description => 'my sec group desc'} + collection_tests(HP[:network].security_groups, attributes, true) + + tests('success') do + + attributes = {:name => 'fogsecgroup', :description => 'fog sec group desc'} + @secgroup = HP[:network].security_groups.create(attributes) + + tests('#all(filter)').succeeds do + secgroup = HP[:network].security_groups.all({:name => 'fogsecgroup'}) + secgroup.first.name == 'fogsecgroup' + end + + @secgroup.destroy + + end + +end \ No newline at end of file