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
This commit is contained in:
tengqm 2015-07-06 10:29:22 -04:00
parent 043775a4e7
commit e2b0644f8d

@ -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):