2009-07-11 16:41:21 -04:00
|
|
|
module Fog
|
|
|
|
module Parsers
|
2011-06-16 19:28:54 -04:00
|
|
|
module Compute
|
|
|
|
module AWS
|
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 = {}
|
2011-06-23 14:51:00 -04:00
|
|
|
@context = []
|
2011-06-24 20:31:44 -04:00
|
|
|
@contexts = ['blockDeviceMapping', 'groupSet', 'instancesSet', 'instanceState', 'placement', 'productCodes', 'stateReason', 'tagSet']
|
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
|
2011-06-23 14:51:00 -04:00
|
|
|
if @contexts.include?(name)
|
|
|
|
@context.push(name)
|
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
|
2011-06-24 20:31:44 -04:00
|
|
|
when 'availabilityZone', 'tenancy'
|
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',
|
2011-07-26 13:11:44 -04:00
|
|
|
'keyName', 'platform', 'privateDnsName', 'privateIpAddress', 'ramdiskId',
|
2012-01-31 23:30:44 -05:00
|
|
|
'reason', 'rootDeviceType', 'subnetId', 'vpcId'
|
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)
|
2011-06-23 14:51:00 -04:00
|
|
|
when *@contexts
|
|
|
|
@context.pop
|
2009-07-11 16:41:21 -04:00
|
|
|
when 'code'
|
2011-06-23 14:51:00 -04:00
|
|
|
@instance[@context.last][name] = value.to_i
|
2010-02-20 16:12:04 -05:00
|
|
|
when 'deleteOnTermination'
|
2011-06-23 14:51:00 -04:00
|
|
|
@block_device_mapping[name] = (value == 'true')
|
2010-02-20 16:12:04 -05:00
|
|
|
when 'deviceName', 'status', 'volumeId'
|
2011-05-12 16:15:13 -04:00
|
|
|
@block_device_mapping[name] = value
|
2011-07-15 12:29:26 -04:00
|
|
|
when 'groupId', 'groupName'
|
2011-06-24 20:31:44 -04:00
|
|
|
case @context.last
|
|
|
|
when 'groupSet'
|
2012-01-30 20:44:08 -05:00
|
|
|
@reservation['groupSet'] << value if @context.first != "instancesSet"
|
2011-06-24 20:31:44 -04:00
|
|
|
when 'placement'
|
|
|
|
@instance['placement'][name] = value
|
|
|
|
end
|
2009-07-11 16:41:21 -04:00
|
|
|
when 'item'
|
2011-06-23 14:51:00 -04:00
|
|
|
case @context.last
|
|
|
|
when 'blockDeviceMapping'
|
2010-02-20 16:12:04 -05:00
|
|
|
@instance['blockDeviceMapping'] << @block_device_mapping
|
|
|
|
@block_device_mapping = {}
|
2011-06-23 14:51:00 -04:00
|
|
|
when 'instancesSet'
|
2010-10-13 12:39:32 -04:00
|
|
|
@reservation['instancesSet'] << @instance
|
|
|
|
@instance = { 'blockDeviceMapping' => [], 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [], 'stateReason' => {}, 'tagSet' => {} }
|
2011-06-23 14:51:00 -04:00
|
|
|
when 'tagSet'
|
|
|
|
@instance['tagSet'][@tag['key']] = @tag['value']
|
|
|
|
@tag = {}
|
|
|
|
when nil
|
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'
|
2011-06-23 14:51:00 -04:00
|
|
|
@instance[@context.last][name] = value
|
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-06-23 14:51:00 -04:00
|
|
|
@instance['monitoring'][name] = (value == 'true')
|
2009-07-11 16:41:21 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|