summaryrefslogtreecommitdiff
path: root/cinderclient/utils.py
diff options
context:
space:
mode:
authorSheel Rana <ranasheel2000@gmail.com>2016-02-18 00:45:10 +0530
committerSheel Rana <ranasheel2000@gmail.com>2016-02-19 17:26:24 +0000
commita26c1e67b674e20ccbe57e20fd591d8c3b545696 (patch)
tree3b6a7bfffb161a4844aadf26c1204dc9cc695743 /cinderclient/utils.py
parentf88e4da1d6f507e7fe419a049ca46ba3af5df524 (diff)
downloadpython-cinderclient-a26c1e67b674e20ccbe57e20fd591d8c3b545696.tar.gz
Extra 'u' in output of cinder cli commands
In output of cinder show command, below fields contains extra 'u' character being unicode: 1. volume_image_metadata 2. metadata In output of "cinder credentials", below field contains extra 'u' 1. roles In output of "cinder qos-create", below field contains extra 'u' 1. specs In output of "cinder qos-list", below field contains extra 'u' 1. specs In output of "cinder extra-specs-list", below field contains extra 'u' 1. extra_specs In output of "cinder qos-show", below field contains extra 'u' 1. specs Change-Id: I8be32f117ddc29b087ee872ff065c175dd70b372 Closes-Bug: #1538413 Closes-Bug: #1538415
Diffstat (limited to 'cinderclient/utils.py')
-rw-r--r--cinderclient/utils.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/cinderclient/utils.py b/cinderclient/utils.py
index 24ea134..c501e7c 100644
--- a/cinderclient/utils.py
+++ b/cinderclient/utils.py
@@ -161,6 +161,13 @@ def print_list(objs, fields, exclude_unavailable=False, formatters=None,
pt = prettytable.PrettyTable((f for f in fields), caching=False)
pt.aligns = ['l' for f in fields]
for row in rows:
+ count = 0
+ # Converts unicode values in dictionary to string
+ for part in row:
+ count = count + 1
+ if isinstance(part, dict):
+ part = unicode_key_value_to_string(part)
+ row[count - 1] = part
pt.add_row(row)
if sortby_index is None:
@@ -170,11 +177,25 @@ def print_list(objs, fields, exclude_unavailable=False, formatters=None,
_print(pt, order_by)
-def print_dict(d, property="Property"):
+def unicode_key_value_to_string(dictionary):
+ """Recursively converts dictionary keys to strings."""
+ if not isinstance(dictionary, dict):
+ return dictionary
+ return dict((str(k), str(unicode_key_value_to_string(v)))
+ for k, v in dictionary.items())
+
+
+def print_dict(d, property="Property", formatters=None):
pt = prettytable.PrettyTable([property, 'Value'], caching=False)
pt.aligns = ['l', 'l']
+ formatters = formatters or {}
+
for r in six.iteritems(d):
r = list(r)
+
+ if r[0] in formatters:
+ r[1] = unicode_key_value_to_string(r[1])
+
if isinstance(r[1], six.string_types) and "\r" in r[1]:
r[1] = r[1].replace("\r", " ")
pt.add_row(r)