mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
the old parser was not working properly
This commit is contained in:
parent
efa6ee66ce
commit
6aad80460b
1 changed files with 31 additions and 61 deletions
|
@ -4,90 +4,60 @@ module Fog
|
|||
module AWS
|
||||
class DescribeInstanceStatus < Fog::Parsers::Base
|
||||
|
||||
def new_instance
|
||||
@instance = { 'instanceState' => {}, 'systemStatus' => { 'details' => [] }, 'instanceStatus' => { 'details' => [] }, 'event' => {} }
|
||||
def new_instance!
|
||||
@instance = { 'instanceState' => {}, 'systemStatus' => { 'details' => [] }, 'instanceStatus' => { 'details' => [] }, 'eventsSet' => [] }
|
||||
end
|
||||
|
||||
def new_item
|
||||
def new_item!
|
||||
@item = {}
|
||||
end
|
||||
|
||||
def reset
|
||||
@instance_status = {}
|
||||
@response = { 'instanceStatusSet' => [] }
|
||||
@in_system_status = false
|
||||
@in_details = false
|
||||
@in_event = false
|
||||
new_instance
|
||||
new_item
|
||||
@inside = nil
|
||||
end
|
||||
|
||||
def start_element(name, attrs=[])
|
||||
super
|
||||
case name
|
||||
when 'item'
|
||||
if @inside
|
||||
new_item!
|
||||
else
|
||||
new_instance!
|
||||
end
|
||||
when 'systemStatus'
|
||||
@in_system_status = true
|
||||
@inside = :systemStatus
|
||||
when 'instanceState'
|
||||
@inside = :instanceState
|
||||
when 'instanceStatus'
|
||||
@in_instance_status = true
|
||||
when 'details'
|
||||
@in_details = true
|
||||
when 'event'
|
||||
@in_event = true
|
||||
@inside = :instanceStatus
|
||||
when 'eventsSet'
|
||||
@inside = :eventsSet
|
||||
end
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
case name
|
||||
when 'name'
|
||||
if @in_details
|
||||
@item[name] = value
|
||||
else
|
||||
@instance['instanceState'][name] = value
|
||||
end
|
||||
when 'status'
|
||||
if @in_details
|
||||
@item[name] = value
|
||||
elsif @in_system_status
|
||||
@instance['systemStatus'][name] = value
|
||||
elsif @in_instance_status
|
||||
@instance['instanceStatus'][name] = value
|
||||
end
|
||||
when 'details'
|
||||
@in_details = false
|
||||
when 'item'
|
||||
if @in_system_status
|
||||
@instance['systemStatus']['details'] << @item
|
||||
elsif @in_instance_status
|
||||
@instance['instanceStatus']['details'] << @item
|
||||
else
|
||||
@response['instanceStatusSet'] << @instance
|
||||
new_instance
|
||||
end
|
||||
new_item
|
||||
when 'instanceStatus'
|
||||
@in_instance_status = false
|
||||
when 'systemStatus'
|
||||
@in_system_status = false
|
||||
when 'code'
|
||||
if @in_event
|
||||
@instance['event'][name] = value.strip
|
||||
else
|
||||
@instance['instanceState'][name] = value
|
||||
end
|
||||
when 'description'
|
||||
if @in_event
|
||||
@instance['event'][name] = value.strip
|
||||
end
|
||||
when 'notAfter', 'notBefore'
|
||||
if @in_event
|
||||
@instance['event'][name] = Time.parse(value)
|
||||
end
|
||||
when 'event'
|
||||
@in_event = false
|
||||
#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', 'description', 'notBefore', 'notAfter', 'name', 'status'
|
||||
@item.nil? ? (@instance[@inside.to_s][name] = value) : (@item[name] = value)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue