2009-07-17 03:36:42 -04:00
|
|
|
module Fog
|
|
|
|
module Parsers
|
2011-06-16 19:28:54 -04:00
|
|
|
module Compute
|
|
|
|
module AWS
|
2009-07-17 03:36:42 -04:00
|
|
|
|
|
|
|
class RunInstances < Fog::Parsers::Base
|
|
|
|
|
|
|
|
def reset
|
2010-02-20 16:40:46 -05:00
|
|
|
@block_device_mapping = {}
|
2011-06-24 20:31:44 -04:00
|
|
|
@context = []
|
|
|
|
@contexts = ['blockDeviceMapping', 'groupSet', 'placement', 'productCodes']
|
2010-02-20 16:40:46 -05:00
|
|
|
@instance = { 'blockDeviceMapping' => [], 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [] }
|
2009-08-01 04:15:44 -04:00
|
|
|
@response = { 'groupSet' => [], 'instancesSet' => [] }
|
2009-07-17 03:36:42 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def start_element(name, attrs = [])
|
2010-05-05 16:39:41 -04:00
|
|
|
super
|
2011-06-24 20:31:44 -04:00
|
|
|
if @contexts.include?(name)
|
|
|
|
@context.push(name)
|
2009-07-17 03:36:42 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def end_element(name)
|
|
|
|
case name
|
|
|
|
when 'amiLaunchIndex'
|
2011-05-12 16:15:13 -04:00
|
|
|
@instance[name] = value.to_i
|
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
|
2011-06-24 20:31:44 -04:00
|
|
|
when 'availabilityZone', 'tenancy'
|
2011-05-12 16:15:13 -04:00
|
|
|
@instance['placement'][name] = value
|
2010-02-20 16:40:46 -05:00
|
|
|
when 'attachTime'
|
2011-05-12 16:15:13 -04:00
|
|
|
@block_device_mapping[name] = Time.parse(value)
|
2011-06-24 20:31:44 -04:00
|
|
|
when *@contexts
|
|
|
|
@context.pop
|
2009-07-19 19:50:19 -04:00
|
|
|
when 'code'
|
2011-05-12 16:15:13 -04:00
|
|
|
@instance['instanceState'][name] = value.to_i
|
2010-02-20 16:40:46 -05:00
|
|
|
when 'deleteOnTermination'
|
2011-05-12 16:15:13 -04:00
|
|
|
@block_device_mapping[name] = (value == 'true')
|
2010-02-20 16:40:46 -05:00
|
|
|
when 'deviceName', 'status', 'volumeId'
|
2011-05-12 16:15:13 -04:00
|
|
|
@block_device_mapping[name] = value
|
2009-07-17 03:36:42 -04:00
|
|
|
when 'groupId'
|
2011-05-12 16:15:13 -04:00
|
|
|
@response['groupSet'] << value
|
2011-06-24 20:31:44 -04:00
|
|
|
when 'groupName'
|
|
|
|
case @context.last
|
|
|
|
when 'groupSet'
|
|
|
|
@response['groupSet'] << value
|
|
|
|
when 'placement'
|
|
|
|
@instance['placement'][name] = value
|
|
|
|
end
|
2009-07-17 03:36:42 -04:00
|
|
|
when 'item'
|
2011-06-24 20:31:44 -04:00
|
|
|
case @context.last
|
|
|
|
when 'blockDeviceMapping'
|
2010-02-20 16:40:46 -05:00
|
|
|
@instance['blockDeviceMapping'] << @block_device_mapping
|
|
|
|
@block_device_mapping = {}
|
2011-06-24 20:31:44 -04:00
|
|
|
when nil
|
2009-08-01 04:15:44 -04:00
|
|
|
@response['instancesSet'] << @instance
|
2010-02-20 16:40:46 -05:00
|
|
|
@instance = { 'blockDeviceMapping' => [], 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [] }
|
2009-07-17 03:36:42 -04:00
|
|
|
end
|
|
|
|
when 'launchTime'
|
2011-05-12 16:15:13 -04:00
|
|
|
@instance[name] = Time.parse(value)
|
2009-07-19 19:50:19 -04:00
|
|
|
when 'name'
|
2011-05-12 16:15:13 -04:00
|
|
|
@instance['instanceState'][name] = value
|
2009-08-01 04:15:44 -04:00
|
|
|
when 'ownerId', 'requestId', 'reservationId'
|
2011-05-12 16:15:13 -04:00
|
|
|
@response[name] = value
|
2009-07-17 03:36:42 -04:00
|
|
|
when 'product_code'
|
2011-05-12 16:15:13 -04:00
|
|
|
@instance['productCodes'] << value
|
2009-07-17 17:05:05 -04:00
|
|
|
when 'state'
|
2011-05-12 16:15:13 -04:00
|
|
|
@instance['monitoring'][name] = (value == 'true')
|
2010-08-17 06:28:06 -04:00
|
|
|
when 'subnetId'
|
2011-05-12 16:15:13 -04:00
|
|
|
@response[name] = value
|
2009-07-17 03:36:42 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|