From 7b6d9bc7f8bd57799a8b44698ec860ebb02599d6 Mon Sep 17 00:00:00 2001 From: Leonid Plisov Date: Mon, 23 Dec 2024 15:27:32 +0300 Subject: [PATCH] add code --- plugins/modules/vmware_guest_network.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/plugins/modules/vmware_guest_network.py b/plugins/modules/vmware_guest_network.py index 799d19d3f3..d319ccb244 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,14 @@ 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: + dvs = network.config.distributedVirtualSwitch + if (switch_name and dvs.config.name == switch_name) or not switch_name: + return network + if compute_resource: for network in compute_resource.network: if isinstance(network, vim.dvs.DistributedVirtualPortgroup):