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:
parent
aceed44d89
commit
1b096dd4e7
5 changed files with 107 additions and 0 deletions
30
lib/fog/hp/models/network/security_group.rb
Normal file
30
lib/fog/hp/models/network/security_group.rb
Normal 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
|
35
lib/fog/hp/models/network/security_groups.rb
Normal file
35
lib/fog/hp/models/network/security_groups.rb
Normal 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
|
|
@ -20,6 +20,8 @@ module Fog
|
|||
collection :ports
|
||||
model :router
|
||||
collection :routers
|
||||
model :security_group
|
||||
collection :security_groups
|
||||
model :subnet
|
||||
collection :subnets
|
||||
|
||||
|
|
20
tests/hp/models/network/security_group_tests.rb
Normal file
20
tests/hp/models/network/security_group_tests.rb
Normal 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
|
20
tests/hp/models/network/security_groups_tests.rb
Normal file
20
tests/hp/models/network/security_groups_tests.rb
Normal 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
|
Loading…
Reference in a new issue