Class: Fog::Parsers::Compute::VcloudDirector::Vm
Instance Attribute Summary
Attributes inherited from Base
#response
Instance Method Summary
collapse
#extract_attributes
Methods inherited from Base
#attr_value, #characters, #end_element_namespace, #initialize, #start_element_namespace, #value
Instance Method Details
#end_element(name) ⇒ Object
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
|
# File 'lib/fog/vcloud_director/parsers/compute/vm.rb', line 33
def end_element(name)
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'
if @resource_type == '17' @response[:vm][:disks] ||= []
@response[:vm][:disks] << { @element_name => @current_host_resource[:capacity].to_i }
end
when 'Link'
@response[:vm][:links] = @links
end
end
|
#human_status(status) ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/fog/vcloud_director/parsers/compute/vm.rb', line 64
def human_status(status)
case status
when '0', 0
'creating'
when '8', 8
'off'
when '4', 4
'on'
else
'unknown'
end
end
|
#reset ⇒ Object
8
9
10
11
12
13
14
|
# File 'lib/fog/vcloud_director/parsers/compute/vm.rb', line 8
def reset
@in_operating_system = false
@in_children = false
@resource_type = nil
@response = { :vm => { :ip_address => '' } }
@links = []
end
|
#start_element(name, attributes) ⇒ Object
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/fog/vcloud_director/parsers/compute/vm.rb', line 16
def start_element(name, attributes)
super
case name
when 'OperatingSystemSection'
@in_operating_system = true
when 'Vm'
vm_attrs = (attributes)
@response[:vm].merge!(vm_attrs.reject {|key,value| ![:href, :name, :status, :type].include?(key)})
@response[:vm][:id] = @response[:vm][:href].split('/').last
@response[:vm][:status] = human_status(@response[:vm][:status])
when 'HostResource'
@current_host_resource = (attributes)
when 'Link'
@links << (attributes)
end
end
|