Class: Fog::Parsers::Compute::VcloudDirector::Vm

Inherits:
VcloudDirectorParser show all
Includes:
VmParserHelper
Defined in:
lib/fog/vcloud_director/parsers/compute/vm.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


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
# File 'lib/fog/vcloud_director/parsers/compute/vm.rb', line 31

def end_element(name)
  parse_end_element name, @response[:vm]
  case name
  when 'IpAddress'
    @response[:vm][:ip_address] = value
  when 'Description'
    if @in_operating_system
      @response[:vm][:operating_system] = value
      @in_operating_system = false
    end
  when 'ResourceType'
    @resource_type = value
  when 'VirtualQuantity'
    case @resource_type
    when '3'
      @response[:vm][:cpu] = value
    when '4'
      @response[:vm][:memory] = value
    end
  when 'ElementName'
    @element_name = value
  when 'Item'
    case @resource_type
    when '17' # disk
      @response[:vm][:disks] ||= []
      @response[:vm][:disks] << { @element_name => @current_host_resource[:capacity].to_i }
    when '10' # nic
      @response[:vm][:network_adapters] ||= []
      @response[:vm][:network_adapters] << {
        :ip_address => @current_network_connection[:ipAddress],
        :primary => (@current_network_connection[:primaryNetworkConnection] == 'true'),
        :ip_allocation_mode => @current_network_connection[:ipAddressingMode]
      }
    end
  when 'Link'
    @response[:vm][:links] = @links
  end
end

#human_status(status) ⇒ Object


70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/fog/vcloud_director/parsers/compute/vm.rb', line 70

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
# File 'lib/fog/vcloud_director/parsers/compute/vm.rb', line 10

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

#start_element(name, attributes) ⇒ Object


18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fog/vcloud_director/parsers/compute/vm.rb', line 18

def start_element(name, attributes)
  super
  if name == 'Vm'
    vm_attrs = extract_attributes(attributes)
    @response[:vm].merge!(vm_attrs.reject {|key,value| ![:href, :name, :status, :type, :deployed].include?(key)})
    @response[:vm][:id] = @response[:vm][:href].split('/').last
    @response[:vm][:status] = human_status(@response[:vm][:status])
    @response[:vm][:deployed] = @response[:vm][:deployed] == 'true'
  else
    parse_start_element name, attributes, @response[:vm]
  end
end