How to adjust network_adapter, statement from



In the redhat handbook from the redhat site I find the following example to adjust the network adapter settings of a VMWare VM:

Example: prov.set_network_adapter(1, {:network => dvs_net1, :is_dvs => true} )

(2.24.3. VM Provision Task (miq_provision) -

When I apply this in the Cloudforms code, it does not work:


dvs_port_group = 'md1-bz-160’
log(:info, “Set Adapter Properties”)
prov.set_network_adapter(1, {:network => dvs_port_group, :devicetype => ‘VirtualVmxnet3’, :is_dvs => true})


[----] I, [2017-02-07T12:23:41.583256 #23391:63878bc] INFO – : Q-task_id([miq_provision_12000000000144]) set VM location - DVS Port group is: md1-bz-160
[----] I, [2017-02-07T12:23:41.801448 #23391:63878bc] INFO – : Q-task_id([miq_provision_12000000000144]) set VM location - prov: Option - networks: [nil, {:network=>“md1-bz-160”, :devicetype=>“VirtualVmxnet3”, :is_dvs=>true}]

[----] I, [2017-02-07T12:25:19.408967 #4766:ba7138] INFO – : Q-task_id([miq_provision_12000000000144]) Processed State=[CheckProvisioned] with Result=[error]
[----] W, [2017-02-07T12:25:19.409363 #4766:ba7138] WARN – : Q-task_id([miq_provision_12000000000144]) Error in State=[CheckProvisioned]
[----] I, [2017-02-07T12:25:19.409967 #4766:ba7138] INFO – : Q-task_id([miq_provision_12000000000144]) In State=[CheckProvisioned], invoking [on_error] method=[update_provision_status(status => '[NoMethodError]: undefined method []' for nil:NilClass')] [----] I, [2017-02-07T12:25:20.313058 #4766:ba7138] INFO -- : Q-task_id([miq_provision_12000000000144]) Invoking [inline] method [/ManageIQ/Infrastructure/VM/Provisioning/StateMachines/VMProvision_VM/update_provision_status] with inputs [{"status"=>"[NoMethodError]: undefined method[]"}]

The problem is that network adapter id ‘1’ is translated to ‘nil’. And subsequent the error ‘undefined method `[]’ for nil:NilClass’)]’ occurs. Is the original syntax from the redhat handbook wrong. What am I missing?


I am having this SAME exact issue. Did you ever figure out what was going on?


I found a resolution to this issue.

First off, this only occurs if the NIC in slot “0” is not defined directly when adding addtional nics. A BZ has been submitted and a correction has been made in the upstream. See below:

This is going to corrected in a near release. HOWEVER, here is a method you can use to get around the issue:

 #Collect items from our Service dialog.  add_nics is a check box thats true or false on the dialog. device_type comes from our instance variables.
$device_type = $evm.object['nic_type']

#Use this method to iterate through and add our nics.
def add_nics (nic_number, new_vlan)
  if nic_number.nil?
    $evm.log(:info, "Selected VLAN was empty. No NIC(s) to add")
    $evm.log(:info, "Creating NIC #{nic_number} with vlan/network #{new_vlan}")
    $prov.set_network_adapter(nic_number, {:network=>new_vlan, :devicetype=>$device_type, :is_dvs => false})

# We are setting the very first NIC below.  Important because the vmware network gem needs the first nic to be 0 before adding additional
# nics and we always refer to this nic as "vlan" in the service dialog.
add_nics(0, $prov.get_option(:vlan))

# Run through any additional vlan1-21 that may be present in the service dialog and create nics. 
position = 1
count = 1
for count in 1..21
  nic_name = "vlan#{count}"
  nic = $prov.get_option(nic_name.to_sym)
  if nic.nil?
    add_nics(position, nic)
    position = position + 1