diff --git a/lib/fog/aws/models/compute/security_group.rb b/lib/fog/aws/models/compute/security_group.rb index 5793226f8..fa03d74e8 100644 --- a/lib/fog/aws/models/compute/security_group.rb +++ b/lib/fog/aws/models/compute/security_group.rb @@ -101,7 +101,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 +199,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..22f887320 --- /dev/null +++ b/lib/fog/aws/parsers/compute/create_security_group.rb @@ -0,0 +1,24 @@ +module Fog + module Parsers + module Compute + module AWS + + class CreateSecurityGroup < Fog::Parsers::Base + + def end_element(name) + case name + when 'return' + if value == 'true' + @response[name] = true + else + @response[name] = false + end + when 'requestId', '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..509acdd97 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 @@ -48,6 +49,7 @@ module Fog self.data[:security_groups][name] = data response.body = { 'requestId' => Fog::AWS::Mock.request_id, + 'groupId' => data['groupId'], 'return' => true } response diff --git a/tests/aws/requests/compute/security_group_tests.rb b/tests/aws/requests/compute/security_group_tests.rb index 20270d2a8..aaba70028 100644 --- a/tests/aws/requests/compute/security_group_tests.rb +++ b/tests/aws/requests/compute/security_group_tests.rb @@ -1,4 +1,9 @@ Shindo.tests('Fog::Compute[:aws] | security group requests', ['aws']) do + @create_security_group_format = { + 'requestId' => String, + 'groupId' => String, + 'return' => Fog::Boolean + } @security_groups_format = { 'requestId' => String, @@ -23,11 +28,11 @@ Shindo.tests('Fog::Compute[:aws] | security group requests', ['aws']) do tests('success') do - tests("#create_security_group('fog_security_group', 'tests group')").formats(AWS::Compute::Formats::BASIC) do + tests("#create_security_group('fog_security_group', 'tests group')").formats(@create_security_group_format) do Fog::Compute[:aws].create_security_group('fog_security_group', 'tests group').body end - tests("#create_security_group('fog_security_group_two', 'tests group')").formats(AWS::Compute::Formats::BASIC) do + tests("#create_security_group('fog_security_group_two', 'tests group')").formats(@create_security_group_format) do Fog::Compute[:aws].create_security_group('fog_security_group_two', 'tests group').body end @@ -264,7 +269,7 @@ Shindo.tests('Fog::Compute[:aws] | security group requests', ['aws']) do vpc_id = Fog::Compute[:aws].create_vpc('10.255.254.64/28').body['vpcSet'].first['vpcId'] # Create security group in VPC - tests("#create_security_group('vpc_security_group', 'tests group')").formats(AWS::Compute::Formats::BASIC) do + tests("#create_security_group('vpc_security_group', 'tests group')").formats(@create_security_group_format) do Fog::Compute[:aws].create_security_group('vpc_security_group', 'tests group', vpc_id).body end