Skip to content

Commit

Permalink
VMware: confine search for network till datacenter level (ansible#40382)
Browse files Browse the repository at this point in the history
If there are multiple distributed virtual portgroup network with same name
in different datacenter, vmware_guest module used to choose first DVPG irrespective
of the datacenter. This caused problem if two datacenter has same name for DVPG,
vmware_guest module failed with error "The object or item referred to could not be found."

This fix adds check to search for network (Distributed Virtual Portgroup)
till datacenter level. This avoids selection of same name DVPG from other datacenter.

Signed-off-by: Abhijeet Kasurde <[email protected]>
  • Loading branch information
Akasurde authored Aug 7, 2018
1 parent 3dcbf3b commit 5936e1f
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/ansible/modules/cloud/vmware/vmware_guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1118,7 +1118,7 @@ def sanitize_network_params(self):
self.module.fail_json(msg="Please specify at least a network name or"
" a VLAN name under VM network list.")

if 'name' in network and find_obj(self.content, [vim.Network], network['name']) is None:
if 'name' in network and self.cache.get_network(network['name']) is None:
self.module.fail_json(msg="Network '%(name)s' does not exist." % network)
elif 'vlan' in network:
dvps = self.cache.get_all_objs(self.content, [vim.dvs.DistributedVirtualPortgroup])
Expand Down Expand Up @@ -1241,6 +1241,7 @@ def configure_network(self, vm_obj):

if hasattr(self.cache.get_network(network_name), 'portKeys'):
# VDS switch

pg_obj = None
if 'dvswitch_name' in network_devices[key]:
dvs_name = network_devices[key]['dvswitch_name']
Expand All @@ -1251,7 +1252,7 @@ def configure_network(self, vm_obj):
if pg_obj is None:
self.module.fail_json(msg="Unable to find distributed port group %s" % network_name)
else:
pg_obj = find_obj(self.content, [vim.dvs.DistributedVirtualPortgroup], network_name)
pg_obj = self.cache.find_obj(self.content, [vim.dvs.DistributedVirtualPortgroup], network_name)

if (nic.device.backing and
(not hasattr(nic.device.backing, 'port') or
Expand Down

0 comments on commit 5936e1f

Please sign in to comment.