vmware_datastore_facts: don't modify dict in iter

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

Fixes #54869

(cherry picked from commit 339a0f4a8c)
This commit is contained in:
Gonéri Le Bouder 2019-04-16 23:09:55 -04:00 committed by Toshio Kuratomi
parent d112106985
commit 51a849c89f
2 changed files with 5 additions and 1 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- With Python3, we cannot iterate on a dict and modify it at the same time (https://github.com/ansible/ansible/issues/54869).

View file

@ -214,10 +214,12 @@ 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():
parent_dc = get_parent_datacenter(k)
if parent_dc.name != self.dc_name:
objects.pop(k, None)
tmpobjs.pop(k, None)
objects = tmpobjs
else:
# everything else should be a list
objects = [x for x in objects if get_parent_datacenter(x).name == self.dc_name]