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

74 lines
2.4 KiB
Ruby
Raw Normal View History

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