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:
parent
950fc37af8
commit
c3058e86f3
4 changed files with 87 additions and 13 deletions
|
@ -31,6 +31,7 @@ module Fog
|
|||
request :delete_server
|
||||
request :get_flavor_details
|
||||
request :get_image_details
|
||||
request :get_security_group
|
||||
request :get_server_details
|
||||
request :list_addresses
|
||||
request :list_private_addresses
|
||||
|
|
|
@ -6,18 +6,27 @@ module Fog
|
|||
# Create a new security group
|
||||
#
|
||||
# ==== Parameters
|
||||
# * name<~String> - name of the security group
|
||||
# * description<~String> - description of the security group
|
||||
# * '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
|
||||
# * '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 create_security_group(name, description)
|
||||
|
|
|
@ -8,6 +8,8 @@ module Fog
|
|||
# ==== Parameters
|
||||
# * id<~Integer> - Id of the security group to delete
|
||||
#
|
||||
#
|
||||
# {Openstack API Reference}[http://docs.openstack.org]
|
||||
def delete_security_group(security_group_id)
|
||||
request(
|
||||
:expects => 202,
|
||||
|
@ -22,11 +24,15 @@ module Fog
|
|||
|
||||
def delete_security_group(security_group_id)
|
||||
response = Excon::Response.new
|
||||
self.data[:last_modified][:security_groups].delete(security_group_id)
|
||||
self.data[:security_groups].delete(security_group_id)
|
||||
response.status = 202
|
||||
response.body = "202 Accepted\n\nThe request is accepted for processing.\n\n "
|
||||
response
|
||||
if self.data[:security_groups].include? (security_group_id)
|
||||
self.data[:last_modified][:security_groups].delete(security_group_id)
|
||||
self.data[:security_groups].delete(security_group_id)
|
||||
response.status = 202
|
||||
response.body = "202 Accepted\n\nThe request is accepted for processing.\n\n "
|
||||
response
|
||||
else
|
||||
raise Fog::Compute::HP::NotFound
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
58
lib/fog/hp/requests/compute/get_security_group.rb
Normal file
58
lib/fog/hp/requests/compute/get_security_group.rb
Normal 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
|
Loading…
Reference in a new issue