From da03bd80e3b83faf465f1446c4553c5d97b5bad5 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Wed, 14 Oct 2020 10:48:44 +0100 Subject: Add 'flavor list --min-disk', '--min-ram' options Allow us to filter on minimum disk and RAM, and close another gap with novaclient. Change-Id: Ib3f0bdf419675e1c35c3406fbac8a4c18ac56a33 Signed-off-by: Stephen Finucane --- openstackclient/compute/v2/flavor.py | 43 ++++++++++++++++++++++++++++++------ 1 file changed, 36 insertions(+), 7 deletions(-) (limited to 'openstackclient/compute') diff --git a/openstackclient/compute/v2/flavor.py b/openstackclient/compute/v2/flavor.py index 8477e8ef..fa98e131 100644 --- a/openstackclient/compute/v2/flavor.py +++ b/openstackclient/compute/v2/flavor.py @@ -263,6 +263,18 @@ class ListFlavor(command.Lister): default=False, help=_("List all flavors, whether public or private") ) + parser.add_argument( + '--min-disk', + type=int, + metavar='', + help=_('Filters the flavors by a minimum disk space, in GiB.'), + ) + parser.add_argument( + '--min-ram', + type=int, + metavar='', + help=_('Filters the flavors by a minimum RAM, in MiB.'), + ) parser.add_argument( '--long', action='store_true', @@ -277,8 +289,13 @@ class ListFlavor(command.Lister): parser.add_argument( '--limit', type=int, - metavar="", - help=_("Maximum number of flavors to display") + metavar='', + help=_( + 'Maximum number of flavors to display. This is also ' + 'configurable on the server. The actual limit used will be ' + 'the lower of the user-supplied value and the server ' + 'configuration-derived value' + ), ) return parser @@ -293,15 +310,24 @@ class ListFlavor(command.Lister): query_attrs = { 'is_public': is_public } + if parsed_args.marker: query_attrs['marker'] = parsed_args.marker + if parsed_args.limit: query_attrs['limit'] = parsed_args.limit + if parsed_args.limit or parsed_args.marker: # User passed explicit pagination request, switch off SDK # pagination query_attrs['paginated'] = False + if parsed_args.min_disk: + query_attrs['min_disk'] = parsed_args.min_disk + + if parsed_args.min_ram: + query_attrs['min_ram'] = parsed_args.min_ram + data = list(compute_client.flavors(**query_attrs)) # Even if server supports 2.61 some policy might stop it sending us # extra_specs. So try to fetch them if they are absent @@ -341,10 +367,13 @@ class ListFlavor(command.Lister): "Properties", ) - return (column_headers, - (utils.get_item_properties( - s, columns, formatters=_formatters, - ) for s in data)) + return ( + column_headers, + ( + utils.get_item_properties(s, columns, formatters=_formatters) + for s in data + ), + ) class SetFlavor(command.Command): @@ -378,13 +407,13 @@ class SetFlavor(command.Command): help=_('Set flavor access to project (name or ID) ' '(admin only)'), ) + identity_common.add_project_domain_option_to_parser(parser) parser.add_argument( '--description', metavar='', help=_("Set description for the flavor.(Supported by API " "versions '2.55' - '2.latest'") ) - identity_common.add_project_domain_option_to_parser(parser) return parser -- cgit v1.2.1