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/ec2/run_instances.rb

66 lines
2.1 KiB
Ruby
Raw Normal View History

module Fog
module Parsers
module AWS
module EC2
class RunInstances < Fog::Parsers::Base
def reset
2009-08-01 04:15:44 -04:00
@instance = { 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [] }
@response = { 'groupSet' => [], 'instancesSet' => [] }
end
def start_element(name, attrs = [])
if name == 'groupSet'
@in_group_set = true
elsif name == 'productCodes'
@in_product_codes = true
end
@value = ''
end
def end_element(name)
case name
when 'amiLaunchIndex'
2009-08-01 04:15:44 -04:00
@instance[name] = @value.to_i
when 'availabilityZone'
2009-08-01 04:15:44 -04:00
@instance['placement'][name] = @value
when 'code'
2009-08-01 04:15:44 -04:00
@instance['instanceState'][name] = @value.to_i
when 'dnsName', 'kernelId', 'keyName', 'imageId', 'instanceId', 'instanceType', 'platform', 'privateDnsName', 'ramdiskId', 'reason', 'requestorId'
@instance[name] = @value
when 'groupId'
2009-08-01 04:15:44 -04:00
@response['groupSet'] << @value
when 'groupSet'
@in_group_set = false
when 'item'
unless @in_group_set || @in_product_codes
2009-08-01 04:15:44 -04:00
@response['instancesSet'] << @instance
@instance = { 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [] }
end
when 'launchTime'
2009-08-01 04:15:44 -04:00
@instance[name] = Time.parse(@value)
when 'name'
2009-08-01 04:15:44 -04:00
@instance['instanceState'][name] = @value
when 'ownerId', 'requestId', 'reservationId'
@response[name] = @value
when 'product_code'
2009-08-01 04:15:44 -04:00
@instance['productCodes'] << @value
when 'productCodes'
@in_product_codes = false
2009-07-17 17:05:05 -04:00
when 'state'
if @value == 'true'
2009-08-01 04:15:44 -04:00
@instance['monitoring'][name] = true
2009-07-17 17:05:05 -04:00
else
2009-08-01 04:15:44 -04:00
@instance['monitoring'][name] = false
2009-07-17 17:05:05 -04:00
end
end
end
end
end
end
end
end