Skip to content

Commit b663e8a

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "Add 'flavor list --min-disk', '--min-ram' options"
2 parents 23afc0a + da03bd8 commit b663e8a

3 files changed

Lines changed: 73 additions & 7 deletions

File tree

openstackclient/compute/v2/flavor.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,18 @@ def get_parser(self, prog_name):
263263
default=False,
264264
help=_("List all flavors, whether public or private")
265265
)
266+
parser.add_argument(
267+
'--min-disk',
268+
type=int,
269+
metavar='<min-disk>',
270+
help=_('Filters the flavors by a minimum disk space, in GiB.'),
271+
)
272+
parser.add_argument(
273+
'--min-ram',
274+
type=int,
275+
metavar='<min-ram>',
276+
help=_('Filters the flavors by a minimum RAM, in MiB.'),
277+
)
266278
parser.add_argument(
267279
'--long',
268280
action='store_true',
@@ -277,8 +289,13 @@ def get_parser(self, prog_name):
277289
parser.add_argument(
278290
'--limit',
279291
type=int,
280-
metavar="<num-flavors>",
281-
help=_("Maximum number of flavors to display")
292+
metavar='<num-flavors>',
293+
help=_(
294+
'Maximum number of flavors to display. This is also '
295+
'configurable on the server. The actual limit used will be '
296+
'the lower of the user-supplied value and the server '
297+
'configuration-derived value'
298+
),
282299
)
283300
return parser
284301

@@ -293,15 +310,24 @@ def take_action(self, parsed_args):
293310
query_attrs = {
294311
'is_public': is_public
295312
}
313+
296314
if parsed_args.marker:
297315
query_attrs['marker'] = parsed_args.marker
316+
298317
if parsed_args.limit:
299318
query_attrs['limit'] = parsed_args.limit
319+
300320
if parsed_args.limit or parsed_args.marker:
301321
# User passed explicit pagination request, switch off SDK
302322
# pagination
303323
query_attrs['paginated'] = False
304324

325+
if parsed_args.min_disk:
326+
query_attrs['min_disk'] = parsed_args.min_disk
327+
328+
if parsed_args.min_ram:
329+
query_attrs['min_ram'] = parsed_args.min_ram
330+
305331
data = list(compute_client.flavors(**query_attrs))
306332
# Even if server supports 2.61 some policy might stop it sending us
307333
# extra_specs. So try to fetch them if they are absent
@@ -341,10 +367,13 @@ def take_action(self, parsed_args):
341367
"Properties",
342368
)
343369

344-
return (column_headers,
345-
(utils.get_item_properties(
346-
s, columns, formatters=_formatters,
347-
) for s in data))
370+
return (
371+
column_headers,
372+
(
373+
utils.get_item_properties(s, columns, formatters=_formatters)
374+
for s in data
375+
),
376+
)
348377

349378

350379
class SetFlavor(command.Command):
@@ -378,13 +407,13 @@ def get_parser(self, prog_name):
378407
help=_('Set flavor access to project (name or ID) '
379408
'(admin only)'),
380409
)
410+
identity_common.add_project_domain_option_to_parser(parser)
381411
parser.add_argument(
382412
'--description',
383413
metavar='<description>',
384414
help=_("Set description for the flavor.(Supported by API "
385415
"versions '2.55' - '2.latest'")
386416
)
387-
identity_common.add_project_domain_option_to_parser(parser)
388417

389418
return parser
390419

openstackclient/tests/unit/compute/v2/test_flavor.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,6 +635,37 @@ def test_flavor_list_long(self):
635635
self.assertEqual(self.columns_long, columns)
636636
self.assertItemsEqual(self.data_long, tuple(data))
637637

638+
def test_flavor_list_min_disk_min_ram(self):
639+
arglist = [
640+
'--min-disk', '10',
641+
'--min-ram', '2048',
642+
]
643+
verifylist = [
644+
('min_disk', 10),
645+
('min_ram', 2048),
646+
]
647+
648+
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
649+
650+
# In base command class Lister in cliff, abstract method take_action()
651+
# returns a tuple containing the column names and an iterable
652+
# containing the data to be listed.
653+
columns, data = self.cmd.take_action(parsed_args)
654+
655+
# Set expected values
656+
kwargs = {
657+
'is_public': True,
658+
'min_disk': 10,
659+
'min_ram': 2048,
660+
}
661+
662+
self.sdk_client.flavors.assert_called_with(
663+
**kwargs
664+
)
665+
666+
self.assertEqual(self.columns, columns)
667+
self.assertEqual(tuple(self.data), tuple(data))
668+
638669

639670
class TestFlavorSet(TestFlavor):
640671

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- |
4+
The ``openstack flavor list`` command now accepts two additional
5+
options, ``--min-disk`` and ``--min-ram``, to filter flavor by
6+
minimum disk and minimum RAM, respectively.

0 commit comments

Comments
 (0)