vmware: avoid unnecessary copy() call (#60476)
Two vmware modules uses copy() to duplicate an internal instance of a pyvmomi object. This to be able to modify the object during an iteration. See: https://github.com/ansible/ansible/pull/60196/files#r312643761 Closes: #60399
This commit is contained in:
parent
fa783c027b
commit
df2a09e998
2 changed files with 4 additions and 8 deletions
|
@ -217,12 +217,10 @@ class PyVmomiCache(object):
|
|||
if confine_to_datacenter:
|
||||
if hasattr(objects, 'items'):
|
||||
# resource pools come back as a dictionary
|
||||
tmpobjs = objects.copy()
|
||||
for k, v in objects.items():
|
||||
for k, v in tuple(objects.items()):
|
||||
parent_dc = get_parent_datacenter(k)
|
||||
if parent_dc.name != self.dc_name:
|
||||
tmpobjs.pop(k, None)
|
||||
objects = tmpobjs
|
||||
del objects[k]
|
||||
else:
|
||||
# everything else should be a list
|
||||
objects = [x for x in objects if get_parent_datacenter(x).name == self.dc_name]
|
||||
|
|
|
@ -785,12 +785,10 @@ class PyVmomiCache(object):
|
|||
if hasattr(objects, 'items'):
|
||||
# resource pools come back as a dictionary
|
||||
# make a copy
|
||||
tmpobjs = objects.copy()
|
||||
for k, v in objects.items():
|
||||
for k, v in tuple(objects.items()):
|
||||
parent_dc = self.get_parent_datacenter(k)
|
||||
if parent_dc.name != self.dc_name:
|
||||
tmpobjs.pop(k, None)
|
||||
objects = tmpobjs
|
||||
del objects[k]
|
||||
else:
|
||||
# everything else should be a list
|
||||
objects = [x for x in objects if self.get_parent_datacenter(x).name == self.dc_name]
|
||||
|
|
Loading…
Reference in a new issue