File: run_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 (90 lines) | stat: -rw-r--r-- 3,705 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
module Fog
  module Parsers
    module AWS
      module Compute
        class RunInstances < Fog::Parsers::Base
          def reset
            @block_device_mapping = {}
            @network_interfaces = {}
            @context = []
            @contexts = ['networkInterfaces', 'blockDeviceMapping', 'groupSet', 'placement', 'productCodes']
            @instance = { 'networkInterfaces' => [], 'blockDeviceMapping' => [], 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [] }
            @response = { 'groupSet' => [], 'instancesSet' => [] }
          end

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

          def end_element(name)
            case name
            when 'amiLaunchIndex'
              @instance[name] = value.to_i
            when 'architecture', 'clientToken', 'dnsName', 'hypervisor', 'imageId',
                  'instanceId', 'instanceType', 'ipAddress', 'kernelId', 'keyName',
                  'instanceLifecycle', 'privateDnsName', 'privateIpAddress', 'ramdiskId',
                  'reason', 'requesterId', 'rootDeviceType', 'sourceDestCheck',
                  'spotInstanceRequestId', 'virtualizationType'
              @instance[name] = value
            when 'availabilityZone', 'tenancy'
              @instance['placement'][name] = value
            when 'attachTime'
              @block_device_mapping[name] = Time.parse(value)
            when *@contexts
              @context.pop
            when 'code'
              @instance['instanceState'][name] = value.to_i
            when 'deleteOnTermination'
              @block_device_mapping[name] = (value == 'true')
              @network_interfaces[name] = (value == 'true')
            when 'deviceName', 'status', 'volumeId'
              @block_device_mapping[name] = value
            when 'networkInterfaceId'
              @network_interfaces[name] = value
            when 'groupId'
              @response['groupSet'] << value
            when 'groupName'
              case @context.last
              when 'groupSet'
                @response['groupSet'] << value
              when 'placement'
                @instance['placement'][name] = value
              end
            when 'item'
              case @context.last
              when 'blockDeviceMapping'
                @instance['blockDeviceMapping'] << @block_device_mapping
                @block_device_mapping = {}
              when 'networkInterfaces'
                @instance['networkInterfaces'] << @network_interfaces
                @network_interfaces = {}
              when nil
                @response['instancesSet'] << @instance
                @instance = { 'networkInterfaces' => [], 'blockDeviceMapping' => [], 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [] }
              end
            when 'launchTime'
              @instance[name] = Time.parse(value)
            when 'name'
              @instance['instanceState'][name] = value
            when 'ownerId', 'requestId', 'reservationId'
              @response[name] = value
            when 'product_code'
              @instance['productCodes'] << value
            when 'state'
              @instance['monitoring'][name] = (value == 'true')
            when 'subnetId'
              @response[name] = value
            when 'ebsOptimized'
              @instance['ebsOptimized'] = (value == 'true')
            when 'associatePublicIP'
              @instance['associatePublicIP'] = (value == 'true')
            end
          end
        end
      end
    end
  end
end