mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Enable and implemented create_security_groups method for request layer for compute services.
This commit is contained in:
parent
bfadebf62a
commit
48099f8522
2 changed files with 79 additions and 1 deletions
|
@ -23,6 +23,7 @@ module Fog
|
|||
#request :confirm_resized_server
|
||||
request :create_image
|
||||
request :create_key_pair
|
||||
request :create_security_group
|
||||
request :create_server
|
||||
request :delete_image
|
||||
request :delete_key_pair
|
||||
|
@ -61,7 +62,16 @@ module Fog
|
|||
},
|
||||
:images => {},
|
||||
:key_pairs => {},
|
||||
:security_groups => {},
|
||||
:security_groups => {
|
||||
'default' => {
|
||||
'id' => Fog::Mock.random_numbers(3),
|
||||
'name' => "default",
|
||||
'description' => "default security group",
|
||||
'tenant_id' => Fog::HP::Mock.user_id,
|
||||
'rules' => [ {"from_port"=>22, "group"=>{}, "ip_protocol"=>"tcp", "to_port"=>22, "parent_group_id"=>"#{Fog::Mock.random_numbers(3)}", "ip_range"=>{ "cidr"=>"0.0.0.0/0" }, "id"=>"#{Fog::Mock.random_numbers(3)}"},
|
||||
{"from_port"=>-1, "group"=>{}, "ip_protocol"=>"icmp", "to_port"=>-1, "parent_group_id"=>"#{Fog::Mock.random_numbers(3)}", "ip_range"=>{ "cidr"=>"0.0.0.0/0" }, "id"=>"#{Fog::Mock.random_numbers(3)}"} ]
|
||||
}
|
||||
},
|
||||
:servers => {}
|
||||
}
|
||||
end
|
||||
|
|
68
lib/fog/hp/requests/compute/create_security_group.rb
Normal file
68
lib/fog/hp/requests/compute/create_security_group.rb
Normal file
|
@ -0,0 +1,68 @@
|
|||
module Fog
|
||||
module Compute
|
||||
class HP
|
||||
class Real
|
||||
|
||||
# Create a new security group
|
||||
#
|
||||
# ==== Parameters
|
||||
# * name<~String> - name of the security group
|
||||
# * description<~String> - description of the security group
|
||||
#
|
||||
# ==== Returns
|
||||
# * response<~Excon::Response>:
|
||||
# * body<~Hash>:
|
||||
# * 'keypair'<~Hash> - The keypair data
|
||||
# * 'public_key'<~String> - The public key for the keypair
|
||||
# * 'private_key'<~String> - The private key for the keypair
|
||||
# * 'user_id'<~String> - The user id
|
||||
# * 'fingerprint'<~String> - SHA-1 digest of DER encoded private key
|
||||
# * 'name'<~String> - Name of key
|
||||
#
|
||||
# {Openstack API Reference}[http://docs.openstack.org]
|
||||
def create_security_group(name, description)
|
||||
data = {
|
||||
'security_group' => {
|
||||
'name' => name,
|
||||
'description' => description || "#{name} security group"
|
||||
}
|
||||
}
|
||||
|
||||
request(
|
||||
:body => MultiJson.encode(data),
|
||||
:expects => 200,
|
||||
:method => 'POST',
|
||||
:path => 'os-security-groups.json'
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
class Mock
|
||||
|
||||
def create_security_group(name, description)
|
||||
response = Excon::Response.new
|
||||
unless self.data[:security_groups][name]
|
||||
response.status = 200
|
||||
data = {
|
||||
'id' => Fog::Mock.random_numbers(3),
|
||||
'name' => name,
|
||||
'description' => description || "#{name} security group",
|
||||
'tenant_id' => Fog::HP::Mock.user_id,
|
||||
'rules' => []
|
||||
}
|
||||
self.data[:last_modified][:security_groups][name] = Time.now
|
||||
self.data[:security_groups][name] = data
|
||||
|
||||
response.body = { 'security_group' => data }
|
||||
response
|
||||
else
|
||||
raise Fog::Compute::HP::Error.new("InvalidSecurityGroup.Duplicate => The security group '#{name}' already exists")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Reference in a new issue