diff --git a/plugins/modules/vmware_guest_network.py b/plugins/modules/vmware_guest_network.py index 799d19d3f..aa66caa55 100644 --- a/plugins/modules/vmware_guest_network.py +++ b/plugins/modules/vmware_guest_network.py @@ -75,6 +75,7 @@ network_name: description: - Name of network in vSphere. + - Work faster then o(vlan_id) for big infrastructure with many networks. type: str device_type: default: vmxnet3 @@ -319,6 +320,17 @@ def _get_network_object(self, vm_obj): for pg in vm_obj.runtime.host.config.network.portgroup: pg_lookup[pg.spec.name] = {'switch': pg.spec.vswitchName, 'vlan_id': pg.spec.vlanId} + if network_name: + networks = self.find_network_by_name(network_name) + for network in networks: + if network in compute_resource.network: + if isinstance(network, vim.dvs.DistributedVirtualPortgroup): + dvs = network.config.distributedVirtualSwitch + if (switch_name and dvs.config.name == switch_name) or not switch_name: + return network + elif isinstance(network, vim.Network): + return network + if compute_resource: for network in compute_resource.network: if isinstance(network, vim.dvs.DistributedVirtualPortgroup):