lib/ec2/ec2.rb in aws-2.4.5 vs lib/ec2/ec2.rb in aws-2.5.0
- old
+ new
@@ -87,13 +87,14 @@
def self.connection_name
:ec2_connection
end
@@bench = AwsBenchmarkingBlock.new
- def self.bench
+ def self.bench
@@bench
end
+
def self.bench_xml
@@bench.xml
end
def self.bench_ec2
@@ -401,30 +402,10 @@
result
rescue Exception
on_exception
end
- def describe_availability_zones(options={})
- link = generate_request("DescribeAvailabilityZones", options={})
- request_info_xml_simple(self.class.connection_name, @params, link, @logger,
- :group_tags =>{"DBInstances" =>"DBInstance",
- "DBParameterGroups"=>"DBParameterGroup",
- "DBSecurityGroups" =>"DBSecurityGroup",
- "EC2SecurityGroups"=>"EC2SecurityGroup",
- "IPRanges" =>"IPRange"},
- :force_array =>["DBInstances",
- "DBParameterGroups",
- "DBSecurityGroups",
- "EC2SecurityGroups",
- "IPRanges"],
- :pull_out_array =>options[:pull_out_array],
- :pull_out_single=>options[:pull_out_single],
- :wrapper =>options[:wrapper])
- rescue Exception
- on_exception
- end
-
# Retrieve information about EC2 instances. If +list+ is omitted then returns the
# list of all instances.
#
# ec2.describe_instances #=>
# [{:aws_image_id => "ami-e444444d",
@@ -446,11 +427,11 @@
# :monitoring_state => ...,
# ..., {...}]
#
def describe_instances(list=[])
link = generate_request("DescribeInstances", hash_params('InstanceId', list.to_a))
- request_cache_or_info(:describe_instances, link, QEc2DescribeInstancesParser, @@bench, list.blank?) do |parser|
+ request_cache_or_info(:describe_instances, link, QEc2DescribeInstancesParser, @@bench, list.nil? || list.empty?) do |parser|
get_desc_instances(parser.result)
end
rescue Exception
on_exception
end
@@ -558,28 +539,41 @@
'MinCount' => (options[:min_count] || 1).to_s,
'MaxCount' => (options[:max_count] || 1).to_s,
'AddressingType' => options[:addressing_type] || DEFAULT_ADDRESSING_TYPE,
'InstanceType' => options[:instance_type] || DEFAULT_INSTANCE_TYPE})
# optional params
- params['KeyName'] = options[:key_name] unless options[:key_name].blank?
- params['KernelId'] = options[:kernel_id] unless options[:kernel_id].blank?
- params['RamdiskId'] = options[:ramdisk_id] unless options[:ramdisk_id].blank?
- params['Placement.AvailabilityZone'] = options[:availability_zone] unless options[:availability_zone].blank?
- params['BlockDeviceMappings'] = options[:block_device_mappings] unless options[:block_device_mappings].blank?
- params['Monitoring.Enabled'] = options[:monitoring_enabled] unless options[:monitoring_enabled].blank?
- params['SubnetId'] = options[:subnet_id] unless options[:subnet_id].blank?
- params['AdditionalInfo'] = options[:additional_info] unless options[:additional_info].blank?
+ params['KeyName'] = options[:key_name] unless Aws::Utils.blank?(options[:key_name])
+ params['KernelId'] = options[:kernel_id] unless Aws::Utils.blank?(options[:kernel_id])
+ params['RamdiskId'] = options[:ramdisk_id] unless Aws::Utils.blank?(options[:ramdisk_id])
+ params['Placement.AvailabilityZone'] = options[:availability_zone] unless Aws::Utils.blank?(options[:availability_zone])
+ params['BlockDeviceMappings'] = options[:block_device_mappings] unless Aws::Utils.blank?(options[:block_device_mappings])
+ params['Monitoring.Enabled'] = options[:monitoring_enabled] unless Aws::Utils.blank?(options[:monitoring_enabled])
+ params['SubnetId'] = options[:subnet_id] unless Aws::Utils.blank?(options[:subnet_id])
+ params['AdditionalInfo'] = options[:additional_info] unless Aws::Utils.blank?(options[:additional_info])
params['DisableApiTermination'] = options[:disable_api_termination].to_s unless options[:disable_api_termination].nil?
- params['InstanceInitiatedShutdownBehavior'] = options[:instance_initiated_shutdown_behavior] unless options[:instance_initiated_shutdown_behavior].blank?
- unless options[:user_data].blank?
+ params['InstanceInitiatedShutdownBehavior'] = options[:instance_initiated_shutdown_behavior] unless Aws::Utils.blank?(options[:instance_initiated_shutdown_behavior])
+ unless Aws::Utils.blank?(options[:user_data])
options[:user_data].strip!
# Do not use CGI::escape(encode64(...)) as it is done in Amazons EC2 library.
# Amazon 169.254.169.254 does not like escaped symbols!
# And it doesn't like "\n" inside of encoded string! Grrr....
# Otherwise, some of UserData symbols will be lost...
- params['UserData'] = Base64.encode64(options[:user_data]).delete("\n").strip unless options[:user_data].blank?
+ params['UserData'] = Base64.encode64(options[:user_data]).delete("\n").strip unless Aws::Utils.blank?(options[:user_data])
end
+ unless options[:block_device_mappings].blank?
+ options[:block_device_mappings].size.times do |n|
+ if options[:block_device_mappings][n][:virtual_name]
+ params["BlockDeviceMapping.#{n+1}.VirtualName"] = options[:block_device_mappings][n][:virtual_name]
+ end
+ if options[:block_device_mappings][n][:device_name]
+ params["BlockDeviceMapping.#{n+1}.DeviceName"] = options[:block_device_mappings][n][:device_name]
+ end
+ if options[:block_device_mappings][n][:ebs_snapshot_id]
+ params["BlockDeviceMapping.#{n+1}.Ebs.SnapshotId"] = options[:block_device_mappings][n][:ebs_snapshot_id]
+ end
+ end
+ end
link = generate_request("RunInstances", params)
#debugger
instances = request_info(link, QEc2DescribeInstancesParser.new(:logger => @logger))
get_desc_instances(instances)
rescue Exception
@@ -611,11 +605,53 @@
link = generate_request("TerminateInstances", hash_params('InstanceId', list.to_a))
request_info(link, QEc2TerminateInstancesParser.new(:logger => @logger))
rescue Exception
on_exception
end
-
+
+ # Stop EBS-backed EC2 instances. Returns a list of instance state changes or an exception.
+ #
+ # ec2.stop_instances(['i-f222222d', 'i-f222222e']) #=>
+ # [{:aws_instance_id => "i-f222222d",
+ # :aws_current_state_code => 64,
+ # :aws_current_state => "stopping",
+ # :aws_prev_state_code => 16,
+ # :aws_prev_state => "running"},
+ # {:aws_instance_id => "i-f222222e",
+ # :aws_current_state_code => 64,
+ # :aws_current_state => "stopping",
+ # :aws_prev_state_code => 16,
+ # :aws_prev_state => "running"}]
+ #
+ def stop_instances(list=[])
+ link = generate_request("StopInstances", hash_params('InstanceId', list.to_a))
+ request_info(link, QEc2StopInstancesParser.new(:logger => @logger))
+ rescue Exception
+ on_exception
+ end
+
+ # Start EBS-backed EC2 instances. Returns a list of instance state changes or an exception.
+ #
+ # ec2.start_instances(['i-f222222d', 'i-f222222e']) #=>
+ # [{:aws_instance_id => "i-f222222d",
+ # :aws_current_state_code => 0,
+ # :aws_current_state => "pending",
+ # :aws_prev_state_code => 80,
+ # :aws_prev_state => "stopped"},
+ # {:aws_instance_id => "i-f222222e",
+ # :aws_current_state_code => 0,
+ # :aws_current_state => "pending",
+ # :aws_prev_state_code => 80,
+ # :aws_prev_state => "stopped"}]
+ #
+ def start_instances(list=[])
+ link = generate_request("StartInstances", hash_params('InstanceId', list.to_a))
+ request_info(link, QEc2StartInstancesParser.new(:logger => @logger))
+ rescue Exception
+ on_exception
+ end
+
# Retreive EC2 instance OS logs. Returns a hash of data or an exception.
#
# ec2.get_console_output('i-f222222d') =>
# {:aws_instance_id => 'i-f222222d',
# :aws_timestamp => "2007-05-23T14:36:07.000-07:00",
@@ -700,11 +736,11 @@
policy = {'expiration' => s3_expires.strftime('%Y-%m-%dT%H:%M:%SZ'),
'conditions' => [{'bucket' => s3_bucket},
{'acl' => s3_upload_policy},
['starts-with', '$key', s3_prefix]]}.to_json
policy64 = Base64.encode64(policy).gsub("\n", "")
- signed_policy64 = AwsUtils.sign(s3_owner_aws_secret_access_key, policy64)
+ signed_policy64 = Utils.sign(s3_owner_aws_secret_access_key, policy64)
# fill request params
params = {'InstanceId' => instance_id,
'Storage.S3.AWSAccessKeyId' => s3_owner_aws_access_key_id,
'Storage.S3.UploadPolicy' => policy64,
'Storage.S3.UploadPolicySignature' => signed_policy64,
@@ -766,55 +802,55 @@
# Retrieve Security Group information. If +list+ is omitted the returns the whole list of groups.
#
# ec2.describe_security_groups #=>
# [{:aws_group_name => "default-1",
# :aws_owner => "000000000888",
- # :aws_description => "Default allowing SSH, HTTP, and HTTPS ingress",
+ # :aws_description => "a default security group",
# :aws_perms =>
- # [{:owner => "000000000888", :group => "default"},
- # {:owner => "000000000888", :group => "default-1"},
- # {:to_port => "-1", :protocol => "icmp", :from_port => "-1", :cidr_ips => "0.0.0.0/0"},
- # {:to_port => "22", :protocol => "tcp", :from_port => "22", :cidr_ips => "0.0.0.0/0"},
- # {:to_port => "80", :protocol => "tcp", :from_port => "80", :cidr_ips => "0.0.0.0/0"},
- # {:to_port => "443", :protocol => "tcp", :from_port => "443", :cidr_ips => "0.0.0.0/0"}]},
- # ..., {...}]
+ # [ {:protocol => "tcp", :from_port=>"1000", :to_port=>"2000",
+ # :ip_ranges=>[{cidr_ip=>"10.1.2.3/32"}, {cidr_ip=>"192.168.1.10/24"}],
+ # :groups => [{:owner=>"123456789012", :group_name="default"}] },
+ #
+ # {:protocol ="icmp", :from_port="-1", :to_port=>"-1",
+ # :ip_ranges=>[{:cidr_ip=>"0.0.0.0/0"}],
+ # :groups=>[] },
+ #
+ # {:protocol=>"udp", :from_port=>"0", :to_port=>"65535",
+ # :ip_ranges=>[],
+ # :groups=>[{:owner=>"123456789012", :group_name=>"newgroup"}, {:owner=>"123456789012", :group_name=>"default"}],
+ #
+ # {:protocol=>"tcp", :from_port="22", :to_port=>"22",
+ # :ip_ranges=>[{:cidr_ip=>"0.0.0.0/0"}],
+ # :groups=>[{:owner=>"", :group_name=>"default"}] },
+ #
+ # ..., {...}
+ # ]
#
def describe_security_groups(list=[])
link = generate_request("DescribeSecurityGroups", hash_params('GroupName', list.to_a))
- request_cache_or_info(:describe_security_groups, link, QEc2DescribeSecurityGroupsParser, @@bench, list.blank?) do |parser|
- result = []
- parser.result.each do |item|
- perms = []
- item.ipPermissions.each do |perm|
- perm.groups.each do |ngroup|
- perms << {:group => ngroup.groupName,
- :owner => ngroup.userId}
- end
- perm.ipRanges.each do |cidr_ip|
- perms << {:from_port => perm.fromPort,
- :to_port => perm.toPort,
- :protocol => perm.ipProtocol,
- :cidr_ips => cidr_ip}
- end
+ request_cache_or_info(:describe_security_groups, link, QEc2DescribeSecurityGroupsParser, @@bench, list.nil? || list.empty?) do |parser|
+ result = []
+ parser.result.each do |item|
+ perms = []
+ item.ipPermissions.each do |perm|
+ current = {:from_port => perm.fromPort,
+ :to_port => perm.toPort,
+ :protocol => perm.ipProtocol,
+ :groups => [], :ip_ranges => []}
+ perm.groups.each do |ngroup|
+ current[:groups] << {:group_name => ngroup.groupName, :owner => ngroup.userId}
end
-
- # delete duplication
- perms.each_index do |i|
- (0...i).each do |j|
- if perms[i] == perms[j] then
- perms[i] = nil; break;
- end
- end
+ perm.ipRanges.each do |cidr_ip|
+ current[:ip_ranges] << {:cidr_ip => cidr_ip.cidrIp}
end
- perms.compact!
-
- result << {:aws_owner => item.ownerId,
- :aws_group_name => item.groupName,
- :aws_description => item.groupDescription,
- :aws_perms => perms}
-
+ perms << current
end
+ result << {:aws_owner => item.ownerId,
+ :aws_group_name => item.groupName,
+ :aws_description => item.groupDescription,
+ :aws_perms => perms}
+ end
result
end
rescue Exception
on_exception
end
@@ -823,11 +859,11 @@
#
# ec2.create_security_group('default-1',"Default allowing SSH, HTTP, and HTTPS ingress") #=> true
#
def create_security_group(name, description)
# EC2 doesn't like an empty description...
- description = " " if description.blank?
+ description = " " if Aws::Utils.blank?(description)
link = generate_request("CreateSecurityGroup",
'GroupName' => name.to_s,
'GroupDescription' => description.to_s)
request_info(link, RightBoolResponseParser.new(:logger => @logger))
rescue Exception
@@ -920,11 +956,11 @@
# {:aws_fingerprint=> "1e:29:30:47:58:6d:7b:8c:9f:08:11:20:3c:44:52:69:74:80:97:08", :aws_key_name=>"key-2"},
# ..., {...} ]
#
def describe_key_pairs(list=[])
link = generate_request("DescribeKeyPairs", hash_params('KeyName', list.to_a))
- request_cache_or_info :describe_key_pairs, link, QEc2DescribeKeyPairParser, @@bench, list.blank?
+ request_cache_or_info :describe_key_pairs, link, QEc2DescribeKeyPairParser, @@bench, list.nil? || list.empty?
rescue Exception
on_exception
end
# Create new SSH key. Returns a hash of the key's data or an exception.
@@ -993,11 +1029,11 @@
# ec2.describe_addresses('75.101.154.140') #=> [{:instance_id=>"i-d630cbbf", :public_ip=>"75.101.154.140"}]
#
def describe_addresses(list=[])
link = generate_request("DescribeAddresses",
hash_params('PublicIp', list.to_a))
- request_cache_or_info :describe_addresses, link, QEc2DescribeAddressesParser, @@bench, list.blank?
+ request_cache_or_info :describe_addresses, link, QEc2DescribeAddressesParser, @@bench, list.nil? || list.empty?
rescue Exception
on_exception
end
# Disassociate the specified elastic IP address from the instance to which it is assigned.
@@ -1042,15 +1078,37 @@
# :zone_name=>"us-east-1c"}]
#
def describe_availability_zones(list=[])
link = generate_request("DescribeAvailabilityZones",
hash_params('ZoneName', list.to_a))
- request_cache_or_info :describe_availability_zones, link, QEc2DescribeAvailabilityZonesParser, @@bench, list.blank?
+ request_cache_or_info :describe_availability_zones, link, QEc2DescribeAvailabilityZonesParser, @@bench, list.nil? || list.empty?
rescue Exception
on_exception
end
+# This is using the new way, but not sure it's backwrads compatible
+ def describe_availability_zones2(options={})
+ link = generate_request("DescribeAvailabilityZones", options={})
+ request_info_xml_simple(self.class.connection_name, @params, link, @logger,
+ :group_tags =>{"DBInstances" =>"DBInstance",
+ "DBParameterGroups"=>"DBParameterGroup",
+ "DBSecurityGroups" =>"DBSecurityGroup",
+ "EC2SecurityGroups"=>"EC2SecurityGroup",
+ "IPRanges" =>"IPRange"},
+ :force_array =>["DBInstances",
+ "DBParameterGroups",
+ "DBSecurityGroups",
+ "EC2SecurityGroups",
+ "IPRanges"],
+ :pull_out_array =>options[:pull_out_array],
+ :pull_out_single=>options[:pull_out_single],
+ :wrapper =>options[:wrapper])
+ rescue Exception
+ on_exception
+ end
+
+
#-----------------------------------------------------------------
# Regions
#-----------------------------------------------------------------
# Describe regions.
@@ -1058,11 +1116,11 @@
# ec2.describe_regions #=> ["eu-west-1", "us-east-1"]
#
def describe_regions(list=[])
link = generate_request("DescribeRegions",
hash_params('RegionName', list.to_a))
- request_cache_or_info :describe_regions, link, QEc2DescribeRegionsParser, @@bench, list.blank?
+ request_cache_or_info :describe_regions, link, QEc2DescribeRegionsParser, @@bench, list.nil? || list.empty?
rescue Exception
on_exception
end
@@ -1091,11 +1149,11 @@
# :aws_created_at => Wed Jun 18 08:19:21 UTC 2008,}, ... ]
#
def describe_volumes(list=[])
link = generate_request("DescribeVolumes",
hash_params('VolumeId', list.to_a))
- request_cache_or_info :describe_volumes, link, QEc2DescribeVolumesParser, @@bench, list.blank?
+ request_cache_or_info :describe_volumes, link, QEc2DescribeVolumesParser, @@bench, list.nil? || list.empty?
rescue Exception
on_exception
end
# Create new EBS volume based on previously created snapshot.
@@ -1176,12 +1234,12 @@
# :aws_attached_at => "2008-03-28T14:38:34.000Z",
# :aws_id => "vol-898a6fe0"}
#
def detach_volume(volume_id, instance_id=nil, device=nil, force=nil)
hash = {"VolumeId" => volume_id.to_s}
- hash["InstanceId"] = instance_id.to_s unless instance_id.blank?
- hash["Device"] = device.to_s unless device.blank?
+ hash["InstanceId"] = instance_id.to_s unless Aws::Utils.blank?(instance_id)
+ hash["Device"] = device.to_s unless Aws::Utils.blank?(device)
hash["Force"] = 'true' if force
#
link = generate_request("DetachVolume", hash)
request_info(link, QEc2AttachAndDetachVolumeParser.new(:logger => @logger))
rescue Exception
@@ -1208,11 +1266,11 @@
# :aws_started_at => "2008-02-23T16:23:19.000Z" },...]
#
def describe_snapshots(list=[])
link = generate_request("DescribeSnapshots",
hash_params('SnapshotId', list.to_a))
- request_cache_or_info :describe_snapshots, link, QEc2DescribeSnapshotsParser, @@bench, list.blank?
+ request_cache_or_info :describe_snapshots, link, QEc2DescribeSnapshotsParser, @@bench, list.nil? || list.empty?
rescue Exception
on_exception
end
# Create a snapshot of specified volume.
@@ -1222,13 +1280,12 @@
# :aws_started_at => Tue Jun 24 18:40:40 UTC 2008,
# :aws_progress => "",
# :aws_status => "pending",
# :aws_id => "snap-d56783bc"}
#
- def create_snapshot(volume_id)
- link = generate_request("CreateSnapshot",
- "VolumeId" => volume_id.to_s)
+ def create_snapshot(volume_id, options={})
+ link = generate_request("CreateSnapshot", options.merge({"VolumeId" => volume_id.to_s}))
request_info(link, QEc2CreateSnapshotParser.new(:logger => @logger))
rescue Exception
on_exception
end
@@ -1395,10 +1452,14 @@
class QEc2UserIdGroupPairType #:nodoc:
attr_accessor :userId
attr_accessor :groupName
end
+ class QEc2IpRangeItemType #:nodoc:
+ attr_accessor :cidrIp
+ end
+
class QEc2IpPermissionType #:nodoc:
attr_accessor :ipProtocol
attr_accessor :fromPort
attr_accessor :toPort
attr_accessor :groups
@@ -1424,39 +1485,36 @@
@perm = QEc2IpPermissionType.new
@perm.ipRanges = []
@perm.groups = []
elsif @xmlpath=='DescribeSecurityGroupsResponse/securityGroupInfo/item/ipPermissions/item/groups'
@sgroup = QEc2UserIdGroupPairType.new
+ elsif @xmlpath=='DescribeSecurityGroupsResponse/securityGroupInfo/item/ipPermissions/item/ipRanges'
+ @sIpRange = QEc2IpRangeItemType.new
end
end
end
def tagend(name)
case name
- when 'ownerId' then
- @group.ownerId = @text
- when 'groupDescription' then
- @group.groupDescription = @text
+ when 'ownerId' then @group.ownerId = @text
+ when 'groupDescription' then @group.groupDescription = @text
when 'groupName'
if @xmlpath=='DescribeSecurityGroupsResponse/securityGroupInfo/item'
- @group.groupName = @text
+ @group.groupName = @text
elsif @xmlpath=='DescribeSecurityGroupsResponse/securityGroupInfo/item/ipPermissions/item/groups/item'
@sgroup.groupName = @text
end
- when 'ipProtocol' then
- @perm.ipProtocol = @text
- when 'fromPort' then
- @perm.fromPort = @text
- when 'toPort' then
- @perm.toPort = @text
- when 'userId' then
- @sgroup.userId = @text
- when 'cidrIp' then
- @perm.ipRanges << @text
+ when 'ipProtocol' then @perm.ipProtocol = @text
+ when 'fromPort' then @perm.fromPort = @text
+ when 'toPort' then @perm.toPort = @text
+ when 'userId' then @sgroup.userId = @text
+ when 'cidrIp' then @sIpRange.cidrIp = @text
when 'item'
if @xmlpath=='DescribeSecurityGroupsResponse/securityGroupInfo/item/ipPermissions/item/groups'
@perm.groups << @sgroup
+ elsif @xmlpath=='DescribeSecurityGroupsResponse/securityGroupInfo/item/ipPermissions/item/ipRanges'
+ @perm.ipRanges << @sIpRange
elsif @xmlpath=='DescribeSecurityGroupsResponse/securityGroupInfo/item/ipPermissions'
@group.ipPermissions << @perm
elsif @xmlpath=='DescribeSecurityGroupsResponse/securityGroupInfo'
@result << @group
end
@@ -1743,11 +1801,74 @@
def reset
@result = []
end
end
+
+ class QEc2StopInstancesParser < AwsParser #:nodoc:
+ def tagstart(name, attributes)
+ @instance = {} if name == 'item'
+ end
+
+ def tagend(name)
+ case name
+ when 'instanceId' then
+ @instance[:aws_instance_id] = @text
+ when 'code'
+ if @xmlpath == 'StopInstancesResponse/instancesSet/item/currentState'
+ @instance[:aws_current_state_code] = @text.to_i
+ elsif @xmlpath == 'StopInstancesResponse/instancesSet/item/previousState'
+ @instance[:aws_prev_state_code] = @text.to_i
+ end
+ when 'name'
+ if @xmlpath == 'StopInstancesResponse/instancesSet/item/currentState'
+ @instance[:aws_current_state] = @text
+ elsif @xmlpath == 'StopInstancesResponse/instancesSet/item/previousState'
+ @instance[:aws_prev_state] = @text
+ end
+ when 'item' then
+ @result << @instance
+ end
+ end
+
+ def reset
+ @result = []
+ end
+ end
+ class QEc2StartInstancesParser < AwsParser #:nodoc:
+ def tagstart(name, attributes)
+ @instance = {} if name == 'item'
+ end
+
+ def tagend(name)
+ case name
+ when 'instanceId' then
+ @instance[:aws_instance_id] = @text
+ when 'code'
+ if @xmlpath == 'StartInstancesResponse/instancesSet/item/currentState'
+ @instance[:aws_current_state_code] = @text.to_i
+ elsif @xmlpath == 'StartInstancesResponse/instancesSet/item/previousState'
+ @instance[:aws_prev_state_code] = @text.to_i
+ end
+ when 'name'
+ if @xmlpath == 'StartInstancesResponse/instancesSet/item/currentState'
+ @instance[:aws_current_state] = @text
+ elsif @xmlpath == 'StartInstancesResponse/instancesSet/item/previousState'
+ @instance[:aws_prev_state] = @text
+ end
+ when 'item' then
+ @result << @instance
+ end
+ end
+
+ def reset
+ @result = []
+ end
+ end
+
+
#-----------------------------------------------------------------
# PARSERS: Console
#-----------------------------------------------------------------
class QEc2GetConsoleOutputParser < AwsParser #:nodoc:
@@ -1857,11 +1978,11 @@
end
def tagend(name)
case name
when 'instanceId' then
- @address[:instance_id] = @text.blank? ? nil : @text
+ @address[:instance_id] = Aws::Utils.blank?(@text) ? nil : @text
when 'publicIp' then
@address[:public_ip] = @text
when 'item' then
@result << @address
end
@@ -1927,11 +2048,11 @@
when 'createTime' then
@result[:aws_created_at] = Time.parse(@text)
when 'size' then
@result[:aws_size] = @text.to_i ###
when 'snapshotId' then
- @result[:snapshot_id] = @text.blank? ? nil : @text ###
+ @result[:snapshot_id] = Aws::Utils.blank?(@text) ? nil : @text ###
when 'availabilityZone' then
@result[:zone] = @text ###
end
end
@@ -1995,11 +2116,11 @@
when 'device' then
@volume[:aws_device] = @text
when 'attachTime' then
@volume[:aws_attached_at] = Time.parse(@text)
when 'snapshotId' then
- @volume[:snapshot_id] = @text.blank? ? nil : @text
+ @volume[:snapshot_id] = Aws::Utils.blank?(@text) ? nil : @text
when 'availabilityZone' then
@volume[:zone] = @text
when 'item'
case @xmlpath
when 'DescribeVolumesResponse/volumeSet' then
@@ -2016,12 +2137,23 @@
#-----------------------------------------------------------------
# PARSERS: EBS - Snapshots
#-----------------------------------------------------------------
class QEc2DescribeSnapshotsParser < AwsParser #:nodoc:
+
+ def initialize (params={})
+ @inside_tagset = false
+ super(params)
+ end
+
def tagstart(name, attributes)
- @snapshot = {} if name == 'item'
+ case name
+ when 'tagSet'
+ @inside_tagset = true
+ when 'item'
+ @snapshot = {} unless @inside_tagset
+ end
end
def tagend(name)
case name
when 'volumeId' then
@@ -2038,11 +2170,17 @@
@snapshot[:aws_description] = @text
when 'ownerId' then
@snapshot[:aws_owner] = @text
when 'volumeSize' then
@snapshot[:aws_volume_size] = @text.to_i
+ when 'tagSet' then
+ @inside_tagset = false
+ when 'key' then
+ @key = ('aws_tag_' + @text).to_sym
+ when 'value' then
+ @snapshot[@key] = @text
when 'item' then
- @result << @snapshot
+ @result << @snapshot unless @inside_tagset
end
end
def reset
@result = []