vmware_guest: Fix VM creation when adding a network device without a MAC address (#24138)

* vmware_guest: Fix VM creation when adding a network device without a MAC address

* Provide python2.4 compatibility
pull/24636/merge
Lemar Carthens 8 years ago committed by jctanner
parent e5cd675b38
commit ef13f0f389

@ -238,13 +238,19 @@ def gather_vm_facts(content, vm):
if not hasattr(entry, 'macAddress'): if not hasattr(entry, 'macAddress'):
continue continue
if entry.macAddress:
mac_addr = entry.macAddress
mac_addr_dash = mac_addr.replace(':', '-')
else:
mac_addr = mac_addr_dash = None
factname = 'hw_eth' + str(ethernet_idx) factname = 'hw_eth' + str(ethernet_idx)
facts[factname] = { facts[factname] = {
'addresstype': entry.addressType, 'addresstype': entry.addressType,
'label': entry.deviceInfo.label, 'label': entry.deviceInfo.label,
'macaddress': entry.macAddress, 'macaddress': mac_addr,
'ipaddresses': net_dict.get(entry.macAddress, None), 'ipaddresses': net_dict.get(entry.macAddress, None),
'macaddress_dash': entry.macAddress.replace(':', '-'), 'macaddress_dash': mac_addr_dash,
'summary': entry.deviceInfo.summary, 'summary': entry.deviceInfo.summary,
} }
facts['hw_interfaces'].append('eth' + str(ethernet_idx)) facts['hw_interfaces'].append('eth' + str(ethernet_idx))

@ -399,7 +399,6 @@ class PyVmomiDeviceHelper(object):
(device_type, device_infos['name'])) (device_type, device_infos['name']))
nic.device.wakeOnLanEnabled = True nic.device.wakeOnLanEnabled = True
nic.device.addressType = 'assigned'
nic.device.deviceInfo = vim.Description() nic.device.deviceInfo = vim.Description()
nic.device.deviceInfo.label = device_label nic.device.deviceInfo.label = device_label
nic.device.deviceInfo.summary = device_infos['name'] nic.device.deviceInfo.summary = device_infos['name']
@ -408,7 +407,10 @@ class PyVmomiDeviceHelper(object):
nic.device.connectable.allowGuestControl = True nic.device.connectable.allowGuestControl = True
nic.device.connectable.connected = True nic.device.connectable.connected = True
if 'mac' in device_infos: if 'mac' in device_infos:
nic.device.addressType = 'assigned'
nic.device.macAddress = device_infos['mac'] nic.device.macAddress = device_infos['mac']
else:
nic.device.addressType = 'generated'
return nic return nic

Loading…
Cancel
Save