1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

Merge pull request #2504 from BrindleFly/master

Fixing defect with handling of multiple <item>
This commit is contained in:
Wesley Beary 2013-12-23 13:03:41 -08:00
commit 5e93f8d96d

View file

@ -5,9 +5,25 @@ module Fog
class DescribeReservedInstances < Fog::Parsers::Base
def get_default_item
{'tagSet' => {}, 'recurringCharges' => {}}
end
def reset
@reserved_instance = {}
@context = []
# Note: <recurringCharges> should also be handled as a set, but do not want to disrupt anyone relying on
# it currently being flatted
@contexts = ['reservedInstancesSet', 'tagSet']
@reserved_instance = get_default_item
@response = { 'reservedInstancesSet' => [] }
@tag = {}
end
def start_element(name, attrs = [])
super
if @contexts.include?(name)
@context.push(name)
end
end
def end_element(name)
@ -18,9 +34,19 @@ module Fog
@reserved_instance[name] = value.to_i
when 'fixedPrice', 'amount', 'usagePrice'
@reserved_instance[name] = value.to_f
when *@contexts
@context.pop
when 'item'
@response['reservedInstancesSet'] << @reserved_instance
@reserved_instance = {}
case @context.last
when 'reservedInstancesSet'
@response['reservedInstancesSet'] << @reserved_instance
@reserved_instance = get_default_item
when 'tagSet'
@reserved_instance['tagSet'][@tag['key']] = @tag['value']
@tag = {}
end
when 'key', 'value'
@tag[name] = value
when 'requestId'
@response[name] = value
when 'start','end'