mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
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
This commit is contained in:
parent
b06c61c49b
commit
072c4bed1d
1 changed files with 12 additions and 8 deletions
|
@ -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 = []
|
||||
|
|
Loading…
Reference in a new issue