Allow configuration of manual mac address (#35504)

This commit is contained in:
Pierrick Caillon 2018-03-01 15:54:40 +01:00 committed by Abhijeet Kasurde
parent 3a6f0fbb9c
commit 808f45db55

View file

@ -112,7 +112,7 @@ options:
default: null default: null
vm_nic: vm_nic:
description: description:
- A key, value list of nics, their types and what network to put them on. - A key, value list of nics, their types and what network to put them on. Optionaly with their MAC address.
required: false required: false
default: null default: null
vm_extra_config: vm_extra_config:
@ -466,7 +466,7 @@ def add_floppy(module, s, config_target, config, devices, default_devs, type="im
devices.append(floppy_spec) devices.append(floppy_spec)
def add_nic(module, s, nfmor, config, devices, nic_type="vmxnet3", network_name="VM Network", network_type="standard"): def add_nic(module, s, nfmor, config, devices, nic_type="vmxnet3", network_name="VM Network", network_type="standard", mac_address=None):
# add a NIC # add a NIC
# Different network card types are: "VirtualE1000", # Different network card types are: "VirtualE1000",
# "VirtualE1000e","VirtualPCNet32", "VirtualVmxnet", "VirtualNmxnet2", # "VirtualE1000e","VirtualPCNet32", "VirtualVmxnet", "VirtualNmxnet2",
@ -516,6 +516,10 @@ def add_nic(module, s, nfmor, config, devices, nic_type="vmxnet3", network_name=
msg="Error adding nic backing to vm spec. No network type of:" msg="Error adding nic backing to vm spec. No network type of:"
" %s" % (network_type)) " %s" % (network_type))
if mac_address:
nic_ctlr.set_element_addressType('manual')
nic_ctlr.set_element_macAddress(mac_address)
else:
nic_ctlr.set_element_addressType("generated") nic_ctlr.set_element_addressType("generated")
nic_ctlr.set_element_backing(nic_backing) nic_ctlr.set_element_backing(nic_backing)
nic_ctlr.set_element_key(4) nic_ctlr.set_element_key(4)
@ -1447,9 +1451,10 @@ def create_vm(vsphere_client, module, esxi, resource_pool, cluster_name, guest,
module.fail_json( module.fail_json(
msg="Error on %s definition. network_type needs to be " msg="Error on %s definition. network_type needs to be "
" specified." % nic) " specified." % nic)
mac_address = vm_nic[nic]['mac_address'] if 'mac_address' in vm_nic[nic] else None
# Add the nic to the VM spec. # Add the nic to the VM spec.
add_nic(module, vsphere_client, nfmor, config, devices, add_nic(module, vsphere_client, nfmor, config, devices,
nictype, network, network_type) nictype, network, network_type, mac_address)
config.set_element_deviceChange(devices) config.set_element_deviceChange(devices)
create_vm_request.set_element_config(config) create_vm_request.set_element_config(config)