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

first pass at describe security groups

This commit is contained in:
Wesley Beary 2009-07-04 11:27:14 -07:00
parent d40995dd17
commit 2180a50662
3 changed files with 116 additions and 7 deletions

View file

@ -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

View file

@ -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

View file

@ -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