Class: VCloudSdk::Xml::Vm

Inherits:
Wrapper
  • Object
show all
Defined in:
lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb

Instance Method Summary collapse

Methods inherited from Wrapper

#==, #[], #[]=, #add_child, #attribute, #content, #content=, #create_child, #create_qualified_name, #create_xpath_query, #doc_namespaces, #edit_link, #get_nodes, #href, #href=, #href_id, #name, #name=, #power_off_link, #power_on_link, #remove_link, #running_tasks, #to_s, #type, #type=, #undeploy_link, #urn, #xpath

Constructor Details

#initialize(xml, ns = nil, ns_definitions = nil) ⇒ Vm

Returns a new instance of Vm.



4
5
6
7
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 4

def initialize(xml, ns = nil, ns_definitions = nil)
  super(xml, ns, ns_definitions)
  @logger = Config.logger
end

Instance Method Details

#add_hard_disk(capacity, bus_type, bus_sub_type) ⇒ Object

hardware modification methods



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 97

def add_hard_disk(capacity, bus_type, bus_sub_type)
  section = hardware_section
  # 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])
  new_disk.add_rasd(RASD_TYPES[:INSTANCE_ID])
  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)] = capacity.to_s
  host_resource[new_disk.create_qualified_name(
    "busSubType", VCLOUD_NAMESPACE)] = bus_sub_type
  host_resource[new_disk.create_qualified_name(
    "busType", VCLOUD_NAMESPACE)] = bus_type
end


23
24
25
26
27
28
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 23

def attach_disk_link
  get_nodes(XML_TYPE[:LINK],
            { rel: "disk:attach",
              type: MEDIA_TYPE[:DISK_ATTACH_DETACH_PARAMS] },
            true).first
end

#change_cpu_count(quantity) ⇒ Object



131
132
133
134
135
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 131

def change_cpu_count(quantity)
  @logger.debug("Updating CPU count on vm #{name} to #{quantity} ")
  item = hardware_section.cpu
  item.set_rasd("VirtualQuantity", quantity)
end

#change_memory(mb) ⇒ Object



137
138
139
140
141
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 137

def change_memory(mb)
  @logger.debug("Updating memory on vm #{name} to #{mb} MB")
  item = hardware_section.memory
  item.set_rasd("VirtualQuantity", mb)
end

#delete_hard_disk?(disk_name) ⇒ Boolean

Returns:

  • (Boolean)


120
121
122
123
124
125
126
127
128
129
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 120

def delete_hard_disk?(disk_name)
  hardware_section.hard_disks.each do |disk|
    if disk.element_name == disk_name
      disk.node.remove
      return true
    end
  end

  false
end

#delete_nics(*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)



146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 146

def delete_nics(*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
    @logger.info("Removing NIC #{nic_index} from VM #{name}")
    primary_index = net_conn_section.remove_network_connection(nic_index)
    vhw_section.remove_nic(nic_index)
    vhw_section.reconcile_primary_network(primary_index) if primary_index
  end
end

#descriptionObject



37
38
39
40
41
42
43
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 37

def description
  nodes = get_nodes("Description")
  return nodes unless nodes
  node = nodes.first
  return node unless node
  node.content
end

#description=(value) ⇒ Object



45
46
47
48
49
50
51
52
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 45

def description=(value)
  nodes = get_nodes("Description")
  return unless nodes
  node = nodes.first
  return unless node
  node.content = value
  value
end


30
31
32
33
34
35
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 30

def detach_disk_link
  get_nodes(XML_TYPE[:LINK],
            { rel: "disk:detach",
              type: MEDIA_TYPE[:DISK_ATTACH_DETACH_PARAMS] },
            true).first
end


66
67
68
69
70
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 66

def eject_media_link
  get_nodes(XML_TYPE[:LINK],
            { rel: "media:ejectMedia" },
            true).first
end

#hardware_sectionObject



78
79
80
81
82
83
84
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 78

def hardware_section
  get_nodes("VirtualHardwareSection",
            nil,
            false,
            OVF)
            .first
end


60
61
62
63
64
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 60

def insert_media_link
  get_nodes(XML_TYPE[:LINK],
            { rel: "media:insertMedia" },
            true).first
end


72
73
74
75
76
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 72

def 
  get_nodes(XML_TYPE[:LINK],
            { type: MEDIA_TYPE[:METADATA] },
            true).first
end

#network_connection_sectionObject



86
87
88
89
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 86

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

#product_sectionObject



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

def product_section
  get_nodes("ProductSection", nil, true, OVF).first
end


16
17
18
19
20
21
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 16

def product_sections_link
  get_nodes(XML_TYPE[:LINK],
            { type: MEDIA_TYPE[:PRODUCT_SECTIONS] },
            true)
            .first
end


54
55
56
57
58
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 54

def reconfigure_link
  get_nodes(XML_TYPE[:LINK],
            { rel: "reconfigureVm" },
            true).first
end

#set_nic_is_connected(nic_index, is_connected) ⇒ Object



161
162
163
164
165
166
167
168
169
170
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 161

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
    fail ObjectNotFoundError,
         "NIC #{nic_index} cannot be found on VM #{name}."
  end
  connection.is_connected = is_connected
  nil
end

#set_primary_nic(nic_index) ⇒ Object



172
173
174
175
176
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 172

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


9
10
11
12
13
14
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/vm.rb', line 9

def vapp_link
  get_nodes(XML_TYPE[:LINK],
            { type: MEDIA_TYPE[:VAPP] },
            true)
            .first
end