Class: Fog::Parsers::AWS::Compute::DescribeInstances

Inherits:
Base
  • Object
show all
Defined in:
lib/fog/aws/parsers/compute/describe_instances.rb

Instance Attribute Summary

Attributes inherited from Base

#response

Instance Method Summary collapse

Methods inherited from Base

#characters, #initialize

Constructor Details

This class inherits a constructor from Fog::Parsers::Base

Instance Method Details

#end_element(name) ⇒ Object



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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/fog/aws/parsers/compute/describe_instances.rb', line 34

def end_element(name)
  case name
  when 'amiLaunchIndex'
    @instance[name] = @value.to_i
  when 'availabilityZone'
    @instance['placement'][name] = @value
  when 'architecture', 'clientToken', 'dnsName', 'imageId',
        'instanceId', 'instanceType', 'ipAddress', 'kernelId',
        'keyName', 'privateDnsName', 'privateIpAddress', 'ramdiskId',
        'reason', 'rootDeviceType'
    @instance[name] = @value
  when 'attachTime'
    @block_device_mapping[name] = Time.parse(@value)
  when 'blockDeviceMapping'
    @in_block_device_mapping = false
  when 'code'
    if @in_instance_state
      @instance['instanceState'][name] = @value.to_i
    elsif @in_state_reason
      @instance['stateReason'][name] = @value.to_i
    end
  when 'deleteOnTermination'
    if @value == 'true'
      @block_device_mapping[name] = true
    else
      @block_device_mapping[name] = false
    end
  when 'deviceName', 'status', 'volumeId'
    @block_device_mapping[name] = @value
  when 'groupId'
    @reservation['groupSet'] << @value
  when 'groupSet', 'productCodes'
    @in_subset = false
  when 'instancesSet'
    @in_instances_set = false
  when 'instanceState'
    @in_instance_state = false
  when 'item'
    if @in_block_device_mapping
      @instance['blockDeviceMapping'] << @block_device_mapping
      @block_device_mapping = {}
    elsif @in_tag_set
      @instance['tagSet'][@tag['key']] = @tag['value']
      @tag = {}
    elsif @in_instances_set
      @reservation['instancesSet'] << @instance
      @instance = { 'blockDeviceMapping' => [], 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [], 'stateReason' => {}, 'tagSet' => {} }
    elsif !@in_subset
      @response['reservationSet'] << @reservation
      @reservation = { 'groupSet' => [], 'instancesSet' => [] }
    end
  when 'key', 'value'
    @tag[name] = @value
  when 'launchTime'
    @instance[name] = Time.parse(@value)
  when 'name'
    if @in_instance_state
      @instance['instanceState'][name] = @value
    elsif @in_state_reason
      @instance['stateReason'][name] = @value
    end
  when 'ownerId', 'reservationId'
    @reservation[name] = @value
  when 'requestId'
    @response[name] = @value
  when 'productCode'
    @instance['productCodes'] << @value
  when 'state'
    if @value == 'true'
      @instance['monitoring'][name] = true
    else
      @instance['monitoring'][name] = false
    end
  when 'stateReason'
    @in_state_reason = false
  when 'tagSet'
    @in_tag_set = false
  end
end

#resetObject



8
9
10
11
12
13
14
# File 'lib/fog/aws/parsers/compute/describe_instances.rb', line 8

def reset
  @block_device_mapping = {}
  @instance = { 'blockDeviceMapping' => [], 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [], 'stateReason' => {}, 'tagSet' => {} }
  @reservation = { 'groupSet' => [], 'instancesSet' => [] }
  @response = { 'reservationSet' => [] }
  @tag = {}
end

#start_element(name, attrs = []) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fog/aws/parsers/compute/describe_instances.rb', line 16

def start_element(name, attrs = [])
  super
  case name
  when 'blockDeviceMapping'
    @in_block_device_mapping = true
  when'groupSet', 'productCodes'
    @in_subset = true
  when 'instancesSet'
    @in_instances_set = true
  when 'instanceState'
    @in_instance_state = true
  when 'stateReason'
    @in_state_reason = true
  when 'tagSet'
    @in_tag_set = true
  end
end