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
pull/16773/head
jctanner 8 years ago committed by GitHub
parent b06c61c49b
commit 072c4bed1d

@ -80,7 +80,7 @@ class VMWareInventory(object):
host_filters = [] host_filters = []
groupby_patterns = [] groupby_patterns = []
bad_types = ['Array'] bad_types = ['Array', 'disabledMethod', 'declaredAlarmState']
if (sys.version_info > (3, 0)): if (sys.version_info > (3, 0)):
safe_types = [int, bool, str, float, None] safe_types = [int, bool, str, float, None]
else: else:
@ -112,6 +112,10 @@ class VMWareInventory(object):
def debugl(self, text): def debugl(self, text):
if self.args.debug: if self.args.debug:
try:
text = str(text)
except UnicodeEncodeError:
text = text.encode('ascii','ignore')
print(text) print(text)
def show(self): def show(self):
@ -313,18 +317,18 @@ class VMWareInventory(object):
instances = [] instances = []
if hasattr(child, 'childEntity'): 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) instances += self._get_instances_from_children(child.childEntity)
elif hasattr(child, 'vmFolder'): elif hasattr(child, 'vmFolder'):
self.debugl("FOLDER: %s" % str(child)) self.debugl("FOLDER: %s" % child)
instances += self._get_instances_from_children(child.vmFolder) instances += self._get_instances_from_children(child.vmFolder)
elif hasattr(child, 'index'): elif hasattr(child, 'index'):
self.debugl("LIST: %s" % str(child)) self.debugl("LIST: %s" % child)
for x in sorted(child): for x in sorted(child):
self.debugl("LIST_ITEM: %s" % x) self.debugl("LIST_ITEM: %s" % x)
instances += self._get_instances_from_children(x) instances += self._get_instances_from_children(x)
elif hasattr(child, 'guest'): elif hasattr(child, 'guest'):
self.debugl("GUEST: %s" % str(child)) self.debugl("GUEST: %s" % child)
instances.append(child) instances.append(child)
elif hasattr(child, 'vm'): elif hasattr(child, 'vm'):
# resource pools # resource pools
@ -433,7 +437,7 @@ class VMWareInventory(object):
newkey = t.render(v) newkey = t.render(v)
newkey = newkey.strip() newkey = newkey.strip()
except Exception as e: except Exception as e:
self.debugl(str(e)) self.debugl(e)
#import epdb; epdb.st() #import epdb; epdb.st()
if not newkey: if not newkey:
continue continue
@ -520,13 +524,13 @@ class VMWareInventory(object):
rdata = {} rdata = {}
self.debugl("PROCESSING: %s" % str(vobj)) self.debugl("PROCESSING: %s" % vobj)
if type(vobj) in self.safe_types: if type(vobj) in self.safe_types:
try: try:
rdata = vobj rdata = vobj
except Exception as e: except Exception as e:
self.debugl(str(e)) self.debugl(e)
elif hasattr(vobj, 'append'): elif hasattr(vobj, 'append'):
rdata = [] rdata = []

Loading…
Cancel
Save