Class: VCloudSdk::Xml::NicItemWrapper

Inherits:
Item show all
Defined in:
lib/cloud/vcloud/xml/wrapper_classes/nic_item_wrapper.rb

Instance Method Summary collapse

Methods inherited from Item

#add_rasd, #edit_link, #get_rasd, #get_rasd_content, #set_rasd

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, #name, #name=, #to_s, #type, #urn, #xpath

Constructor Details

#initialize(item) ⇒ NicItemWrapper

Returns a new instance of NicItemWrapper.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cloud/vcloud/xml/wrapper_classes/nic_item_wrapper.rb', line 5

def initialize(item)
  super(item.node, item.namespace, item.namespace_definitions)

  # Ensure the underlying XML has all the necessary RASD elements.
  # This is useful for NIC creation.
  # Should have no effect when receiving XML from VCD.
  [:ADDRESS_ON_PARENT, :CONNECTION, :INSTANCE_ID].each { |t|
    rt = RASD_TYPES[t]
    add_rasd(rt) unless get_rasd(rt) }

  rt = RASD_TYPES[:RESOURCE_SUB_TYPE]
  unless get_rasd(rt)
    add_rasd(rt)
    set_rasd(rt, RESOURCE_SUB_TYPE[:VMXNET3])
  end

  rt = RASD_TYPES[:RESOURCE_TYPE]
  unless get_rasd(rt)
    add_rasd(rt)
    set_rasd(rt, HARDWARE_TYPE[:NIC])
  end
end

Instance Method Details

#ip_addressing_modeObject



46
47
48
49
# File 'lib/cloud/vcloud/xml/wrapper_classes/nic_item_wrapper.rb', line 46

def ip_addressing_mode
  attr = create_qualified_name("ipAddressingMode", VCLOUD_NAMESPACE)
  connection[attr]
end

#is_primaryObject



28
29
30
# File 'lib/cloud/vcloud/xml/wrapper_classes/nic_item_wrapper.rb', line 28

def is_primary
  connection["primaryNetworkConnection"]
end

#is_primary=(value) ⇒ Object



32
33
34
35
36
# File 'lib/cloud/vcloud/xml/wrapper_classes/nic_item_wrapper.rb', line 32

def is_primary=(value)
  primary_attr = create_qualified_name("primaryNetworkConnection",
    VCLOUD_NAMESPACE)
  connection[primary_attr] = value.to_s
end

#mac_addressObject



69
70
71
# File 'lib/cloud/vcloud/xml/wrapper_classes/nic_item_wrapper.rb', line 69

def mac_address
  get_rasd_content(RASD_TYPES[:ADDRESS])
end

#networkObject



73
74
75
# File 'lib/cloud/vcloud/xml/wrapper_classes/nic_item_wrapper.rb', line 73

def network
  connection.content
end

#network=(value) ⇒ Object



77
78
79
# File 'lib/cloud/vcloud/xml/wrapper_classes/nic_item_wrapper.rb', line 77

def network=(value)
  connection.content = value
end

#nic_indexObject



38
39
40
# File 'lib/cloud/vcloud/xml/wrapper_classes/nic_item_wrapper.rb', line 38

def nic_index
  get_rasd_content(RASD_TYPES[:ADDRESS_ON_PARENT])
end

#nic_index=(value) ⇒ Object



42
43
44
# File 'lib/cloud/vcloud/xml/wrapper_classes/nic_item_wrapper.rb', line 42

def nic_index=(value)
  set_rasd(RASD_TYPES[:ADDRESS_ON_PARENT], value)
end

#set_ip_addressing_mode(mode, ip = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/cloud/vcloud/xml/wrapper_classes/nic_item_wrapper.rb', line 51

def set_ip_addressing_mode(mode, ip = nil)
  unless IP_ADDRESSING_MODE.values.include?(mode)
    raise ArgumentError, "Invalid choice for IP addressing mode."
  end

  if ip && !ip_addressing_mode == IP_ADDRESSING_MODE[:MANUAL]
    raise ArgumentError,
      "Cannot set IP address unless IP addressing mode is MANUAL"
  end

  mode_attr = create_qualified_name("ipAddressingMode",
    VCLOUD_NAMESPACE)
  connection[mode_attr] = mode

  ip_attr =  create_qualified_name("ipAddress", VCLOUD_NAMESPACE)
  connection[ip_attr] = !ip.nil? ? ip : ""
end