Merge "Add wrap option to nova credentials for humans"

This commit is contained in:
Jenkins 2013-03-11 16:43:19 +00:00 committed by Gerrit Code Review
commit 2f2f4fcf2b
3 changed files with 10 additions and 4 deletions

View File

@ -1,6 +1,7 @@
import os
import re
import sys
import textwrap
import uuid
import prettytable
@ -168,13 +169,15 @@ def print_list(objs, fields, formatters={}, sortby_index=0):
print(strutils.safe_encode(pt.get_string()))
def print_dict(d, dict_property="Property"):
def print_dict(d, dict_property="Property", wrap=0):
pt = prettytable.PrettyTable([dict_property, 'Value'], caching=False)
pt.align = 'l'
for k, v in d.iteritems():
# convert dict to str to check length
if isinstance(v, dict):
v = str(v)
if wrap > 0:
v = textwrap.fill(str(v), wrap)
# if value has a newline, add in multiple rows
# e.g. fault with stacktrace
if v and isinstance(v, basestring) and r'\n' in v:

View File

@ -2608,12 +2608,15 @@ def do_endpoints(cs, _args):
utils.print_dict(e['endpoints'][0], e['name'])
@utils.arg('--wrap', dest='wrap', metavar='<integer>', default=64,
help='wrap PKI tokens to a specified length, or 0 to disable')
def do_credentials(cs, _args):
"""Show user credentials returned from auth"""
ensure_service_catalog_present(cs)
catalog = cs.client.service_catalog.catalog
utils.print_dict(catalog['access']['user'], "User Credentials")
utils.print_dict(catalog['access']['token'], "Token")
utils.print_dict(catalog['access']['user'], "User Credentials",
wrap=int(_args.wrap))
utils.print_dict(catalog['access']['token'], "Token", wrap=int(_args.wrap))
@utils.arg('server', metavar='<server>', help='Name or ID of server.')

View File

@ -102,7 +102,7 @@ class ShellTest(utils.TestCase):
def test_bash_completion(self):
stdout, stderr = self.shell('bash-completion')
# just check we have some output
required = ['--matching help secgroup-delete-rule --priority']
required = ['--matching --wrap help secgroup-delete-rule --priority']
for r in required:
self.assertThat((stdout + stderr),
matchers.MatchesRegex(r, re.DOTALL | re.MULTILINE))