From 443b25d72aff7944cd2505c3430978e8048e6b8d Mon Sep 17 00:00:00 2001 From: jctanner Date: Fri, 25 Aug 2017 09:53:01 -0400 Subject: [PATCH] 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 --- contrib/inventory/vmware_inventory.py | 33 +++++++++++++++++---------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/contrib/inventory/vmware_inventory.py b/contrib/inventory/vmware_inventory.py index c0c799095c..b6ed76109e 100755 --- a/contrib/inventory/vmware_inventory.py +++ b/contrib/inventory/vmware_inventory.py @@ -578,18 +578,27 @@ class VMWareInventory(object): for idx, x in enumerate(parts): - # if the val wasn't set yet, get it from the parent - if not val: - try: - val = getattr(vm, x) - except AttributeError as e: - self.debugl(e) + if isinstance(val, dict): + if x in val: + val = val.get(x) + elif x.lower() in val: + val = val.get(x.lower()) else: - # in a subkey, get the subprop from the previous attrib - try: - val = getattr(val, x) - except AttributeError as e: - self.debugl(e) + # if the val wasn't set yet, get it from the parent + if not val: + try: + val = getattr(vm, x) + 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 if self.lowerkeys: @@ -653,7 +662,7 @@ class VMWareInventory(object): 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 ''' rdata = {}