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

Support Partial reservations by parsing an array of recurring charges

This is a semi-breaking change: the recurringCharges field is switching from a
Hash to an Array, however it never before contained any values because it was
unable to parse the AWS XML response. The likelihood of breaking anybody's
"working" code is rather low given that it never worked.

While the AWS API currently supports only a single type of recurring charge,
hourly, they've left the ability to have more/other recurring charge types in
the future, so we should reflect that in the parsed data structure as well.
This commit is contained in:
Aaron Stone 2017-01-03 23:32:04 -08:00
parent 786db72892
commit c422aa7501

View file

@ -4,16 +4,15 @@ module Fog
module AWS
class DescribeReservedInstances < Fog::Parsers::Base
def get_default_item
{'tagSet' => {}, 'recurringCharges' => {}}
{'tagSet' => {}, 'recurringCharges' => []}
end
def reset
@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']
@contexts = ['reservedInstancesSet', 'recurringCharges', 'tagSet']
@reserved_instance = get_default_item
@response = { 'reservedInstancesSet' => [] }
@charge = {}
@tag = {}
end
@ -26,11 +25,11 @@ module Fog
def end_element(name)
case name
when 'availabilityZone', 'instanceType', 'productDescription', 'reservedInstancesId', 'state', 'offeringType', 'instanceTenancy'
when 'availabilityZone', 'instanceTenancy', 'instanceType', 'offeringType', 'productDescription', 'reservedInstancesId', 'state'
@reserved_instance[name] = value
when 'duration', 'instanceCount'
@reserved_instance[name] = value.to_i
when 'fixedPrice', 'amount', 'usagePrice'
when 'fixedPrice', 'usagePrice'
@reserved_instance[name] = value.to_f
when *@contexts
@context.pop
@ -39,10 +38,22 @@ module Fog
when 'reservedInstancesSet'
@response['reservedInstancesSet'] << @reserved_instance
@reserved_instance = get_default_item
when 'recurringCharges'
@reserved_instance['recurringCharges'] << { 'frequency' => @charge['frequency'], 'amount' => @charge['amount'] }
@charge = {}
when 'tagSet'
@reserved_instance['tagSet'][@tag['key']] = @tag['value']
@tag = {}
end
when 'amount'
case @context.last
when 'reservedInstancesSet'
@reserved_instance[name] = value.to_f
when 'recurringCharges'
@charge[name] = value.to_f
end
when 'frequency'
@charge[name] = value
when 'key', 'value'
@tag[name] = value
when 'requestId'