diff --git a/lib/fog/aws/parsers/compute/describe_instance_status.rb b/lib/fog/aws/parsers/compute/describe_instance_status.rb index 80906911d..66af27c1e 100644 --- a/lib/fog/aws/parsers/compute/describe_instance_status.rb +++ b/lib/fog/aws/parsers/compute/describe_instance_status.rb @@ -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