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
This commit is contained in:
@@ -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 = prettytable.PrettyTable((f for f in fields), caching=False)
|
||||||
pt.aligns = ['l' for f in fields]
|
pt.aligns = ['l' for f in fields]
|
||||||
for row in rows:
|
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)
|
pt.add_row(row)
|
||||||
|
|
||||||
if sortby_index is None:
|
if sortby_index is None:
|
||||||
@@ -170,11 +177,25 @@ def print_list(objs, fields, exclude_unavailable=False, formatters=None,
|
|||||||
_print(pt, order_by)
|
_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 = prettytable.PrettyTable([property, 'Value'], caching=False)
|
||||||
pt.aligns = ['l', 'l']
|
pt.aligns = ['l', 'l']
|
||||||
|
formatters = formatters or {}
|
||||||
|
|
||||||
for r in six.iteritems(d):
|
for r in six.iteritems(d):
|
||||||
r = list(r)
|
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]:
|
if isinstance(r[1], six.string_types) and "\r" in r[1]:
|
||||||
r[1] = r[1].replace("\r", " ")
|
r[1] = r[1].replace("\r", " ")
|
||||||
pt.add_row(r)
|
pt.add_row(r)
|
||||||
|
@@ -293,7 +293,8 @@ def do_show(cs, args):
|
|||||||
info.update(volume._info)
|
info.update(volume._info)
|
||||||
|
|
||||||
info.pop('links', None)
|
info.pop('links', None)
|
||||||
utils.print_dict(info)
|
utils.print_dict(info,
|
||||||
|
formatters=['metadata', 'volume_image_metadata'])
|
||||||
|
|
||||||
|
|
||||||
class CheckSizeArgForCreate(argparse.Action):
|
class CheckSizeArgForCreate(argparse.Action):
|
||||||
@@ -1001,9 +1002,12 @@ def do_endpoints(cs, args):
|
|||||||
def do_credentials(cs, args):
|
def do_credentials(cs, args):
|
||||||
"""Shows user credentials returned from auth."""
|
"""Shows user credentials returned from auth."""
|
||||||
catalog = cs.client.service_catalog.catalog
|
catalog = cs.client.service_catalog.catalog
|
||||||
utils.print_dict(catalog['user'], "User Credentials")
|
|
||||||
utils.print_dict(catalog['token'], "Token")
|
|
||||||
|
|
||||||
|
# formatters defines field to be converted from unicode to string
|
||||||
|
utils.print_dict(catalog['user'], "User Credentials",
|
||||||
|
formatters=['domain', 'roles'])
|
||||||
|
utils.print_dict(catalog['token'], "Token",
|
||||||
|
formatters=['audit_ids', 'tenant'])
|
||||||
|
|
||||||
_quota_resources = ['volumes', 'snapshots', 'gigabytes',
|
_quota_resources = ['volumes', 'snapshots', 'gigabytes',
|
||||||
'backups', 'backup_gigabytes',
|
'backups', 'backup_gigabytes',
|
||||||
@@ -1925,7 +1929,9 @@ def do_encryption_type_delete(cs, args):
|
|||||||
|
|
||||||
|
|
||||||
def _print_qos_specs(qos_specs):
|
def _print_qos_specs(qos_specs):
|
||||||
utils.print_dict(qos_specs._info)
|
|
||||||
|
# formatters defines field to be converted from unicode to string
|
||||||
|
utils.print_dict(qos_specs._info, formatters=['specs'])
|
||||||
|
|
||||||
|
|
||||||
def _print_qos_specs_list(q_specs):
|
def _print_qos_specs_list(q_specs):
|
||||||
|
Reference in New Issue
Block a user