1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

[hp|network] Add models for security groups, along with tests.

This commit is contained in:
Rupak Ganguly 2013-04-08 16:53:05 -04:00
parent aceed44d89
commit 1b096dd4e7
5 changed files with 107 additions and 0 deletions

View file

@ -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

View file

@ -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

View file

@ -20,6 +20,8 @@ module Fog
collection :ports
model :router
collection :routers
model :security_group
collection :security_groups
model :subnet
collection :subnets

View file

@ -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

View file

@ -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