diff --git a/lib/fog/hp/compute.rb b/lib/fog/hp/compute.rb index 45e66cbb0..b726de999 100644 --- a/lib/fog/hp/compute.rb +++ b/lib/fog/hp/compute.rb @@ -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 diff --git a/lib/fog/hp/requests/compute/create_security_group.rb b/lib/fog/hp/requests/compute/create_security_group.rb index 9ef3a0230..3433fba82 100644 --- a/lib/fog/hp/requests/compute/create_security_group.rb +++ b/lib/fog/hp/requests/compute/create_security_group.rb @@ -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) diff --git a/lib/fog/hp/requests/compute/delete_security_group.rb b/lib/fog/hp/requests/compute/delete_security_group.rb index beb6ff044..0e1b397c2 100644 --- a/lib/fog/hp/requests/compute/delete_security_group.rb +++ b/lib/fog/hp/requests/compute/delete_security_group.rb @@ -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 diff --git a/lib/fog/hp/requests/compute/get_security_group.rb b/lib/fog/hp/requests/compute/get_security_group.rb new file mode 100644 index 000000000..d8c1eccdc --- /dev/null +++ b/lib/fog/hp/requests/compute/get_security_group.rb @@ -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