Skip to content

Commit

Permalink
fix serious quoting issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jeking3 committed Oct 10, 2018
1 parent ec0cdca commit 0e99451
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions actions/get_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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("'")

0 comments on commit 0e99451

Please sign in to comment.