From ecc1404219c1c817007a3cec1553347e888273ee Mon Sep 17 00:00:00 2001 From: tengqm Date: Sun, 1 Feb 2015 22:33:20 +0800 Subject: [PATCH] Added short ID support for node-list --- senlinclient/v1/shell.py | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/senlinclient/v1/shell.py b/senlinclient/v1/shell.py index 2b18a678..363afa66 100644 --- a/senlinclient/v1/shell.py +++ b/senlinclient/v1/shell.py @@ -361,10 +361,18 @@ def do_cluster_show(sc, args): help=_('Limit the number of nodes returned.')) @utils.arg('-m', '--marker', metavar='', help=_('Only return nodes that appear after the given node ID.')) +@utils.arg('-F', '--full-id', default=False, action="store_true", + help=_('Print full IDs in list.')) @utils.arg('id', metavar='', help=_('Name or ID of cluster to nodes from.')) def do_cluster_node_list(sc, args): '''List nodes from cluster.''' + def _short_id(obj): + return obj.id[:8] + ' ...' + + def _short_physical_id(obj): + return obj.physical_id[:8] + ' ...' + fields = ['id', 'name', 'index', 'status', 'physical_id', 'created_time'] query = { @@ -381,7 +389,15 @@ def do_cluster_node_list(sc, args): msg = _('No node matching criteria is found') raise exc.CommandError(msg) - utils.print_list(nodes, fields, sortby_index=5) + if not args.full_id: + formatters = { + 'id': _short_id, + 'physical_id': _short_physical_id, + } + else: + formatters = {} + + utils.print_list(nodes, fields, formatters=formatters, sortby_index=5) @utils.arg('-n', '--nodes', metavar='', @@ -501,8 +517,18 @@ def do_cluster_policy_update(sc, args): help=_('Limit the number of nodes returned.')) @utils.arg('-m', '--marker', metavar='', help=_('Only return nodes that appear after the given node ID.')) +@utils.arg('-F', '--full-id', default=False, action="store_true", + help=_('Print full IDs in list.')) def do_node_list(sc, args): '''Show list of nodes.''' + def _short_id(obj): + return obj.id[:8] + ' ...' + + def _short_cluster_id(obj): + return obj.cluster_id[:8] + ' ...' if obj.cluster_id else '' + + def _short_physical_id(obj): + return obj.physical_id[:8] + ' ...' if obj.physical_id else '' fields = ['id', 'name', 'status', 'cluster_id', 'physical_id', 'profile_name', 'created_time', 'updated_time'] @@ -521,7 +547,17 @@ def do_node_list(sc, args): fields.append('deleted_time') nodes = sc.list(models.Node, **queries) - utils.print_list(nodes, fields, sortby_index=5) + + if not args.full_id: + formatters = { + 'id': _short_id, + 'cluster_id': _short_cluster_id, + 'physical_id': _short_physical_id, + } + else: + formatters = {} + + utils.print_list(nodes, fields, formatters=formatters, sortby_index=5) @utils.arg('-c', '--cluster', metavar='',