From 7fbe19c04745a3351f5915a8109e3c71bcb938c8 Mon Sep 17 00:00:00 2001 From: reversecipher Date: Thu, 11 Jan 2018 00:57:08 +0200 Subject: [PATCH] vmware_guest: fix dvs idempotency issue (#34208) * vmware_guest: fix dvs idempotency issue * Rewrite VDS section * Fix PEP 8 error --- .../modules/cloud/vmware/vmware_guest.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/ansible/modules/cloud/vmware/vmware_guest.py b/lib/ansible/modules/cloud/vmware/vmware_guest.py index e9a5b66d93..5376cc2b42 100644 --- a/lib/ansible/modules/cloud/vmware/vmware_guest.py +++ b/lib/ansible/modules/cloud/vmware/vmware_guest.py @@ -944,18 +944,15 @@ class PyVmomiHelper(PyVmomi): # VDS switch pg_obj = find_obj(self.content, [vim.dvs.DistributedVirtualPortgroup], network_devices[key]['name']) - if (nic.device.backing and not hasattr(nic.device.backing, 'port')): + if (nic.device.backing and not hasattr(nic.device.backing, 'port')) or \ + (nic.device.backing and (nic.device.backing.port.portgroupKey != pg_obj.key or + nic.device.backing.port.switchUuid != pg_obj.config.distributedVirtualSwitch.uuid)): + dvs_port_connection = vim.dvs.PortConnection() + dvs_port_connection.portgroupKey = pg_obj.key + dvs_port_connection.switchUuid = pg_obj.config.distributedVirtualSwitch.uuid + nic.device.backing = vim.vm.device.VirtualEthernetCard.DistributedVirtualPortBackingInfo() + nic.device.backing.port = dvs_port_connection nic_change_detected = True - elif (nic.device.backing and (nic.device.backing.port.portgroupKey != pg_obj.key or - nic.device.backing.port.switchUuid != pg_obj.config.distributedVirtualSwitch.uuid)): - nic_change_detected = True - - dvs_port_connection = vim.dvs.PortConnection() - dvs_port_connection.portgroupKey = pg_obj.key - dvs_port_connection.switchUuid = pg_obj.config.distributedVirtualSwitch.uuid - nic.device.backing = vim.vm.device.VirtualEthernetCard.DistributedVirtualPortBackingInfo() - nic.device.backing.port = dvs_port_connection - nic_change_detected = True else: # vSwitch if not isinstance(nic.device.backing, vim.vm.device.VirtualEthernetCard.NetworkBackingInfo):