File: describe_reserved_instances.rb

package info (click to toggle)
ruby-fog-aws 3.3.0-5
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,816 kB
  • sloc: ruby: 68,587; makefile: 6
file content (69 lines) | stat: -rw-r--r-- 2,366 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
module Fog
  module Parsers
    module AWS
      module Compute
        class DescribeReservedInstances < Fog::Parsers::Base
          def get_default_item
            {'tagSet' => {}, 'recurringCharges' => []}
          end

          def reset
            @context = []
            @contexts = ['reservedInstancesSet', 'recurringCharges', 'tagSet']
            @reserved_instance = get_default_item
            @response = { 'reservedInstancesSet' => [] }
            @charge = {}
            @tag = {}
          end

          def start_element(name, attrs = [])
            super
            if @contexts.include?(name)
              @context.push(name)
            end
          end

          def end_element(name)
            case name
            when 'availabilityZone', 'instanceTenancy', 'instanceType', 'offeringType', 'productDescription', 'reservedInstancesId', 'scope', 'state'
              @reserved_instance[name] = value
            when 'duration', 'instanceCount'
              @reserved_instance[name] = value.to_i
            when 'fixedPrice', 'usagePrice'
              @reserved_instance[name] = value.to_f
            when *@contexts
              @context.pop
            when 'item'
              case @context.last
              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'
              @response[name] = value
            when 'start','end'
              @reserved_instance[name] = Time.parse(value)
            end
          end
        end
      end
    end
  end
end