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/compute/parsers/aws/describe_instances.rb

120 lines
4.3 KiB
Ruby
Raw Normal View History

module Fog
module Parsers
module AWS
2010-09-08 17:40:02 -04:00
module Compute
class DescribeInstances < Fog::Parsers::Base
def reset
@block_device_mapping = {}
2010-10-12 14:00:59 -04:00
@instance = { 'blockDeviceMapping' => [], 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [], 'stateReason' => {}, 'tagSet' => {} }
2009-08-01 04:15:44 -04:00
@reservation = { 'groupSet' => [], 'instancesSet' => [] }
@response = { 'reservationSet' => [] }
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
when'groupSet', 'productCodes'
@in_subset = true
when 'instancesSet'
@in_instances_set = true
when 'instanceState'
@in_instance_state = true
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)
case name
when 'amiLaunchIndex'
2009-08-01 04:15:44 -04:00
@instance[name] = @value.to_i
when 'availabilityZone'
@instance['placement'][name] = @value
when 'architecture', 'clientToken', 'dnsName', 'imageId',
'instanceId', 'instanceType', 'ipAddress', 'kernelId',
'keyName', 'privateDnsName', 'privateIpAddress', 'ramdiskId',
'reason', 'rootDeviceType'
@instance[name] = @value
when 'attachTime'
@block_device_mapping[name] = Time.parse(@value)
when 'blockDeviceMapping'
@in_block_device_mapping = false
when 'code'
if @in_instance_state
@instance['instanceState'][name] = @value.to_i
elsif @in_state_reason
@instance['stateReason'][name] = @value.to_i
end
when 'deleteOnTermination'
if @value == 'true'
@block_device_mapping[name] = true
else
@block_device_mapping[name] = false
end
when 'deviceName', 'status', 'volumeId'
@block_device_mapping[name] = @value
when 'groupId'
2009-08-01 04:15:44 -04:00
@reservation['groupSet'] << @value
when 'groupSet', 'productCodes'
@in_subset = false
when 'instancesSet'
@in_instances_set = false
when 'instanceState'
@in_instance_state = false
when 'item'
if @in_block_device_mapping
@instance['blockDeviceMapping'] << @block_device_mapping
@block_device_mapping = {}
2010-10-12 14:00:59 -04:00
elsif @in_tag_set
@instance['tagSet'][@tag['key']] = @tag['value']
@tag = {}
elsif @in_instances_set
@reservation['instancesSet'] << @instance
@instance = { 'blockDeviceMapping' => [], 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [], 'stateReason' => {}, 'tagSet' => {} }
elsif !@in_subset
2009-08-01 04:15:44 -04:00
@response['reservationSet'] << @reservation
@reservation = { 'groupSet' => [], 'instancesSet' => [] }
end
2010-10-12 14:00:59 -04:00
when 'key', 'value'
@tag[name] = @value
when 'launchTime'
2009-08-01 04:15:44 -04:00
@instance[name] = Time.parse(@value)
when 'name'
if @in_instance_state
@instance['instanceState'][name] = @value
elsif @in_state_reason
@instance['stateReason'][name] = @value
end
2009-08-01 04:15:44 -04:00
when 'ownerId', 'reservationId'
@reservation[name] = @value
when 'requestId'
2009-08-01 04:15:44 -04:00
@response[name] = @value
when 'productCode'
2009-08-01 04:15:44 -04:00
@instance['productCodes'] << @value
when 'state'
if @value == 'true'
2009-08-01 04:15:44 -04:00
@instance['monitoring'][name] = true
else
2009-08-01 04:15:44 -04:00
@instance['monitoring'][name] = false
end
when 'stateReason'
@in_state_reason = false
2010-10-12 14:00:59 -04:00
when 'tagSet'
@in_tag_set = false
end
end
end
end
end
end
end