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 <sfinucan@redhat.com>
This commit is contained in:
parent
0edd055f3f
commit
da03bd80e3
@ -263,6 +263,18 @@ class ListFlavor(command.Lister):
|
|||||||
default=False,
|
default=False,
|
||||||
help=_("List all flavors, whether public or private")
|
help=_("List all flavors, whether public or private")
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--min-disk',
|
||||||
|
type=int,
|
||||||
|
metavar='<min-disk>',
|
||||||
|
help=_('Filters the flavors by a minimum disk space, in GiB.'),
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'--min-ram',
|
||||||
|
type=int,
|
||||||
|
metavar='<min-ram>',
|
||||||
|
help=_('Filters the flavors by a minimum RAM, in MiB.'),
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--long',
|
'--long',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
@ -277,8 +289,13 @@ class ListFlavor(command.Lister):
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--limit',
|
'--limit',
|
||||||
type=int,
|
type=int,
|
||||||
metavar="<num-flavors>",
|
metavar='<num-flavors>',
|
||||||
help=_("Maximum number of flavors to display")
|
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
|
return parser
|
||||||
|
|
||||||
@ -293,15 +310,24 @@ class ListFlavor(command.Lister):
|
|||||||
query_attrs = {
|
query_attrs = {
|
||||||
'is_public': is_public
|
'is_public': is_public
|
||||||
}
|
}
|
||||||
|
|
||||||
if parsed_args.marker:
|
if parsed_args.marker:
|
||||||
query_attrs['marker'] = parsed_args.marker
|
query_attrs['marker'] = parsed_args.marker
|
||||||
|
|
||||||
if parsed_args.limit:
|
if parsed_args.limit:
|
||||||
query_attrs['limit'] = parsed_args.limit
|
query_attrs['limit'] = parsed_args.limit
|
||||||
|
|
||||||
if parsed_args.limit or parsed_args.marker:
|
if parsed_args.limit or parsed_args.marker:
|
||||||
# User passed explicit pagination request, switch off SDK
|
# User passed explicit pagination request, switch off SDK
|
||||||
# pagination
|
# pagination
|
||||||
query_attrs['paginated'] = False
|
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))
|
data = list(compute_client.flavors(**query_attrs))
|
||||||
# Even if server supports 2.61 some policy might stop it sending us
|
# Even if server supports 2.61 some policy might stop it sending us
|
||||||
# extra_specs. So try to fetch them if they are absent
|
# extra_specs. So try to fetch them if they are absent
|
||||||
@ -341,10 +367,13 @@ class ListFlavor(command.Lister):
|
|||||||
"Properties",
|
"Properties",
|
||||||
)
|
)
|
||||||
|
|
||||||
return (column_headers,
|
return (
|
||||||
(utils.get_item_properties(
|
column_headers,
|
||||||
s, columns, formatters=_formatters,
|
(
|
||||||
) for s in data))
|
utils.get_item_properties(s, columns, formatters=_formatters)
|
||||||
|
for s in data
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class SetFlavor(command.Command):
|
class SetFlavor(command.Command):
|
||||||
@ -378,13 +407,13 @@ class SetFlavor(command.Command):
|
|||||||
help=_('Set flavor access to project (name or ID) '
|
help=_('Set flavor access to project (name or ID) '
|
||||||
'(admin only)'),
|
'(admin only)'),
|
||||||
)
|
)
|
||||||
|
identity_common.add_project_domain_option_to_parser(parser)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--description',
|
'--description',
|
||||||
metavar='<description>',
|
metavar='<description>',
|
||||||
help=_("Set description for the flavor.(Supported by API "
|
help=_("Set description for the flavor.(Supported by API "
|
||||||
"versions '2.55' - '2.latest'")
|
"versions '2.55' - '2.latest'")
|
||||||
)
|
)
|
||||||
identity_common.add_project_domain_option_to_parser(parser)
|
|
||||||
|
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
@ -635,6 +635,37 @@ class TestFlavorList(TestFlavor):
|
|||||||
self.assertEqual(self.columns_long, columns)
|
self.assertEqual(self.columns_long, columns)
|
||||||
self.assertListItemEqual(self.data_long, tuple(data))
|
self.assertListItemEqual(self.data_long, tuple(data))
|
||||||
|
|
||||||
|
def test_flavor_list_min_disk_min_ram(self):
|
||||||
|
arglist = [
|
||||||
|
'--min-disk', '10',
|
||||||
|
'--min-ram', '2048',
|
||||||
|
]
|
||||||
|
verifylist = [
|
||||||
|
('min_disk', 10),
|
||||||
|
('min_ram', 2048),
|
||||||
|
]
|
||||||
|
|
||||||
|
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||||
|
|
||||||
|
# In base command class Lister in cliff, abstract method take_action()
|
||||||
|
# returns a tuple containing the column names and an iterable
|
||||||
|
# containing the data to be listed.
|
||||||
|
columns, data = self.cmd.take_action(parsed_args)
|
||||||
|
|
||||||
|
# Set expected values
|
||||||
|
kwargs = {
|
||||||
|
'is_public': True,
|
||||||
|
'min_disk': 10,
|
||||||
|
'min_ram': 2048,
|
||||||
|
}
|
||||||
|
|
||||||
|
self.sdk_client.flavors.assert_called_with(
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(self.columns, columns)
|
||||||
|
self.assertEqual(tuple(self.data), tuple(data))
|
||||||
|
|
||||||
|
|
||||||
class TestFlavorSet(TestFlavor):
|
class TestFlavorSet(TestFlavor):
|
||||||
|
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
features:
|
||||||
|
- |
|
||||||
|
The ``openstack flavor list`` command now accepts two additional
|
||||||
|
options, ``--min-disk`` and ``--min-ram``, to filter flavor by
|
||||||
|
minimum disk and minimum RAM, respectively.
|
Loading…
Reference in New Issue
Block a user