Class: Awsum::Ec2::InstanceParser

Inherits:
Parser show all
Defined in:
lib/ec2/instance.rb

Overview

:nodoc:

Instance Method Summary collapse

Methods inherited from Parser

#parse, #xmldecl

Constructor Details

#initialize(ec2) ⇒ InstanceParser

Returns a new instance of InstanceParser.



58
59
60
61
62
63
64
65
# File 'lib/ec2/instance.rb', line 58

def initialize(ec2)
  @ec2 = ec2
  @instances = []
  @text = nil
  @stack = []
  @placement = nil
  @state = nil
end

Instance Method Details

#resultObject



139
140
141
# File 'lib/ec2/instance.rb', line 139

def result
  @instances
end

#tag_end(tag) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/ec2/instance.rb', line 96

def tag_end(tag)
  case tag
    when 'DescribeInstancesResponse', 'requestId', 'reservationId'
      #no-op
    when 'reservationSet', 'instancesSet', 'productCodes', 'instanceState', 'placement'
      @stack.pop
    when 'item'
      case @stack[-1]
        when 'instancesSet'
          @instances << Instance.new(
                          @ec2,
                          @current['instanceId'], 
                          @current['imageId'], 
                          @current['instanceType'], 
                          @state,
                          @current['dnsName'], 
                          @current['privateDnsName'], 
                          @current['keyName'],
                          @current['kernalId'], 
                          Time.parse(@current['launchTime']),
                          @placement,
                          @product_codes || [],
                          @current['ramdisk_id'], 
                          @current['reason'],
                          @current['amiLaunchIndex'].to_i
                        )
      end
    when 'productCode'
      @product_codes << @text.strip
    when 'availabilityZone'
      @placement = @text.strip
    when 'code'
      @state[:code] = @text.strip.to_i if @stack[-1] == 'instanceState'
    when 'name'
      @state[:name] = @text.strip if @stack[-1] == 'instanceState'
    else
      unless @text.nil? || @current.nil?
        text = @text.strip
        @current[tag] = (text == '' ? nil : text)
      end
  end
end

#tag_start(tag, attributes) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/ec2/instance.rb', line 67

def tag_start(tag, attributes)
  case tag
    when 'reservationSet'
      @stack << 'reservationSet'
    when 'instancesSet'
      @stack << 'instancesSet'
    when 'productCodes'
      @stack << 'productCodes'
    when 'instanceState'
      @stack << 'instanceState'
    when 'placement'
      @stack << 'placement'
    when 'item'
      case @stack[-1]
        when 'reservationSet'
        when 'instancesSet'
          @current = {}
          @state = {}
        when 'productCodes'
          @product_codes = []
      end
  end
  @text = ''
end

#text(text) ⇒ Object



92
93
94
# File 'lib/ec2/instance.rb', line 92

def text(text)
  @text << text unless @text.nil?
end