1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00
fog--fog/lib/fog/aws/parsers/compute/describe_images.rb

85 lines
2.8 KiB
Ruby
Raw Normal View History

module Fog
module Parsers
module Compute
module AWS
class DescribeImages < Fog::Parsers::Base
def reset
@block_device_mapping = {}
2011-08-03 19:49:03 -04:00
@image = { 'blockDeviceMapping' => [], 'productCodes' => [], 'stateReason' => {}, 'tagSet' => {} }
2009-08-01 04:15:44 -04:00
@response = { 'imagesSet' => [] }
2011-08-03 19:49:03 -04:00
@state_reason = {}
2010-10-12 14:00:59 -04:00
@tag = {}
end
def start_element(name, attrs = [])
super
case name
when 'blockDeviceMapping'
@in_block_device_mapping = true
2011-08-03 19:49:03 -04:00
when 'stateReason'
@in_state_reason = true
2010-10-12 14:00:59 -04:00
when 'tagSet'
@in_tag_set = true
end
end
def end_element(name)
if @in_tag_set
case name
when 'item'
@image['tagSet'][@tag['key']] = @tag['value']
@tag = {}
when 'key', 'value'
@tag[name] = value
when 'tagSet'
@in_tag_set = false
end
elsif @in_block_device_mapping
case name
when 'blockDeviceMapping'
@in_block_device_mapping = false
when 'deviceName', 'virtualName', 'snapshotId', 'deleteOnTermination'
@block_device_mapping[name] = value
when 'volumeSize'
@block_device_mapping[name] = value.to_i
when 'item'
@image['blockDeviceMapping'] << @block_device_mapping
@block_device_mapping = {}
end
2011-08-03 19:49:03 -04:00
elsif @in_state_reason
case name
when 'code', 'message'
@state_reason[name] = value
when 'stateReason'
@image['stateReason'] = @state_reason
@state_reason = {}
@in_state_reason = false
end
else
case name
2011-08-03 19:49:03 -04:00
when 'architecture', 'description', 'hypervisor', 'imageId', 'imageLocation', 'imageOwnerAlias', 'imageOwnerId', 'imageState', 'imageType', 'kernelId', 'name', 'platform', 'ramdiskId', 'rootDeviceType','rootDeviceName','virtualizationType'
@image[name] = value
when 'isPublic'
if value == 'true'
@image[name] = true
else
@image[name] = false
end
when 'item'
2009-08-01 04:15:44 -04:00
@response['imagesSet'] << @image
2011-08-03 19:49:03 -04:00
@image = { 'blockDeviceMapping' => [], 'productCodes' => [], 'stateReason' => {}, 'tagSet' => {} }
when 'productCode'
@image['productCodes'] << value
when 'requestId'
@response[name] = value
end
end
end
end
end
end
end
end