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