Class: Fog::Parsers::AWS::EC2::RunInstances

Inherits:
Base
  • Object
show all
Defined in:
lib/fog/aws/parsers/ec2/run_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


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
# File 'lib/fog/aws/parsers/ec2/run_instances.rb', line 26

def end_element(name)
  case name
  when 'amiLaunchIndex'
    @instance[name] = @value.to_i
  when 'architecture', 'dnsName', 'imageId', 'instanceId',
        'instanceType', 'ipAddress', 'kernelId', 'keyName',
        'privateDnsName', 'privateIpAddress', 'ramdiskId', 'reason',
        'rootDeviceType'
    @instance[name] = @value
  when 'availabilityZone'
    @instance['placement'][name] = @value
  when 'attachTime'
    @block_device_mapping[name] = Time.parse(@value)
  when 'blockDeviceMapping'
    @in_block_device_mapping = false
  when 'code'
    @instance['instanceState'][name] = @value.to_i
  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'
    @response['groupSet'] << @value
  when 'groupSet'
    @in_group_set = false
  when 'item'
    if @in_block_device_mapping
      @instance['blockDeviceMapping'] << @block_device_mapping
      @block_device_mapping = {}
    elsif !@in_group_set && !@in_product_codes
      @response['instancesSet'] << @instance
      @instance = { '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 'productCodes'
    @in_product_codes = false
  when 'state'
    if @value == 'true'
      @instance['monitoring'][name] = true
    else
      @instance['monitoring'][name] = false
    end
  end
end

#resetObject


8
9
10
11
12
# File 'lib/fog/aws/parsers/ec2/run_instances.rb', line 8

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

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


14
15
16
17
18
19
20
21
22
23
24
# File 'lib/fog/aws/parsers/ec2/run_instances.rb', line 14

def start_element(name, attrs = [])
  case name
  when 'blockDeviceMapping'
    @in_block_device_mapping = true
  when 'groupSet'
    @in_group_set = true
  when 'productCodes'
    @in_product_codes = true
  end
  @value = ''
end