From de807f03b1890ea0fe65f98852e607a0d284e762 Mon Sep 17 00:00:00 2001 From: MaF Date: Tue, 20 Mar 2012 08:49:49 +0100 Subject: [PATCH] Changes to the security group handling: * CreateSecurityGroup now includes the group id in the reply, this patch makes the code store this * The patch also changes the delete call to use the group id if present (since you must use the id when deleting VPC groups) --- lib/fog/aws/models/compute/security_group.rb | 11 +++++++++- .../parsers/compute/create_security_group.rb | 20 +++++++++++++++++++ .../requests/compute/create_security_group.rb | 7 ++++--- 3 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 lib/fog/aws/parsers/compute/create_security_group.rb diff --git a/lib/fog/aws/models/compute/security_group.rb b/lib/fog/aws/models/compute/security_group.rb index 5793226f8..b5805b7aa 100644 --- a/lib/fog/aws/models/compute/security_group.rb +++ b/lib/fog/aws/models/compute/security_group.rb @@ -1,5 +1,8 @@ require 'fog/core/model' +# XXX +require 'pp' + module Fog module Compute class AWS @@ -101,7 +104,11 @@ module Fog def destroy requires :name - connection.delete_security_group(name) + if group_id.nil? + connection.delete_security_group(name) + else + connection.delete_security_group(nil, group_id) + end true end @@ -195,6 +202,8 @@ module Fog def save requires :description, :name data = connection.create_security_group(name, description, vpc_id).body + new_attributes = data.reject {|key,value| key == 'requestId'} + merge_attributes(new_attributes) true end diff --git a/lib/fog/aws/parsers/compute/create_security_group.rb b/lib/fog/aws/parsers/compute/create_security_group.rb new file mode 100644 index 000000000..e872d57ce --- /dev/null +++ b/lib/fog/aws/parsers/compute/create_security_group.rb @@ -0,0 +1,20 @@ +module Fog + module Parsers + module Compute + module AWS + + class CreateSecurityGroup < Fog::Parsers::Base + + def end_element(name) + case name + when 'requestId', 'return', 'groupId' + @response[name] = value + end + end + + end + + end + end + end +end diff --git a/lib/fog/aws/requests/compute/create_security_group.rb b/lib/fog/aws/requests/compute/create_security_group.rb index e1a621005..b38c0bb4e 100644 --- a/lib/fog/aws/requests/compute/create_security_group.rb +++ b/lib/fog/aws/requests/compute/create_security_group.rb @@ -3,7 +3,7 @@ module Fog class AWS class Real - require 'fog/aws/parsers/compute/basic' + require 'fog/aws/parsers/compute/create_security_group' # Create a new security group # @@ -17,6 +17,7 @@ module Fog # * body<~Hash>: # * 'requestId'<~String> - Id of request # * 'return'<~Boolean> - success? + # * 'groupId'<~String> - Id of created group # # {Amazon API Reference}[http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-CreateSecurityGroup.html] def create_security_group(name, description, vpc_id=nil) @@ -24,8 +25,8 @@ module Fog 'Action' => 'CreateSecurityGroup', 'GroupName' => name, 'GroupDescription' => description, - :parser => Fog::Parsers::Compute::AWS::Basic.new, - 'VpcId' => vpc_id + 'VpcId' => vpc_id, + :parser => Fog::Parsers::Compute::AWS::CreateSecurityGroup.new ) end