summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Coutellier <victor.coutellier@gmail.com>2020-03-11 12:50:13 +0100
committerBalazs Gibizer <balazs.gibizer@est.tech>2020-04-07 18:34:13 +0200
commit9ee74d3ac6d26018d0161e24fe8c0f3f29b21c06 (patch)
treeea789aa65e2466303f54c50961f291a6feddc408
parent0722e80886285f7e5630d5d4012c42806ebc53c2 (diff)
downloadpython-novaclient-9ee74d3ac6d26018d0161e24fe8c0f3f29b21c06.tar.gz
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
-rw-r--r--doc/source/cli/nova.rst37
-rw-r--r--novaclient/__init__.py2
-rw-r--r--novaclient/tests/unit/v2/test_servers.py7
-rw-r--r--novaclient/tests/unit/v2/test_shell.py50
-rw-r--r--novaclient/v2/servers.py6
-rw-r--r--novaclient/v2/shell.py71
-rw-r--r--releasenotes/notes/add-filter-to-nova-list-831dcbb34420fb29.yaml18
7 files changed, 183 insertions, 8 deletions
diff --git a/doc/source/cli/nova.rst b/doc/source/cli/nova.rst
index 84c441bd..48b1dbda 100644
--- a/doc/source/cli/nova.rst
+++ b/doc/source/cli/nova.rst
@@ -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
diff --git a/novaclient/__init__.py b/novaclient/__init__.py
index 773a4b70..f86d680f 100644
--- a/novaclient/__init__.py
+++ b/novaclient/__init__.py
@@ -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")
diff --git a/novaclient/tests/unit/v2/test_servers.py b/novaclient/tests/unit/v2/test_servers.py
index d65ec145..0d3ca4b2 100644
--- a/novaclient/tests/unit/v2/test_servers.py
+++ b/novaclient/tests/unit/v2/test_servers.py
@@ -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)
diff --git a/novaclient/tests/unit/v2/test_shell.py b/novaclient/tests/unit/v2/test_shell.py
index dcd48707..c8d3dc9b 100644
--- a/novaclient/tests/unit/v2/test_shell.py
+++ b/novaclient/tests/unit/v2/test_shell.py
@@ -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))
diff --git a/novaclient/v2/servers.py b/novaclient/v2/servers.py
index ff8c166e..42184345 100644
--- a/novaclient/v2/servers.py
+++ b/novaclient/v2/servers.py
@@ -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:
diff --git a/novaclient/v2/shell.py b/novaclient/v2/shell.py
index e86add10..8dafc164 100644
--- a/novaclient/v2/shell.py
+++ b/novaclient/v2/shell.py
@@ -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',
@@ -1530,6 +1531,61 @@ def _print_flavor(flavor):
"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',
metavar='<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:
diff --git a/releasenotes/notes/add-filter-to-nova-list-831dcbb34420fb29.yaml b/releasenotes/notes/add-filter-to-nova-list-831dcbb34420fb29.yaml
new file mode 100644
index 00000000..e91a6080
--- /dev/null
+++ b/releasenotes/notes/add-filter-to-nova-list-831dcbb34420fb29.yaml
@@ -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