From 0e9945161139e1b7d88025fcdb7864beba37c1b1 Mon Sep 17 00:00:00 2001 From: "James E. King III" Date: Wed, 10 Oct 2018 20:04:47 +0000 Subject: [PATCH] fix serious quoting issue --- actions/get_properties.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/actions/get_properties.py b/actions/get_properties.py index 5a8df4a..feb9289 100644 --- a/actions/get_properties.py +++ b/actions/get_properties.py @@ -103,17 +103,12 @@ def __init__(self, *args, **kwargs): super(PyVmomiObjectJSONEncoder, self).__init__(*args, **kwargs) def default(self, obj): # pylint: disable=method-hidden - # ISO8601 if isinstance(obj, datetime.datetime): return pyVmomi.Iso8601.ISO8601Format(obj) - # DataObject elif isinstance(obj, pyVmomi.VmomiSupport.DataObject): return obj.__dict__ - # ManagedObject elif isinstance(obj, pyVmomi.VmomiSupport.ManagedObject): - # The ManagedObject's reference name. - return repr(obj)[1:-1].split(':')[-1] # strip outer quotes - # Python Type + return unquote(obj).split(':')[-1] elif isinstance(obj, type): return str(obj) return json.JSONEncoder.default(self, obj) @@ -122,9 +117,14 @@ def default(self, obj): # pylint: disable=method-hidden def transform(self, ids, rawdata): result = {} for obj in rawdata: - objid = repr(obj.obj)[1:-1].split(':')[-1] + objid = unquote(obj.obj).split(':')[-1] ps = {} for prop in obj.propSet: - ps[repr(prop.name)[1:-1]] = self.jsonify_vsphere_obj(prop.val) + ps[unquote(prop.name)] = self.jsonify_vsphere_obj(prop.val) result[objid] = ps return (not ids or sorted(result.keys()) == sorted(ids), result) + + +def unquote(item): + return str(item).strip("'") +