Class: VCloudSdk::Xml::VirtualHardwareSection

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

Instance Method Summary collapse

Methods inherited from Wrapper

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

Constructor Details

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

Instance Method Details

#add_item(item) ⇒ Object



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

def add_item(item)
  system_node = get_nodes("System", nil, true, OVF).first
  system_node.node.after(item.node)
end

#cpuObject



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

def cpu
  hardware.find do |h|
    h.get_rasd_content(RASD_TYPES[:RESOURCE_TYPE]) == HARDWARE_TYPE[:CPU]
  end
end


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

def edit_link
  get_nodes(XML_TYPE[:LINK],
            { rel: XML_TYPE[:EDIT],
              type: MEDIA_TYPE[:VIRTUAL_HARDWARE_SECTION] },
            true).first
end

#hard_disksObject



75
76
77
78
79
80
81
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/virtual_hardware_section.rb', line 75

def hard_disks
  items = hardware.select do |h|
    h.get_rasd_content(
    RASD_TYPES[:RESOURCE_TYPE]) == HARDWARE_TYPE[:HARD_DISK]
  end
  items.map { |i| HardDiskItemWrapper.new(i) }
end

#hardwareObject



83
84
85
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/virtual_hardware_section.rb', line 83

def hardware
  get_nodes("Item", nil, false, OVF)
end

#highest_instance_idObject



33
34
35
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/virtual_hardware_section.rb', line 33

def highest_instance_id
  hardware.map{|h| h.instance_id}.max
end

#memoryObject



22
23
24
25
26
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/virtual_hardware_section.rb', line 22

def memory
  hardware.find do |h|
    h.get_rasd_content(RASD_TYPES[:RESOURCE_TYPE]) == HARDWARE_TYPE[:MEMORY]
  end
end

#nicsObject



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

def nics
  items = hardware.select do |h|
    h.get_rasd_content(RASD_TYPES[:RESOURCE_TYPE]) == HARDWARE_TYPE[:NIC]
  end
  items.map { |i| NicItemWrapper.new(i) }
end

#reconcile_primary_network(primary_index) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/virtual_hardware_section.rb', line 62

def reconcile_primary_network(primary_index)
  primary_index = primary_index.to_s
  hardware.select do |item|
    item.get_rasd_content(RASD_TYPES[:RESOURCE_TYPE]) == HARDWARE_TYPE[:NIC]
  end.each do |item|
    if item.get_rasd_content(RASD_TYPES[:ADDRESS_ON_PARENT]) == primary_index
      item.get_rasd(RASD_TYPES[:CONNECTION]).attribute("primaryNetworkConnection").value = "true"
    else
      item.get_rasd(RASD_TYPES[:CONNECTION]).attribute("primaryNetworkConnection").value = "false"
    end
  end
end

#remove_hw(hw_type, index) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/virtual_hardware_section.rb', line 48

def remove_hw(hw_type, index)
  index = index.to_s
  item = hardware.find do |h|
    h.get_rasd_content(RASD_TYPES[:RESOURCE_TYPE]) == hw_type &&
      h.get_rasd_content(RASD_TYPES[:ADDRESS_ON_PARENT]) == index
  end
  if item
    item.node.remove
  else
    fail ObjectNotFoundError,
         "Cannot remove hw item #{hw_type}:#{index}, does not exist."
  end
end

#remove_nic(index) ⇒ Object



44
45
46
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/virtual_hardware_section.rb', line 44

def remove_nic(index)
  remove_hw(HARDWARE_TYPE[:NIC], index)
end

#scsi_controllerObject



28
29
30
31
# File 'lib/ruby_vcloud_sdk/xml/wrapper_classes/virtual_hardware_section.rb', line 28

def scsi_controller
  hardware.find { |h| h.get_rasd_content(RASD_TYPES[:RESOURCE_TYPE]) ==
    HARDWARE_TYPE[:SCSI_CONTROLLER] }
end