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

Enable and implement create, get and delete security group methods for compute service.

This commit is contained in:
Rupak Ganguly 2011-12-01 15:42:33 -05:00
parent 950fc37af8
commit c3058e86f3
4 changed files with 87 additions and 13 deletions

View file

@ -31,6 +31,7 @@ module Fog
request :delete_server request :delete_server
request :get_flavor_details request :get_flavor_details
request :get_image_details request :get_image_details
request :get_security_group
request :get_server_details request :get_server_details
request :list_addresses request :list_addresses
request :list_private_addresses request :list_private_addresses

View file

@ -6,18 +6,27 @@ module Fog
# Create a new security group # Create a new security group
# #
# ==== Parameters # ==== Parameters
# * name<~String> - name of the security group # * 'name'<~String> - name of the security group
# * description<~String> - description of the security group # * 'description'<~String> - description of the security group
# #
# ==== Returns # ==== Returns
# * response<~Excon::Response>: # * response<~Excon::Response>:
# * body<~Hash>: # * body<~Hash>:
# * 'keypair'<~Hash> - The keypair data # * 'security_group'<~Array>:
# * 'public_key'<~String> - The public key for the keypair # * 'rules'<~Array>: - array of security group rules
# * 'private_key'<~String> - The private key for the keypair # * 'id'<~Integer> - id of the security group rule
# * 'user_id'<~String> - The user id # * 'from_port'<~Integer> - start port for rule i.e. 22 (or -1 for ICMP wildcard)
# * 'fingerprint'<~String> - SHA-1 digest of DER encoded private key # * 'to_port'<~Integer> - end port for rule i.e. 22 (or -1 for ICMP wildcard)
# * 'name'<~String> - Name of key # * 'ip_protocol'<~String> - ip protocol for rule, must be in ['tcp', 'udp', 'icmp']
# * 'group'<~Hash>:
# * Undefined
# * 'parent_group_id'<~Integer> - parent group id
# * 'ip_range'<~Hash>:
# * 'cidr'<~String> - ip range address i.e. '0.0.0.0/0'
# * 'id'<~Integer> - id of the security group
# * 'name'<~String> - name of the security group
# * 'description'<~String> - description of the security group
# * 'tenant_id'<~String> - tenant id of the user
# #
# {Openstack API Reference}[http://docs.openstack.org] # {Openstack API Reference}[http://docs.openstack.org]
def create_security_group(name, description) def create_security_group(name, description)

View file

@ -8,6 +8,8 @@ module Fog
# ==== Parameters # ==== Parameters
# * id<~Integer> - Id of the security group to delete # * id<~Integer> - Id of the security group to delete
# #
#
# {Openstack API Reference}[http://docs.openstack.org]
def delete_security_group(security_group_id) def delete_security_group(security_group_id)
request( request(
:expects => 202, :expects => 202,
@ -22,11 +24,15 @@ module Fog
def delete_security_group(security_group_id) def delete_security_group(security_group_id)
response = Excon::Response.new response = Excon::Response.new
if self.data[:security_groups].include? (security_group_id)
self.data[:last_modified][:security_groups].delete(security_group_id) self.data[:last_modified][:security_groups].delete(security_group_id)
self.data[:security_groups].delete(security_group_id) self.data[:security_groups].delete(security_group_id)
response.status = 202 response.status = 202
response.body = "202 Accepted\n\nThe request is accepted for processing.\n\n " response.body = "202 Accepted\n\nThe request is accepted for processing.\n\n "
response response
else
raise Fog::Compute::HP::NotFound
end
end end
end end

View file

@ -0,0 +1,58 @@
module Fog
module Compute
class HP
class Real
# Get details about a security group
#
# ==== Parameters
# * 'security_group_id'<~Integer> - Id of security group to get details for
#
# ==== Returns
# * response<~Excon::Response>:
# * body<~Hash>:
# * 'security_group'<~Array>:
# * 'rules'<~Array>: - array of security group rules
# * 'id'<~Integer> - id of the security group rule
# * 'from_port'<~Integer> - start port for rule i.e. 22 (or -1 for ICMP wildcard)
# * 'to_port'<~Integer> - end port for rule i.e. 22 (or -1 for ICMP wildcard)
# * 'ip_protocol'<~String> - ip protocol for rule, must be in ['tcp', 'udp', 'icmp']
# * 'group'<~Hash>:
# * Undefined
# * 'parent_group_id'<~Integer> - parent group id
# * 'ip_range'<~Hash>:
# * 'cidr'<~String> - ip range address i.e. '0.0.0.0/0'
# * 'id'<~Integer> - id of the security group
# * 'name'<~String> - name of the security group
# * 'description'<~String> - description of the security group
# * 'tenant_id'<~String> - tenant id of the user
#
# {Openstack API Reference}[http://docs.openstack.org]
def get_security_group(security_group_id)
request(
:expects => [200],
:method => 'GET',
:path => "os-security-groups/#{security_group_id}"
)
end
end
class Mock
def get_security_group(security_group_id)
response = Excon::Response.new
if self.data[:security_groups].include? (security_group_id)
sec_group = self.data[:security_groups]['#{security_group_id}']
response.status = 200
response.body = { 'security_group' => sec_group }
response
else
raise Fog::Compute::HP::NotFound
end
end
end
end
end
end