From e2b0644f8d51f9969dce49f26df618ed7e3f72db Mon Sep 17 00:00:00 2001 From: tengqm Date: Mon, 6 Jul 2015 10:29:22 -0400 Subject: [PATCH] Fix some cluster-list option bugs This patch renames the --show-deleted option to -d and the --sort-dir to -s. The reason is to keep the option names consistent across different object types. It also fixes the supports to sort_keys and sort_dir. Change-Id: I2e10e341eccfdbc440ab1b2da8c005a485cdc08d --- senlinclient/v1/shell.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/senlinclient/v1/shell.py b/senlinclient/v1/shell.py index ec5a70a..6d23bf0 100644 --- a/senlinclient/v1/shell.py +++ b/senlinclient/v1/shell.py @@ -543,24 +543,40 @@ def do_cluster_list(sc, args=None): def _short_id(obj): return obj.id[:8] - fields = ['id', 'name', 'status', 'created_time'] + fields = ['id', 'name', 'status', 'created_time', 'updated_time'] + sort_keys = ['name', 'status', 'created_time', 'updated_time'] queries = { 'limit': args.limit, 'marker': args.marker, 'filters': utils.format_parameters(args.filters), + 'sort_keys': args.sort_keys, + 'sort_dir': args.sort_dir, 'show_deleted': args.show_deleted, 'show_nested': args.show_nested } if args.show_nested: fields.append('parent') + # we only validate the sort keys + # - if all keys are valid, we won't enforce sorting in the resulting list + # - if any keys are invalid, we abort the command execution; + # - if no sort key is specified, we use created_time column for sorting + if args.sort_keys: + for key in args.sort_keys.split(';'): + if len(key) > 0 and key not in sort_keys: + raise exc.CommandError(_('Invalid sorting key: %s') % key) + sortby_index = None + else: + sortby_index = 3 + clusters = sc.list(models.Cluster, **queries) formatters = {} if not args.full_id: formatters = { 'id': _short_id, } - utils.print_list(clusters, fields, formatters=formatters, sortby_index=3) + utils.print_list(clusters, fields, formatters=formatters, + sortby_index=sortby_index) def _show_cluster(sc, cluster_id):