Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vmware_guest speedup module #2278

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions plugins/modules/vmware_guest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@
from ansible_collections.community.vmware.plugins.module_utils.vmware_spbm import SPBM


class PyVmomiCache(object):
class PyVmomiCache(PyVmomi):
""" This class caches references to objects which are requested multiples times but not modified """

def __init__(self, content, dc_name=None):
Expand Down Expand Up @@ -1166,13 +1166,17 @@ def get_all_objs(self, content, types, confine_to_datacenter=True):

return objects

def get_network(self, network):
network = quote_obj_name(network)
def get_network(self, network_name):
network_name = quote_obj_name(network_name)

if network not in self.networks:
self.networks[network] = self.find_obj(self.content, [vim.Network], network)
if network_name not in self.networks:
networks = self.find_network_by_name(network_name)
if len(networks) == 1:
self.networks[network_name] = networks[0]
else:
self.networks[network_name] = self.find_obj(self.content, [vim.Network], network_name)

return self.networks[network]
return self.networks[network_name]

def get_cluster(self, cluster):
if cluster not in self.clusters:
Expand Down Expand Up @@ -1940,7 +1944,11 @@ def configure_network(self, vm_obj):
nic.device.deviceInfo.summary = network_name
nic_change_detected = True
else:
pg = find_obj(self.content, [vim.DistributedVirtualPortgroup], network_name)
pgs = self.find_network_by_name(network_name)
if len(pgs) == 1:
pg = pgs[0]
else:
pg = find_obj(self.content, [vim.DistributedVirtualPortgroup], network_name)
if pg is None or nic.device.backing.port.portgroupKey != pg.key:
nic.device.deviceInfo.summary = network_name
nic_change_detected = True
Expand Down Expand Up @@ -1978,7 +1986,11 @@ 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 = self.cache.find_obj(self.content, [vim.dvs.DistributedVirtualPortgroup], network_name)
networks = self.find_network_by_name(network_name)
if len(networks) == 1:
pg_obj = networks[0]
else:
pg_obj = self.cache.find_obj(self.content, [vim.dvs.DistributedVirtualPortgroup], network_name)

# TODO: (akasurde) There is no way to find association between resource pool and distributed virtual portgroup
# For now, check if we are able to find distributed virtual switch
Expand Down
Loading