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

Enable and implement delete security group rules for compute service.

This commit is contained in:
Rupak Ganguly 2011-12-05 19:04:01 -05:00
parent 7dd307b6ad
commit 9cf629bc74
3 changed files with 53 additions and 5 deletions

View file

@ -31,6 +31,7 @@ module Fog
request :delete_image
request :delete_key_pair
request :delete_security_group
request :delete_security_group_rule
request :delete_server
request :get_flavor_details
request :get_image_details

View file

@ -44,21 +44,22 @@ module Fog
def create_security_group_rule(parent_group_id, ip_protocol, from_port, to_port, cidr, group_id=nil)
response = Excon::Response.new
if self.data[:security_groups].has_key?("#{parent_group_id}")
group = self.data[:security_groups]["#{parent_group_id}"]
if group
group['rules'] ||= {}
response.status = 200
data = {
'from_port' => from_port,
'group' => {},
'ip_protocol' => ip_protocol,
'to_port' => to_port,
'parent_group_id' => parent_group_id,
'parent_group_id' => parent_group_id.to_s,
'ip_range' => {
'cidr' => cidr
},
'id' => Fog::Mock.random_numbers(3),
'id' => Fog::Mock.random_numbers(3).to_s,
}
self.data[:security_groups]["#{parent_group_id}"]['rules'] = data
group['rules'][data['id']] = data
response.body = { 'security_group_rule' => data }
response

View file

@ -0,0 +1,46 @@
module Fog
module Compute
class HP
class Real
# Delete a security group rule
#
# ==== Parameters
# * id<~Integer> - id of the security group rule to delete
#
# {Openstack API Reference}[http://docs.openstack.org]
def delete_security_group_rule(security_group_rule_id)
request(
:expects => 202,
:method => 'DELETE',
:path => "os-security-group-rules/#{security_group_rule_id}"
)
end
end
class Mock
def delete_security_group_rule(security_group_rule_id)
response = Excon::Response.new
sg_rule = nil
self.data[:security_groups].each do |skey, sv|
if sv['rules']
sg_rule = sv['rules'].select { |r| r == security_group_rule_id }
end
end
unless sg_rule.empty?
self.data[:security_groups]["#{sg_rule.values.first['parent_group_id']}"]['rules'].delete(security_group_rule_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
end
end
end