Microversion 2.83 - Add more filters for the nova list command
Add these new filters, admin-only until microversion 2.82: - availability-zone - config-drive - key-name - power-state - task-state - vm-state - progress Existing user filter will be available to non admin since microversion 2.83. Part of blueprint non-admin-filter-instance-by-az Change-Id: Id2b5e600c0a41790830823031b20983808cb5ace
This commit is contained in:
parent
0722e80886
commit
9ee74d3ac6
@ -2223,7 +2223,11 @@ nova list
|
||||
[--tenant [<tenant>]] [--user [<user>]] [--deleted]
|
||||
[--fields <fields>] [--minimal]
|
||||
[--sort <key>[:<direction>]] [--marker <marker>]
|
||||
[--limit <limit>] [--changes-since <changes_since>]
|
||||
[--limit <limit>] [--availability-zone <availability_zone>]
|
||||
[--key-name <key_name>] [--config-drive <config_drive>]
|
||||
[--progress <progress>] [--vm-state <vm_state>]
|
||||
[--task-state <task_state>] [--power-state <power_state>]
|
||||
[--changes-since <changes_since>]
|
||||
[--changes-before <changes_before>]
|
||||
[--tags <tags>] [--tags-any <tags-any>]
|
||||
[--not-tags <not-tags>] [--not-tags-any <not-tags-any>]
|
||||
@ -2274,7 +2278,7 @@ present in the failure domain.
|
||||
|
||||
``--user [<user>]``
|
||||
Display information from single user (Admin
|
||||
only).
|
||||
only until microversion 2.82).
|
||||
|
||||
``--deleted``
|
||||
Only display deleted servers (Admin only).
|
||||
@ -2304,6 +2308,35 @@ present in the failure domain.
|
||||
Nova API, limit 'CONF.api.max_limit' will be
|
||||
used instead.
|
||||
|
||||
``--availability-zone <availability_zone>``
|
||||
Display servers based on their availability zone
|
||||
(Admin only until microversion 2.82).
|
||||
|
||||
``--key-name <key_name>``
|
||||
Display servers based on their keypair name
|
||||
(Admin only until microversion 2.82).
|
||||
|
||||
``--config-drive <config_drive>``
|
||||
Display servers based on their config_drive value
|
||||
The value must be a boolean. (Admin only until
|
||||
microversion 2.82).
|
||||
|
||||
``--progress <progress>``
|
||||
Display servers based on their progress value
|
||||
(Admin only until microversion 2.82).
|
||||
|
||||
``--vm-state <vm_state>``
|
||||
Display servers based on their vm_state value
|
||||
(Admin only until microversion 2.82).
|
||||
|
||||
``--task-state <task_state>``
|
||||
Display servers based on their task_state value
|
||||
(Admin only until microversion 2.82).
|
||||
|
||||
``--power-state <power_state>``
|
||||
Display servers based on their power_state value
|
||||
(Admin only until microversion 2.82).
|
||||
|
||||
``--changes-since <changes_since>``
|
||||
List only servers changed later or equal to a
|
||||
certain point of time. The provided time should
|
||||
|
@ -25,4 +25,4 @@ API_MIN_VERSION = api_versions.APIVersion("2.1")
|
||||
# when client supported the max version, and bumped sequentially, otherwise
|
||||
# the client may break due to server side new version may include some
|
||||
# backward incompatible change.
|
||||
API_MAX_VERSION = api_versions.APIVersion("2.82")
|
||||
API_MAX_VERSION = api_versions.APIVersion("2.83")
|
||||
|
@ -85,6 +85,13 @@ class ServersTest(utils.FixturedTestCase):
|
||||
self.assertIn("'locked' argument is only allowed since "
|
||||
"microversion 2.73.", str(e))
|
||||
|
||||
def test_filter_without_config_drive(self):
|
||||
sl = self.cs.servers.list(search_opts={'config_drive': None})
|
||||
self.assert_request_id(sl, fakes.FAKE_REQUEST_ID_LIST)
|
||||
self.assert_called('GET', '/servers/detail')
|
||||
for s in sl:
|
||||
self.assertIsInstance(s, servers.Server)
|
||||
|
||||
def test_list_servers_undetailed(self):
|
||||
sl = self.cs.servers.list(detailed=False)
|
||||
self.assert_request_id(sl, fakes.FAKE_REQUEST_ID_LIST)
|
||||
|
@ -1704,7 +1704,7 @@ class ShellTest(utils.TestCase):
|
||||
self.run_command('list --user fake_user')
|
||||
self.assert_called(
|
||||
'GET',
|
||||
'/servers/detail?all_tenants=1&user_id=fake_user')
|
||||
'/servers/detail?user_id=fake_user')
|
||||
|
||||
def test_list_with_single_sort_key_no_dir(self):
|
||||
self.run_command('list --sort 1')
|
||||
@ -1838,6 +1838,51 @@ class ShellTest(utils.TestCase):
|
||||
'list --changes-before 2016-02-29T06:23:22',
|
||||
api_version='2.65')
|
||||
|
||||
def test_list_with_availability_zone(self):
|
||||
self.run_command('list --availability-zone nova')
|
||||
self.assert_called('GET', '/servers/detail?availability_zone=nova')
|
||||
|
||||
def test_list_with_key_name(self):
|
||||
self.run_command('list --key-name my_key')
|
||||
self.assert_called('GET', '/servers/detail?key_name=my_key')
|
||||
|
||||
def test_list_with_config_drive_passing_through_any_value(self):
|
||||
self.run_command('list --config-drive True')
|
||||
self.assert_called('GET', '/servers/detail?config_drive=True')
|
||||
self.run_command('list --config-drive some-random-string')
|
||||
self.assert_called(
|
||||
'GET', '/servers/detail?config_drive=some-random-string')
|
||||
# This form is special for the test env to pass through an empty string
|
||||
# as a parameter. The real CLI call would look like
|
||||
# list --config drive ''
|
||||
self.run_command(['list', '--config-drive', ''])
|
||||
self.assert_called(
|
||||
'GET', '/servers/detail?config_drive=')
|
||||
|
||||
def test_list_with_progress(self):
|
||||
self.run_command('list --progress 100')
|
||||
self.assert_called('GET', '/servers/detail?progress=100')
|
||||
|
||||
def test_list_with_0_progress(self):
|
||||
self.run_command('list --progress 0')
|
||||
self.assert_called('GET', '/servers/detail?progress=0')
|
||||
|
||||
def test_list_with_vm_state(self):
|
||||
self.run_command('list --vm-state active')
|
||||
self.assert_called('GET', '/servers/detail?vm_state=active')
|
||||
|
||||
def test_list_with_task_state(self):
|
||||
self.run_command('list --task-state reboot_started')
|
||||
self.assert_called('GET', '/servers/detail?task_state=reboot_started')
|
||||
|
||||
def test_list_with_power_state(self):
|
||||
self.run_command('list --power-state 1')
|
||||
self.assert_called('GET', '/servers/detail?power_state=1')
|
||||
|
||||
def test_list_with_power_state_filter_for_0_state(self):
|
||||
self.run_command('list --power-state 0')
|
||||
self.assert_called('GET', '/servers/detail?power_state=0')
|
||||
|
||||
def test_list_fields_redundant(self):
|
||||
output, _err = self.run_command('list --fields id,status,status')
|
||||
header = output.splitlines()[1]
|
||||
@ -4458,7 +4503,8 @@ class ShellTest(utils.TestCase):
|
||||
75, # There are no version-wrapped shell method changes for this.
|
||||
76, # doesn't require any changes in novaclient.
|
||||
77, # There are no version-wrapped shell method changes for this.
|
||||
82, # doesn't require any changes in novaclient.
|
||||
82, # There are no version-wrapped shell method changes for this.
|
||||
83, # There are no version-wrapped shell method changes for this.
|
||||
])
|
||||
versions_supported = set(range(0,
|
||||
novaclient.API_MAX_VERSION.ver_minor + 1))
|
||||
|
@ -893,6 +893,12 @@ class ServerManager(base.BootingManagerWithFind):
|
||||
if isinstance(val, str):
|
||||
val = val.encode('utf-8')
|
||||
qparams[opt] = val
|
||||
# NOTE(gibi): After we fixing bug 1871409 and cleaning up the API
|
||||
# inconsistency around config_drive we can make the
|
||||
# config_drive filter a boolean filter. But until that we
|
||||
# simply pass through any value to the API even empty string.
|
||||
if opt == 'config_drive' and val is not None:
|
||||
qparams[opt] = val
|
||||
|
||||
detail = ""
|
||||
if detailed:
|
||||
|
@ -1486,7 +1486,8 @@ def _print_flavor(flavor):
|
||||
dest='user',
|
||||
metavar='<user>',
|
||||
nargs='?',
|
||||
help=_('Display information from single user (Admin only).'))
|
||||
help=_('Display information from single user (Admin only until '
|
||||
'microversion 2.82).'))
|
||||
@utils.arg(
|
||||
'--deleted',
|
||||
dest='deleted',
|
||||
@ -1529,6 +1530,61 @@ def _print_flavor(flavor):
|
||||
"will be displayed. If limit is bigger than 'CONF.api.max_limit' "
|
||||
"option of Nova API, limit 'CONF.api.max_limit' will be used "
|
||||
"instead."))
|
||||
@utils.arg(
|
||||
'--availability-zone',
|
||||
dest='availability_zone',
|
||||
metavar='<availability_zone>',
|
||||
default=None,
|
||||
help=_('Display servers based on their availability zone (Admin only '
|
||||
'until microversion 2.82).'))
|
||||
@utils.arg(
|
||||
'--key-name',
|
||||
dest='key_name',
|
||||
metavar='<key_name>',
|
||||
default=None,
|
||||
help=_('Display servers based on their keypair name (Admin only until '
|
||||
'microversion 2.82).'))
|
||||
# NOTE(gibi): we can make this a real boolean filter after bug 1871409 is fixed
|
||||
# and the REST API is cleaned up regarding the values of config_drive. Unit
|
||||
# that we simply pass through any string from the user to the REST API.
|
||||
@utils.arg(
|
||||
'--config-drive',
|
||||
dest='config_drive',
|
||||
metavar='<config_drive>',
|
||||
default=None,
|
||||
help=_('Display servers based on their config_drive value (Admin only '
|
||||
'until microversion 2.82). The value must be a boolean value.'))
|
||||
@utils.arg(
|
||||
'--progress',
|
||||
dest='progress',
|
||||
metavar='<progress>',
|
||||
default=None,
|
||||
help=_('Display servers based on their progress value (Admin only until '
|
||||
'microversion 2.82).'))
|
||||
@utils.arg(
|
||||
'--vm-state',
|
||||
dest='vm_state',
|
||||
metavar='<vm_state>',
|
||||
default=None,
|
||||
help=_('Display servers based on their vm_state value (Admin only until '
|
||||
'microversion 2.82).'))
|
||||
@utils.arg(
|
||||
'--task-state',
|
||||
dest='task_state',
|
||||
metavar='<task_state>',
|
||||
default=None,
|
||||
help=_('Display servers based on their task_state value (Admin only until '
|
||||
'microversion 2.82).'))
|
||||
# TODO(gibi): this is now only work with the integer power state values.
|
||||
# Later on we can extend this to accept the string values of the power state
|
||||
# and translate it to integers towards the REST API.
|
||||
@utils.arg(
|
||||
'--power-state',
|
||||
dest='power_state',
|
||||
metavar='<power_state>',
|
||||
default=None,
|
||||
help=_('Display servers based on their power_state value (Admin only '
|
||||
'until microversion 2.82).'))
|
||||
@utils.arg(
|
||||
'--changes-since',
|
||||
dest='changes_since',
|
||||
@ -1603,8 +1659,9 @@ def do_list(cs, args):
|
||||
if args.flavor:
|
||||
flavorid = _find_flavor(cs, args.flavor).id
|
||||
# search by tenant or user only works with all_tenants
|
||||
if args.tenant or args.user:
|
||||
if args.tenant:
|
||||
args.all_tenants = 1
|
||||
|
||||
search_opts = {
|
||||
'all_tenants': args.all_tenants,
|
||||
'reservation_id': args.reservation_id,
|
||||
@ -1618,7 +1675,15 @@ def do_list(cs, args):
|
||||
'user_id': args.user,
|
||||
'host': args.host,
|
||||
'deleted': args.deleted,
|
||||
'changes-since': args.changes_since}
|
||||
'changes-since': args.changes_since,
|
||||
'availability_zone': args.availability_zone,
|
||||
'config_drive': args.config_drive,
|
||||
'key_name': args.key_name,
|
||||
'progress': args.progress,
|
||||
'vm_state': args.vm_state,
|
||||
'task_state': args.task_state,
|
||||
'power_state': args.power_state,
|
||||
}
|
||||
|
||||
for arg in ('tags', "tags-any", 'not-tags', 'not-tags-any'):
|
||||
if arg in args:
|
||||
|
@ -0,0 +1,18 @@
|
||||
---
|
||||
features:
|
||||
- |
|
||||
Added the following filters support for the ``nova list`` command,
|
||||
these filters are admin-only restricted until microversion 2.82:
|
||||
|
||||
* --availability-zone
|
||||
* --config-drive
|
||||
* --key-name
|
||||
* --power-state
|
||||
* --task-state
|
||||
* --vm-state
|
||||
* --progress
|
||||
|
||||
Existing user filter will be available to non admin since
|
||||
`microversion 2.83`_.
|
||||
|
||||
.. _microversion 2.83: https://docs.openstack.org/nova/latest/reference/api-microversion-history.html#id76
|
Loading…
Reference in New Issue
Block a user