Class: Fog::Parsers::Compute::VcloudDirector::Vms

Inherits:
VcloudDirectorParser show all
Includes:
VmParserHelper
Defined in:
lib/fog/vcloud_director/parsers/compute/vms.rb

Instance Method Summary collapse

Methods included from VmParserHelper

#parse_end_element, #parse_start_element

Methods inherited from VcloudDirectorParser

#extract_attributes

Instance Method Details

#end_element(name) ⇒ Object



41
42
43
44
45
46
47
48
49
50
# File 'lib/fog/vcloud_director/parsers/compute/vms.rb', line 41

def end_element(name)
  if @in_children
    if name == 'Vm'
      @response[:vms] << @vm
      @vm = {}
    else
      parse_end_element name, @vm
    end
  end
end

#human_status(status) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/fog/vcloud_director/parsers/compute/vms.rb', line 52

def human_status(status)
  case status
  when '0', 0
    'creating'
  when '8', 8
    'off'
  when '4', 4
    'on'
  else
    'unknown'
  end
end

#resetObject



10
11
12
13
14
15
16
17
# File 'lib/fog/vcloud_director/parsers/compute/vms.rb', line 10

def reset
  @vm = { :ip_address => '' }
  @in_operating_system = false
  @in_children = false
  @resource_type = nil
  @response = { :vms => [] }
  @links = []
end

#start_element(name, attributes) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fog/vcloud_director/parsers/compute/vms.rb', line 19

def start_element(name, attributes)
  super
  case name
  when 'Vm'
    vapp = extract_attributes(attributes)
    @vm.merge!(vapp.reject {|key,value| ![:href, :name, :status, :type, :deployed].include?(key)})
    @vm[:deployed] = response[:deployed] == 'true'
    @vm[:id] = @vm[:href].split('/').last
    @vm[:vapp_id] = @response[:id]
    @vm[:vapp_name] = @response[:name]
    @vm[:status] = human_status(@vm[:status])
  when 'VApp'
    vapp = extract_attributes(attributes)
    @response.merge!(vapp.reject {|key,value| ![:href, :name, :size, :status, :type].include?(key)})
    @response[:id] = @response[:href].split('/').last
  when 'Children'
    @in_children = true
  else
    parse_start_element name, attributes, @vm
  end
end