diff --git a/lib/fog/aws/ec2.rb b/lib/fog/aws/ec2.rb index 10e506069..126142f2a 100644 --- a/lib/fog/aws/ec2.rb +++ b/lib/fog/aws/ec2.rb @@ -142,6 +142,19 @@ module Fog }.merge!(params), Fog::Parsers::AWS::EC2::DescribeImages.new) end + # Describe all or specified security groups + # + # ==== Parameters + # group_name<~Array>:: List of groups to describe, defaults to all + # + # === Returns + def describe_security_groups(group_name = []) + params = indexed_params('GroupName', group_name) + request({ + 'Action' => 'DescribeSecurityGroups', + }.merge!(params), Fog::Parsers::AWS::EC2::DescribeSecurityGroups.new) + end + # Describe all or specified volumes. # # ==== Parameters @@ -221,6 +234,8 @@ module Fog :method => 'POST' }) + p response + if parser && !response.body.empty? Nokogiri::XML::SAX::Parser.new(parser).parse(response.body.split(/<\?xml.*\?>/)[1]) response.body = parser.response diff --git a/lib/fog/aws/ec2/parsers.rb b/lib/fog/aws/ec2/parsers.rb index aa2ef01a2..e90669d1d 100644 --- a/lib/fog/aws/ec2/parsers.rb +++ b/lib/fog/aws/ec2/parsers.rb @@ -122,6 +122,88 @@ module Fog end + class DescribeSecurityGroups < Fog::Parsers::Base + + def reset + @group = {} + @ip_permission = { :groups => [], :ip_ranges => []} + @ip_range = {} + @in_ip_permissions = false + @item = { :ip_permissions => [] } + @response = { :security_group_info => [] } + end + + def start_element(name, attrs = []) + if name == 'ipPermissions' + @in_ip_permissions = true + end + if name == 'groups' + @in_groups = true + end + if name == 'ip_ranges' + @in_ip_ranges = true + end + @value = '' + end + + def end_element(name) + if !@in_ip_permissions + case name + when 'groupName' + @item[:group_name] = @value + when 'groupDescription' + @item[:group_description] = @value + when 'item' + @response[:security_group_info] << @item + @item = { :ip_permissions => [] } + when 'ownerId' + @item[:owner_id] = @value + end + elsif @in_groups + case name + when 'groupName' + @group[:group_name] = @value + when 'groups' + @in_groups = false + when 'item' + unless @group == {} + @ip_permission[:groups] << @group + end + @group = {} + when 'userId' + @group[:user_id] = @value + end + elsif @in_ip_ranges + case name + when 'cidrIp' + @ip_range[:cidr_ip] = @value + when 'ipRanges' + @in_ip_ranges = false + when 'item' + unless @ip_range == {} + @ip_permission[:ip_ranges] << @ip_range + end + @ip_range = {} + end + elsif @in_ip_permissions + case name + when 'fromPort' + @item[:from_port] = @value + when 'item' + @item[:ip_permissions] << @ip_permission + @ip_permission = { :groups => [], :ip_ranges => []} + when 'ipProtocol' + @ip_permission[:ip_protocol] = @value + when 'ipPermissions' + @in_ip_permissions = false + when 'toPort' + @item[:to_port] = @value + end + end + end + + end + class DescribeVolumes < Fog::Parsers::Base def reset @@ -131,6 +213,13 @@ module Fog @volume = { :attachment_set => [] } end + def start_element(name, attrs = []) + if name == 'attachmentSet' + @in_attachment_set = true + end + @value = '' + end + def end_element(name) if @in_attachment_set case name @@ -173,13 +262,6 @@ module Fog end end - def start_element(name, attrs = []) - if name == 'attachmentSet' - @in_attachment_set = true - end - @value = '' - end - end end diff --git a/spec/aws/ec2/describe_security_groups_spec.rb b/spec/aws/ec2/describe_security_groups_spec.rb new file mode 100644 index 000000000..1e291a77e --- /dev/null +++ b/spec/aws/ec2/describe_security_groups_spec.rb @@ -0,0 +1,12 @@ +require File.dirname(__FILE__) + '/../../spec_helper' + +describe 'EC2.describe_security_groups' do + + it "should return proper attributes with no params" do + actual = ec2.describe_security_groups + p actual + end + + it "should return proper attributes with params" + +end