summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorRowin Andruscavage <8740187+MTN-RowinAndruscavage@users.noreply.github.com>2019-06-25 03:10:13 -0700
committerAbhijeet Kasurde <akasurde@redhat.com>2019-06-25 15:40:13 +0530
commit896b84bfbe7e2e1cf5dd3f9246ead98d85fbe356 (patch)
tree5226aebc382879174cb299b2a898e62741dce0be /contrib
parent06292566ec6bda36be05dd351c3635a744f21ad2 (diff)
downloadansible-896b84bfbe7e2e1cf5dd3f9246ead98d85fbe356.tar.gz
VMware: Python3 migrations for vmware_inventory.py (#47538)
* Sort and pretty print json output and cache file * Enable Python3 test for vmware_inventory.py Fixes: #46727 Signed-off-by: Rowin Andruscavage <8740187+MTN-RowinAndruscavage@users.noreply.github.com> Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
Diffstat (limited to 'contrib')
-rwxr-xr-xcontrib/inventory/vmware_inventory.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/contrib/inventory/vmware_inventory.py b/contrib/inventory/vmware_inventory.py
index 2f5e4a8d07..e6407bcbce 100755
--- a/contrib/inventory/vmware_inventory.py
+++ b/contrib/inventory/vmware_inventory.py
@@ -153,7 +153,7 @@ class VMWareInventory(object):
try:
text = str(text)
except UnicodeEncodeError:
- text = text.encode('ascii', 'ignore')
+ text = text.encode('utf-8')
print('%s %s' % (datetime.datetime.now(), text))
def show(self):
@@ -187,14 +187,14 @@ class VMWareInventory(object):
def write_to_cache(self, data):
''' Dump inventory to json file '''
- with open(self.cache_path_cache, 'wb') as f:
- f.write(json.dumps(data))
+ with open(self.cache_path_cache, 'w') as f:
+ f.write(json.dumps(data, indent=2))
def get_inventory_from_cache(self):
''' Read in jsonified inventory '''
jdata = None
- with open(self.cache_path_cache, 'rb') as f:
+ with open(self.cache_path_cache, 'r') as f:
jdata = f.read()
return json.loads(jdata)
@@ -391,7 +391,7 @@ class VMWareInventory(object):
instances = [x for x in instances if x.name == self.args.host]
instance_tuples = []
- for instance in sorted(instances):
+ for instance in instances:
if self.guest_props:
ifacts = self.facts_from_proplist(instance)
else:
@@ -693,7 +693,7 @@ class VMWareInventory(object):
if vobj.isalnum():
rdata = vobj
else:
- rdata = vobj.decode('ascii', 'ignore')
+ rdata = vobj.encode('utf-8').decode('utf-8')
elif issubclass(type(vobj), bool) or isinstance(vobj, bool):
rdata = vobj
elif issubclass(type(vobj), integer_types) or isinstance(vobj, integer_types):