Class: VCloudSdk::Xml::Vm

Inherits:
Wrapper
  • Object
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, #error, #get_nodes, #href, #href_id, #initialize, #to_s, #type, #urn, #xpath

Constructor Details

This class inherits a constructor from VCloudSdk::Xml::Wrapper

Instance Method Details

#add_hard_disk(size_mb) ⇒ Object

hardware modification methods



119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 119

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
  # Create a RASD item
  new_disk = WrapperFactory.create_instance("Item", nil,
    hardware_section.doc_namespaces)
  section.add_item(new_disk)
  # The order matters!
  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



169
170
171
172
173
174
175
176
177
178
179
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 169

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

#agent_idObject



99
100
101
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 99

def agent_id
   @root["agent_id"]
end

#agent_id=(value) ⇒ Object



103
104
105
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 103

def agent_id=(value)
   @root["agent_id"]= value
end


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



159
160
161
162
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 159

def change_cpu_count(quantity)
  item = hardware_section.cpu
  item.set_rasd("VirtualQuantity", quantity)
end

#change_memory(mb) ⇒ Object



164
165
166
167
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 164

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

NIC modification methods



183
184
185
186
187
188
189
190
191
192
193
194
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 183

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


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)



199
200
201
202
203
204
205
206
207
208
209
210
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 199

def delete_nic(*nics)
  # Trying to remove a NIC without removing the network connection
  # first will cause an error.  Removing the network connection of a NIC
  # in the NetworkConnectionSection will automatically delete the NIC.
  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

#descriptionObject



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


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_stateObject



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


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



150
151
152
153
154
155
156
157
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 150

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_sectionObject



107
108
109
110
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 107

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 
  get_nodes("Link", {"type" => MEDIA_TYPE[:METADATA]}, true).first
end

#nameObject



91
92
93
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 91

def name
   @root["name"]
end

#name=(value) ⇒ Object



95
96
97
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 95

def name=(value)
   @root["name"]= value
end

#network_connection_sectionObject



112
113
114
115
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 112

def network_connection_section
  get_nodes("NetworkConnectionSection",
    {"type" => MEDIA_TYPE[:NETWORK_CONNECTION_SECTION]}).first
end


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


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

#prerunning_tasksObject



79
80
81
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 79

def prerunning_tasks
  tasks.find_all { |t| PRE_RUNNING_TASK_STATUSES.include?(t.status) }
end


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


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_tasksObject



83
84
85
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 83

def running_tasks
  get_nodes("Task", {"status" => "running"})
end

#set_nic_is_connected(nic_index, is_connected) ⇒ Object



212
213
214
215
216
217
218
219
220
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 212

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



222
223
224
225
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 222

def set_primary_nic(nic_index)
  net_conn_section = network_connection_section
  net_conn_section.primary_network_connection_index = nic_index
end

#tasksObject



87
88
89
# File 'lib/cloud/vcloud/xml/wrapper_classes/vm.rb', line 87

def tasks
  get_nodes("Task")
end


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