Class: VCloudSdk::Xml::Vm
- Inherits:
-
Wrapper
show all
- Defined in:
- lib/cloud/vcloud/xml/wrapper_classes/vm.rb
Instance Method Summary
collapse
Methods inherited from Wrapper
#==, #[], #[]=, #add_child, #attribute_with_ns, #content, #content=, #create_child, #create_qualified_name, #create_xpath_query, #doc_namespaces, #get_nodes, #href, #initialize, #to_s, #type, #urn, #xpath
Instance Method Details
#add_hard_disk(size_mb) ⇒ Object
hardware modification methods
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
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 107
def add_hard_disk(size_mb)
section = hardware_section
scsi_controller = section.scsi_controller
unless scsi_controller
raise ObjectNotFoundError, "No SCSI controller found for VM #{name}"
end
new_disk = WrapperFactory.create_instance("Item", nil,
hardware_section.doc_namespaces)
section.add_item(new_disk)
new_disk.add_rasd(RASD_TYPES[:HOST_RESOURCE])
instance_id_type = RASD_TYPES[:INSTANCE_ID]
new_disk.add_rasd(instance_id_type)
new_disk.set_rasd(instance_id_type, section.highest_instance_id + 1)
rt = RASD_TYPES[:RESOURCE_TYPE]
new_disk.add_rasd(rt)
new_disk.set_rasd(rt, HARDWARE_TYPE[:HARD_DISK])
host_resource = new_disk.get_rasd(RASD_TYPES[:HOST_RESOURCE])
host_resource[new_disk.create_qualified_name(
"capacity", VCLOUD_NAMESPACE)] = size_mb.to_s
host_resource[new_disk.create_qualified_name(
"busSubType", VCLOUD_NAMESPACE)] = scsi_controller.get_rasd_content(
RASD_TYPES[:RESOURCE_SUB_TYPE])
host_resource[new_disk.create_qualified_name(
"busType", VCLOUD_NAMESPACE)] = HARDWARE_TYPE[:SCSI_CONTROLLER]
end
|
#add_nic(nic_index, network_name, addressing_mode, ip = nil) ⇒ Object
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 157
def add_nic(nic_index, network_name, addressing_mode, ip = nil)
section = hardware_section
is_primary = hardware_section.nics.length == 0
new_nic = Xml::NicItemWrapper.new(Xml::WrapperFactory.create_instance(
"Item", nil, hardware_section.doc_namespaces))
section.add_item(new_nic)
new_nic.nic_index = nic_index
new_nic.network = network_name
new_nic.set_ip_addressing_mode(addressing_mode, ip)
new_nic.is_primary = is_primary
end
|
#attach_disk_link ⇒ Object
5
6
7
8
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 5
def attach_disk_link
get_nodes("Link", {"rel" => "disk:attach",
"type" => MEDIA_TYPE[:DISK_ATTACH_DETACH_PARAMS]}, true).first
end
|
#change_cpu_count(quantity) ⇒ Object
147
148
149
150
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 147
def change_cpu_count(quantity)
item = hardware_section.cpu
item.set_rasd("VirtualQuantity", quantity)
end
|
#change_memory(mb) ⇒ Object
152
153
154
155
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 152
def change_memory(mb)
item = hardware_section.memory
item.set_rasd("VirtualQuantity", mb)
end
|
#connect_nic(nic_index, network_name, addressing_mode, ip_address = nil) ⇒ Object
171
172
173
174
175
176
177
178
179
180
181
182
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 171
def connect_nic(nic_index, network_name, addressing_mode,
ip_address = nil)
section = network_connection_section
new_connection = WrapperFactory.create_instance("NetworkConnection",
nil, network_connection_section.doc_namespaces)
section.add_item(new_connection)
new_connection.network_connection_index = nic_index
new_connection.network = network_name
new_connection.ip_address_allocation_mode = addressing_mode
new_connection.ip_address = ip_address if ip_address
new_connection.is_connected = true
end
|
#container_vapp_link ⇒ Object
75
76
77
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 75
def container_vapp_link
get_nodes("Link", {"type" => MEDIA_TYPE[:VAPP]}, true).first
end
|
#delete_nic(*nics) ⇒ Object
Deletes NIC from VM. Accepts variable number of arguments for NICs. To delete all NICs from VM use the splat operator ex: delete_nic(vm, *vm.hardware_section.nics)
187
188
189
190
191
192
193
194
195
196
197
198
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 187
def delete_nic(*nics)
net_conn_section = network_connection_section
vhw_section = hardware_section
nics.each do |nic|
nic_index = nic.nic_index
net_conn_section.remove_network_connection(nic_index)
vhw_section.remove_nic(nic_index)
end
end
|
#description ⇒ Object
10
11
12
13
14
15
16
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 10
def description
nodes = get_nodes("Description")
return nodes unless nodes
node = nodes.first
return node unless node
node.content
end
|
#description=(value) ⇒ Object
18
19
20
21
22
23
24
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 18
def description=(value)
nodes = get_nodes("Description")
return unless nodes
node = nodes.first
return unless node
node.content = value
end
|
#detach_disk_link ⇒ Object
26
27
28
29
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 26
def detach_disk_link
get_nodes("Link", {"rel" => "disk:detach",
"type" => MEDIA_TYPE[:DISK_ATTACH_DETACH_PARAMS]}, true).first
end
|
#discard_state ⇒ Object
51
52
53
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 51
def discard_state
get_nodes("Link", {"rel" => "discardState"}, true).first
end
|
#edit_link ⇒ Object
55
56
57
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 55
def edit_link
get_nodes("Link", {"rel" => "edit"}, true).first
end
|
67
68
69
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 67
def eject_media_link
get_nodes("Link", {"rel" => "media:ejectMedia"}, true).first
end
|
#find_attached_disk(disk) ⇒ Object
138
139
140
141
142
143
144
145
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 138
def find_attached_disk(disk)
href = disk.is_a?(String) ? disk : disk.href
hardware_section.hard_disks.find do |d|
hard_disk_href = d.disk_href
next if hard_disk_href.nil?
hard_disk_href == href
end
end
|
#hardware_section ⇒ Object
95
96
97
98
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 95
def hardware_section
get_nodes("VirtualHardwareSection", nil, false,
"http://schemas.dmtf.org/ovf/envelope/1").first
end
|
63
64
65
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 63
def insert_media_link
get_nodes("Link", {"rel" => "media:insertMedia"}, true).first
end
|
71
72
73
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 71
def metadata_link
get_nodes("Link", {"type" => MEDIA_TYPE[:METADATA]}, true).first
end
|
#name ⇒ Object
87
88
89
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 87
def name
@root["name"]
end
|
#name=(value) ⇒ Object
91
92
93
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 91
def name=(value)
@root["name"]= value
end
|
#network_connection_section ⇒ Object
100
101
102
103
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 100
def network_connection_section
get_nodes("NetworkConnectionSection",
{"type" => MEDIA_TYPE[:NETWORK_CONNECTION_SECTION]}).first
end
|
#power_off_link ⇒ Object
35
36
37
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 35
def power_off_link
get_nodes("Link", {"rel" => "power:powerOff"}, true).first
end
|
#power_on_link ⇒ Object
31
32
33
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 31
def power_on_link
get_nodes("Link", {"rel" => "power:powerOn"}, true).first
end
|
#reboot_link ⇒ Object
39
40
41
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 39
def reboot_link
get_nodes("Link", {"rel" => "power:reboot"}, true).first
end
|
59
60
61
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 59
def reconfigure_link
get_nodes("Link", {"rel" => "reconfigureVm"}, true).first
end
|
#remove_link(force = false) ⇒ Object
47
48
49
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 47
def remove_link(force = false)
get_nodes("Link", {"rel" => "remove"}, true).first
end
|
#running_tasks ⇒ Object
79
80
81
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 79
def running_tasks
get_nodes("Task", {"status" => "running"})
end
|
#set_nic_is_connected(nic_index, is_connected) ⇒ Object
200
201
202
203
204
205
206
207
208
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 200
def set_nic_is_connected(nic_index, is_connected)
net_conn_section = network_connection_section
connection = net_conn_section.network_connection(nic_index)
unless connection
raise ObjectNotFoundError,
"NIC #{nic_index} cannot be found on VM #{name}."
end
connection.is_connected = is_connected
end
|
#set_primary_nic(nic_index) ⇒ Object
210
211
212
213
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 210
def set_primary_nic(nic_index)
net_conn_section = network_connection_section
net_conn_section.primary_network_connection_index = nic_index
end
|
#tasks ⇒ Object
83
84
85
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 83
def tasks
get_nodes("Task")
end
|
#undeploy_link ⇒ Object
43
44
45
|
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 43
def undeploy_link
get_nodes("Link", {"rel" => "undeploy"}, true).first
end
|