Class: Fog::Parsers::Compute::AWS::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

#attr_value, #characters, #end_element_namespace, #initialize, #start_element_namespace, #value

Constructor Details

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

Instance Method Details

- (Object) end_element(name)



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

def end_element(name)
  case name
  when 'amiLaunchIndex'
    @instance[name] = value.to_i
  when 'arn'
    @instance[@context.last][name] = value
  when 'availabilityZone', 'tenancy'
    @instance['placement'][name] = value
  when 'architecture', 'clientToken', 'dnsName', 'hypervisor', 'imageId',
        'instanceId', 'instanceType', 'ipAddress', 'kernelId', 'keyName',
        'instanceLifecycle', 'platform', 'privateDnsName', 'privateIpAddress', 'ramdiskId',
        'reason', 'requesterId', 'rootDeviceType', 
        'spotInstanceRequestId', 'virtualizationType'
    @instance[name] = value
  when 'attachTime'
    @block_device_mapping[name] = Time.parse(value)
  when *@contexts
    @context.pop
  when 'code'
    @instance[@context.last][name] = @context.last == 'stateReason' ? value : value.to_i
  when 'message'
    @instance[@context.last][name] = value
  when 'deleteOnTermination'
    @block_device_mapping[name] = (value == 'true')
  when 'deviceName', 'status', 'volumeId'
    @block_device_mapping[name] = value
  when 'subnetId', 'vpcId', 'ownerId', 'networkInterfaceId', 'attachmentId'
    @network_interface[name] = value
    @instance[name] = value
  when 'groupId', 'groupName'
    case @context.last
    when 'groupSet'
      (name == 'groupName') ? current_key = 'groupSet' : current_key = 'groupIds'
      case @context[-2]
      when 'instancesSet'
        @reservation[current_key] << value
      when 'networkInterfaceSet'
        @network_interface[current_key] ||= []
        @network_interface[current_key] << value
      end
    when 'placement'
      @instance['placement'][name] = value
    end
  when 'id'
    @instance[@context.last][name] = value
  when 'item'
    case @context.last
    when 'blockDeviceMapping'
      @instance['blockDeviceMapping'] << @block_device_mapping
      @block_device_mapping = {}
    when 'networkInterfaceSet'
      @instance['networkInterfaces'] << @network_interface
      @network_interface = {}
    when 'instancesSet'
      @reservation['instancesSet'] << @instance
      @instance = { 'blockDeviceMapping' => [], 'networkInterfaces' => [], 'iamInstanceProfile' => {}, 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [], 'stateReason' => {}, 'tagSet' => {} }
    when 'tagSet'
      @instance['tagSet'][@tag['key']] = @tag['value']
      @tag = {}
    when 'blockDevices'
      # Ignore this one (Eucalyptus specific)
    when nil
      @response['reservationSet'] << @reservation
      @reservation = { 'groupIds' => [], 'groupSet' => [], 'instancesSet' => [] }
    end
  when 'key', 'value'
    @tag[name] = value
  when 'launchTime'
    @instance[name] = Time.parse(value)
  when 'name'
    @instance[@context.last][name] = value
  when 'ownerId', 'reservationId'
    @reservation[name] = value
  when 'requestId'
    @response[name] = value
  when 'productCode'
    @instance['productCodes'] << value
  when 'state'
    @instance['monitoring'][name] = (value == 'enabled')
  when 'ebsOptimized'
    @instance['ebsOptimized'] = (value == 'true')
  when 'sourceDestCheck'
    if value == 'true'
      @instance[name] = true
    else
      @instance[name] = false
    end
  # Eucalyptus passes status in schema non conforming way
  when 'stateCode'
    @instance['instanceState']['code'] = value
  when 'stateName'
    @instance['instanceState']['name'] = value
  end
end

- (Object) reset



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

def reset
  @block_device_mapping = {}
  @network_interface = {}
  @context = []
  @contexts = ['blockDevices', 'blockDeviceMapping', 'groupSet', 'iamInstanceProfile', 'instancesSet', 'instanceState', 'networkInterfaceSet', 'placement', 'productCodes', 'stateReason', 'tagSet']
  @instance = { 'blockDeviceMapping' => [], 'networkInterfaces' => [], 'iamInstanceProfile' => {}, 'instanceState' => {}, 'monitoring' => {}, 'placement' => {}, 'productCodes' => [], 'stateReason' => {}, 'tagSet' => {} }
  @reservation = { 'groupIds' => [], 'groupSet' => [], 'instancesSet' => [] }
  @response = { 'reservationSet' => [] }
  @tag = {}
end

- (Object) start_element(name, attrs = [])



19
20
21
22
23
24
# File 'lib/fog/aws/parsers/compute/describe_instances.rb', line 19

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