Allow configuration of manual mac address (#35504)
This commit is contained in:
parent
3a6f0fbb9c
commit
808f45db55
1 changed files with 9 additions and 4 deletions
|
@ -112,7 +112,7 @@ options:
|
|||
default: null
|
||||
vm_nic:
|
||||
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
|
||||
default: null
|
||||
vm_extra_config:
|
||||
|
@ -466,7 +466,7 @@ def add_floppy(module, s, config_target, config, devices, default_devs, type="im
|
|||
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
|
||||
# Different network card types are: "VirtualE1000",
|
||||
# "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:"
|
||||
" %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_backing(nic_backing)
|
||||
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(
|
||||
msg="Error on %s definition. network_type needs to be "
|
||||
" 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_nic(module, vsphere_client, nfmor, config, devices,
|
||||
nictype, network, network_type)
|
||||
nictype, network, network_type, mac_address)
|
||||
|
||||
config.set_element_deviceChange(devices)
|
||||
create_vm_request.set_element_config(config)
|
||||
|
|
Loading…
Reference in a new issue