Additional Network Adapters

OK so I am trying to add an additional network adapter to a VM to use for PXE booting later on. It seems that on the odd occassion the adapter fails to be added. And the odd part is that its always the first VM in a batch that suffers from this issue. Its not consistent either. If I provision 20 VMs via API calls, the first may fail to add the 2ns NIC, but the next 19 always add the second NIC. I have tried multiple articles I have found on here (thank you).

Currently I have this code:
begin
$evm.log(:info, “PXE Configure NICs started”)
prov = $evm.root[‘miq_provision’]
vLAN = prov.options[:dialog_pxe_vlans]
$evm.log(:info, “PXE set provisioning NIC vLAN: mt02-native-vlan”)
$evm.log(:info, “PXE Set production NIC vLAN: #{vLAN}”)

  prov.set_option(:requested_network_adapter_count, 2)

  case vLAN
  when "vlan222"
    prov.set_network_adapter(0, {:network => 'vlan222', :devicetype => 'VirtualVmxnet3', :is_dvs => false})
  when "vlan111"
    prov.set_network_adapter(0, {:network => 'vlan111', :devicetype => 'VirtualVmxnet3', :is_dvs => false})
  end
  prov.set_nic_settings(0, {:addr_mode => ['dhcp', 'DHCP']})

  prov.set_network_adapter(1, {:network => 'vlan333', :devicetype => 'VirtualVmxnet3', :is_dvs => false})
  prov.set_nic_settings(1, {:addr_mode => ['dhcp', 'DHCP']}) 

  $evm.log(:info, "PXE Configure NICs complete")
end

exit MIQ_OK

As mentioned, it works 99% of the time, but if it fails, its the first VM (single or batch run).

I have also tried per another article the following code:

begin
  $evm.log(:info, "PXE Configure NICs started")
  prov       = $evm.root['miq_provision']
  vLAN       = prov.options[:dialog_pxe_vlans]
  $evm.log(:info, "PXE set provisioning NIC vLAN: vlan333")
  $evm.log(:info, "PXE Set production   NIC vLAN: #{vLAN}")
  prov.set_option(:requested_network_adapter_count, 2)

  networks = [{:network=>"#{vLAN}", :mac_address=>nil},
                        {:network=>"vlan333", :mac_address=>nil}]
  prov.set_option(:networks, networks)

  prov.set_nic_settings(0, {:addr_mode => ['dhcp', 'DHCP']})
  prov.set_nic_settings(1, {:addr_mode => ['dhcp', 'DHCP']}) 

  $evm.log(:info, "PXE Configure NICs complete")
end

exit MIQ_OK

Any suggestions as to why after setting the requested_network_adapter_count = 2 I would not get a second NIC on the VLAN as shown above? Its very odd behaviour and works 99% of the time except when it doesn’t :wink:

TIA