1
0
Fork 0
mirror of https://github.com/fog/fog-aws.git synced 2022-11-09 13:50:52 -05:00
fog--fog-aws/lib/fog/aws/parsers/compute/describe_instance_status.rb
Josh Lane d48d376e9c initial import
* take the liberty of correcting Aws naming
2014-12-31 09:17:51 -08:00

73 lines
2.2 KiB
Ruby

module Fog
module Parsers
module Compute
module AWS
class DescribeInstanceStatus < Fog::Parsers::Base
def new_instance!
@instance = { 'instanceState' => {}, 'systemStatus' => { 'details' => [] }, 'instanceStatus' => { 'details' => [] }, 'eventsSet' => [] }
end
def new_item!
@item = {}
end
def reset
@response = { 'instanceStatusSet' => [] }
@inside = nil
end
def start_element(name, attrs=[])
super
case name
when 'item'
if @inside
new_item!
else
new_instance!
end
when 'systemStatus'
@inside = :systemStatus
when 'instanceState'
@inside = :instanceState
when 'instanceStatus'
@inside = :instanceStatus
when 'eventsSet'
@inside = :eventsSet
end
end
def end_element(name)
case name
#Simple closers
when 'instanceId', 'availabilityZone'
@instance[name] = value
when 'nextToken', 'requestId'
@response[name] = value
when 'systemStatus', 'instanceState', 'instanceStatus', 'eventsSet'
@inside = nil
when 'item'
case @inside
when :eventsSet
@instance['eventsSet'] << @item
when :systemStatus, :instanceStatus
@instance[@inside.to_s]['details'] << @item
when nil
@response['instanceStatusSet'] << @instance
end
@item = nil
when 'code'
case @inside
when :eventsSet
@item[name] = value
when :instanceState
@instance[@inside.to_s][name] = value.to_i
end
when 'description', 'notBefore', 'notAfter', 'name', 'status'
@item.nil? ? (@instance[@inside.to_s][name] = value) : (@item[name] = value)
end
end
end
end
end
end
end