Skip to content

Commit

Permalink
add code
Browse files Browse the repository at this point in the history
  • Loading branch information
GuideGlyph committed Dec 23, 2024
1 parent 290bc26 commit 76a86a1
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 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 @@ -1978,7 +1982,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

0 comments on commit 76a86a1

Please sign in to comment.