From 072c4bed1d47559827fb55be345f8317c885aa53 Mon Sep 17 00:00:00 2001 From: jctanner Date: Wed, 20 Jul 2016 09:46:50 -0400 Subject: [PATCH] vmware_inventory.py excude more properties and fix debug printing on unicode (#16769) * Fix broken indentation in vmware inventory * Allow script to be a symlink without breaking ini path. * Add some more properties to the bad_types list * Encode unicode strings to ascii Fixes #16763 --- contrib/inventory/vmware_inventory.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/contrib/inventory/vmware_inventory.py b/contrib/inventory/vmware_inventory.py index ae19d704027..2bac42b39a9 100755 --- a/contrib/inventory/vmware_inventory.py +++ b/contrib/inventory/vmware_inventory.py @@ -80,7 +80,7 @@ class VMWareInventory(object): host_filters = [] groupby_patterns = [] - bad_types = ['Array'] + bad_types = ['Array', 'disabledMethod', 'declaredAlarmState'] if (sys.version_info > (3, 0)): safe_types = [int, bool, str, float, None] else: @@ -112,6 +112,10 @@ class VMWareInventory(object): def debugl(self, text): if self.args.debug: + try: + text = str(text) + except UnicodeEncodeError: + text = text.encode('ascii','ignore') print(text) def show(self): @@ -313,18 +317,18 @@ class VMWareInventory(object): instances = [] if hasattr(child, 'childEntity'): - self.debugl("CHILDREN: %s" % str(child.childEntity)) + self.debugl("CHILDREN: %s" % child.childEntity) instances += self._get_instances_from_children(child.childEntity) elif hasattr(child, 'vmFolder'): - self.debugl("FOLDER: %s" % str(child)) + self.debugl("FOLDER: %s" % child) instances += self._get_instances_from_children(child.vmFolder) elif hasattr(child, 'index'): - self.debugl("LIST: %s" % str(child)) + self.debugl("LIST: %s" % child) for x in sorted(child): self.debugl("LIST_ITEM: %s" % x) instances += self._get_instances_from_children(x) elif hasattr(child, 'guest'): - self.debugl("GUEST: %s" % str(child)) + self.debugl("GUEST: %s" % child) instances.append(child) elif hasattr(child, 'vm'): # resource pools @@ -433,7 +437,7 @@ class VMWareInventory(object): newkey = t.render(v) newkey = newkey.strip() except Exception as e: - self.debugl(str(e)) + self.debugl(e) #import epdb; epdb.st() if not newkey: continue @@ -520,13 +524,13 @@ class VMWareInventory(object): rdata = {} - self.debugl("PROCESSING: %s" % str(vobj)) + self.debugl("PROCESSING: %s" % vobj) if type(vobj) in self.safe_types: try: rdata = vobj except Exception as e: - self.debugl(str(e)) + self.debugl(e) elif hasattr(vobj, 'append'): rdata = []