From 6e9a5b59fe37347de58f7ac977acdf2e3deddec3 Mon Sep 17 00:00:00 2001 From: wanghao Date: Wed, 12 Feb 2020 10:08:01 +0800 Subject: [PATCH] Support query queues with count Zaqar will support query queues with '--with_count' to return the amount of the queues. This will help users to quickly get the exact total number of queues which they own. Change-Id: Iced54e7d270e389a23db2a19394025710565923d Implements: blueprint query-queues-with-count Signed-off-by: wanghao --- ...ry-queues-with-count-c9c47e508c04ad66.yaml | 5 ++ zaqarclient/queues/v2/cli.py | 46 ++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/support-query-queues-with-count-c9c47e508c04ad66.yaml diff --git a/releasenotes/notes/support-query-queues-with-count-c9c47e508c04ad66.yaml b/releasenotes/notes/support-query-queues-with-count-c9c47e508c04ad66.yaml new file mode 100644 index 00000000..526ace53 --- /dev/null +++ b/releasenotes/notes/support-query-queues-with-count-c9c47e508c04ad66.yaml @@ -0,0 +1,5 @@ +--- +features: + - Support query queues with filter 'with_count=true' to return the amount of + the queues. This will help users to quickly get the exact total number of + queues which they own. diff --git a/zaqarclient/queues/v2/cli.py b/zaqarclient/queues/v2/cli.py index 9daedba4..05c800f5 100644 --- a/zaqarclient/queues/v2/cli.py +++ b/zaqarclient/queues/v2/cli.py @@ -48,9 +48,51 @@ class OldDeleteQueue(cli.OldDeleteQueue): pass -class ListQueues(cli.ListQueues): +class ListQueues(command.Lister): """List available queues""" - pass + + _description = _("List available queues") + log = logging.getLogger(__name__ + ".ListQueues") + + def get_parser(self, prog_name): + parser = super(ListQueues, self).get_parser(prog_name) + parser.add_argument( + "--marker", + metavar="", + help="Queue's paging marker") + parser.add_argument( + "--limit", + metavar="", + help="Page size limit") + parser.add_argument( + "--detailed", + action="store_true", + help="If show detailed information of queue") + parser.add_argument( + "--with_count", + action="store_true", + help="If show amount information of queue") + + return parser + + def take_action(self, parsed_args): + client = _get_client(self, parsed_args) + kwargs = {} + columns = ["Name"] + if parsed_args.marker is not None: + kwargs["marker"] = parsed_args.marker + if parsed_args.limit is not None: + kwargs["limit"] = parsed_args.limit + if parsed_args.detailed is not None and parsed_args.detailed: + kwargs["detailed"] = parsed_args.detailed + columns.extend(["Metadata_Dict", "Href"]) + if parsed_args.with_count is not None and parsed_args.with_count: + kwargs["with_count"] = parsed_args.with_count + columns.extend(["Count"]) + + data = client.queues(**kwargs) + columns = tuple(columns) + return (columns, (utils.get_item_properties(s, columns) for s in data)) class OldListQueues(cli.OldListQueues):