summaryrefslogtreecommitdiff
path: root/openstackclient
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2021-10-13 10:18:53 +0100
committerStephen Finucane <sfinucan@redhat.com>2021-10-13 12:50:44 +0100
commitcbc64f9469600624e74631f42ca214487e800155 (patch)
treed645fd3ba81b2ce40141cdd836c9c0dfadfa5cb0 /openstackclient
parentec637205a5ca56f61f5cfef3ff248ad6acd1e204 (diff)
downloadpython-openstackclient-cbc64f9469600624e74631f42ca214487e800155.tar.gz
compute: Fix filtering servers by tags
The nova API expects the 'tags' and 'not-tags' filters of the 'GET /servers' (list servers) API to be a CSV string [1]: tags (Optional) A list of tags to filter the server list by. Servers that match all tags in this list will be returned. Boolean expression in this case is 't1 AND t2'. Tags in query must be separated by comma. New in version 2.26 not-tags (Optional) A list of tags to filter the server list by. Servers that don’t match all tags in this list will be returned. Boolean expression in this case is 'NOT (t1 AND t2)'. Tags in query must be separated by comma. New in version 2.26 We were instead providing a Python list, which was simply being URL encoded. Correct this. [1] https://docs.openstack.org/api-ref/compute/?expanded=list-servers-detail#list-servers Change-Id: Ie0251a0dccdf3385089e5bbaedf646a5e928cc48 Signed-off-by: Stephen Finucane <sfinucan@redhat.com> Closes-Bug: #1946816 (cherry picked from commit 53debe7fe1978f661768a27430f646a288948ecc)
Diffstat (limited to 'openstackclient')
-rw-r--r--openstackclient/compute/v2/server.py4
-rw-r--r--openstackclient/tests/unit/compute/v2/test_server.py4
2 files changed, 4 insertions, 4 deletions
diff --git a/openstackclient/compute/v2/server.py b/openstackclient/compute/v2/server.py
index a09fd44d..9180361d 100644
--- a/openstackclient/compute/v2/server.py
+++ b/openstackclient/compute/v2/server.py
@@ -2204,7 +2204,7 @@ class ListServer(command.Lister):
)
raise exceptions.CommandError(msg)
- search_opts['tags'] = parsed_args.tags
+ search_opts['tags'] = ','.join(parsed_args.tags)
if parsed_args.not_tags:
if compute_client.api_version < api_versions.APIVersion('2.26'):
@@ -2214,7 +2214,7 @@ class ListServer(command.Lister):
)
raise exceptions.CommandError(msg)
- search_opts['not-tags'] = parsed_args.not_tags
+ search_opts['not-tags'] = ','.join(parsed_args.not_tags)
if parsed_args.locked:
if compute_client.api_version < api_versions.APIVersion('2.73'):
diff --git a/openstackclient/tests/unit/compute/v2/test_server.py b/openstackclient/tests/unit/compute/v2/test_server.py
index 57840cb0..2f83fa2b 100644
--- a/openstackclient/tests/unit/compute/v2/test_server.py
+++ b/openstackclient/tests/unit/compute/v2/test_server.py
@@ -4269,7 +4269,7 @@ class TestServerList(TestServer):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
- self.search_opts['tags'] = ['tag1', 'tag2']
+ self.search_opts['tags'] = 'tag1,tag2'
self.servers_mock.list.assert_called_with(**self.kwargs)
@@ -4312,7 +4312,7 @@ class TestServerList(TestServer):
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
columns, data = self.cmd.take_action(parsed_args)
- self.search_opts['not-tags'] = ['tag1', 'tag2']
+ self.search_opts['not-tags'] = 'tag1,tag2'
self.servers_mock.list.assert_called_with(**self.kwargs)