Fixup the property collection for dictionaries vs. objects (#28609)

* Fixup the property collection for dictionaries vs. objects

* Remove debug lines

* Do not attempt to sort because it's a waste

* Remove unused code

* Remove extra code

* Capture lowercase keys
This commit is contained in:
jctanner 2017-08-25 09:53:01 -04:00 committed by GitHub
parent 11c9756d9c
commit 443b25d72a

View file

@ -578,18 +578,27 @@ class VMWareInventory(object):
for idx, x in enumerate(parts): for idx, x in enumerate(parts):
# if the val wasn't set yet, get it from the parent if isinstance(val, dict):
if not val: if x in val:
try: val = val.get(x)
val = getattr(vm, x) elif x.lower() in val:
except AttributeError as e: val = val.get(x.lower())
self.debugl(e)
else: else:
# in a subkey, get the subprop from the previous attrib # if the val wasn't set yet, get it from the parent
try: if not val:
val = getattr(val, x) try:
except AttributeError as e: val = getattr(vm, x)
self.debugl(e) except AttributeError as e:
self.debugl(e)
else:
# in a subkey, get the subprop from the previous attrib
try:
val = getattr(val, x)
except AttributeError as e:
self.debugl(e)
# make sure it serializes
val = self._process_object_types(val)
# lowercase keys if requested # lowercase keys if requested
if self.lowerkeys: if self.lowerkeys:
@ -653,7 +662,7 @@ class VMWareInventory(object):
return rdata return rdata
def _process_object_types(self, vobj, thisvm=None, inkey=None, level=0): def _process_object_types(self, vobj, thisvm=None, inkey='', level=0):
''' Serialize an object ''' ''' Serialize an object '''
rdata = {} rdata = {}