Add CLI support for the template_parameters action
Change-Id: I26eb71a4707e3a34e644557389016ea0c35019ca
This commit is contained in:
parent
8e0764c37c
commit
2881226f33
@ -62,13 +62,14 @@ def print_list(objs, fields, formatters={}, custom_labels={}, sortby=0,
|
||||
|
||||
|
||||
def print_dict(d, formatters={}, custom_labels={}, outfile=sys.stdout):
|
||||
'''Prints a dict.
|
||||
'''Prints a dict to the provided file or file-like object.
|
||||
|
||||
:param d: dict to print
|
||||
:param formatters: dict of functions that perform pre-print
|
||||
formatting of dict values (keys are keys from `d` parameter,
|
||||
values are functions that take one parameter - the dict value
|
||||
to format)
|
||||
to format). A wild card formatter can be provided as '*' which
|
||||
will be applied to all fields without a dedicated formatter.
|
||||
:param custom_labels: dict of label overrides for keys (keys are
|
||||
keys from `d` parameter, values are custom labels)
|
||||
'''
|
||||
@ -76,10 +77,14 @@ def print_dict(d, formatters={}, custom_labels={}, outfile=sys.stdout):
|
||||
caching=False, print_empty=False)
|
||||
pt.align = 'l'
|
||||
|
||||
global_formatter = formatters.get('*')
|
||||
|
||||
for field in d.keys():
|
||||
label = custom_labels.get(field, field)
|
||||
if field in formatters:
|
||||
pt.add_row([label, formatters[field](d[field])])
|
||||
elif global_formatter:
|
||||
pt.add_row([label, global_formatter(d[field])])
|
||||
else:
|
||||
pt.add_row([label, d[field]])
|
||||
print(pt.get_string(sortby='Property'), file=outfile)
|
||||
@ -112,7 +117,7 @@ def attr_proxy(attr, formatter=lambda a: a, allow_undefined=True):
|
||||
def attributes_formatter(attributes):
|
||||
"""Given a simple dict format the keyvalue pairs with one on each line.
|
||||
"""
|
||||
return u"\n".join(u"{0}={1}".format(k, v) for k, v in
|
||||
return u"".join(u"{0}={1}\n".format(k, v) for k, v in
|
||||
sorted(attributes.items()))
|
||||
|
||||
|
||||
|
@ -84,7 +84,7 @@ class FormattersTest(tutils.TestCase):
|
||||
'a thing': 'a value'
|
||||
}
|
||||
self.assertEqual(
|
||||
("a thing=a value\nmysql_host=http://somewhere\npassword=pass"),
|
||||
("a thing=a value\nmysql_host=http://somewhere\npassword=pass\n"),
|
||||
fmt.attributes_formatter(attributes),
|
||||
)
|
||||
|
||||
|
@ -277,6 +277,29 @@ tests = [
|
||||
],
|
||||
'err_string': '',
|
||||
'return_code': 0,
|
||||
},
|
||||
# Overcloud - show template parameters
|
||||
{
|
||||
'commands': ['overcloud-show-template-parameters -h',
|
||||
'overcloud-show-template-parameters --help',
|
||||
'help overcloud-show-template-parameters'],
|
||||
'test_identifiers': [
|
||||
'test_overcloud_show_template_parameters_dash_h',
|
||||
'test_overcloud_show_template_parameters_dashdash_help',
|
||||
'test_help_overcloud_show_template_parameters'
|
||||
],
|
||||
'out_includes': [
|
||||
'Show the template parameters stored in the Tuskar API.'
|
||||
],
|
||||
'out_excludes': [
|
||||
'-n <NAME>, --name <NAME>'
|
||||
'overcloud-list',
|
||||
'overcloud-role-template-parameters',
|
||||
'--os-username OS_USERNAME',
|
||||
'Display help for <subcommand>',
|
||||
],
|
||||
'err_string': '',
|
||||
'return_code': 0,
|
||||
}
|
||||
]
|
||||
|
||||
|
@ -88,6 +88,16 @@ def do_overcloud_delete(tuskar, args, outfile=sys.stdout):
|
||||
print(u'Deleted Overcloud "%s".' % overcloud.name, file=outfile)
|
||||
|
||||
|
||||
def do_overcloud_show_template_parameters(tuskar, args, outfile=sys.stdout):
|
||||
"""Show the template parameters stored in the Tuskar API."""
|
||||
template_parameters = tuskar.overclouds.template_parameters()
|
||||
formatters = {
|
||||
'*': fmt.attributes_formatter
|
||||
}
|
||||
template_parameters_dict = template_parameters.to_dict()
|
||||
fmt.print_dict(template_parameters_dict, formatters, outfile=outfile)
|
||||
|
||||
|
||||
def create_overcloud_dict(args):
|
||||
"""Marshal command line arguments to an API request dict."""
|
||||
overcloud_dict = {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user