vmware_datastore_facts: don't nodify dict in iter (#54869) (#54870)

With Python3, we cannot iterate on a dict and modify it at the same time.

Fixes ##54869
This commit is contained in:
Gonéri Le Bouder 2019-04-16 23:09:55 -04:00 committed by ansibot
parent bd0792397b
commit 339a0f4a8c

View file

@ -214,10 +214,12 @@ class PyVmomiCache(object):
if confine_to_datacenter: if confine_to_datacenter:
if hasattr(objects, 'items'): if hasattr(objects, 'items'):
# resource pools come back as a dictionary # resource pools come back as a dictionary
tmpobjs = objects.copy()
for k, v in objects.items(): for k, v in objects.items():
parent_dc = get_parent_datacenter(k) parent_dc = get_parent_datacenter(k)
if parent_dc.name != self.dc_name: if parent_dc.name != self.dc_name:
objects.pop(k, None) tmpobjs.pop(k, None)
objects = tmpobjs
else: else:
# everything else should be a list # everything else should be a list
objects = [x for x in objects if get_parent_datacenter(x).name == self.dc_name] objects = [x for x in objects if get_parent_datacenter(x).name == self.dc_name]