image: Add "id" filter for images

The Glance v2 API supports a range of operators [1] for the list-images
API, allowing us to do things like:

  GET /v2/images?status=in:saving,queued

While there's no good reason to filter images by a single ID, it would
be helpful to be able to filter images by *multiple* IDs. Make this
possible by adding "id" to the list of possible filters.

[1] https://docs.openstack.org/api-ref/image/v2/index.html?expanded=list-images-detail#list-images

Change-Id: I735188e20d4e6c3b326e9080e878e717564b057d
Signed-off-by: Stephen Finucane <stephenfin@redhat.com>
This commit is contained in:
Stephen Finucane 2022-04-12 19:11:43 +01:00
parent 975cabbdd8
commit 6b2f555ade
3 changed files with 48 additions and 26 deletions

View File

@ -34,13 +34,24 @@ class Image(resource.Resource, tag.TagMixin, _download.DownloadMixin):
_store_unknown_attrs_as_properties = True
_query_mapping = resource.QueryParameters(
"name", "visibility",
"member_status", "owner",
"status", "size_min", "size_max",
"protected", "is_hidden",
"sort_key", "sort_dir", "sort", "tag",
"created_at", "updated_at",
is_hidden="os_hidden")
"id",
"name",
"visibility",
"member_status",
"owner",
"status",
"size_min",
"size_max",
"protected",
"is_hidden",
"sort_key",
"sort_dir",
"sort",
"tag",
"created_at",
"updated_at",
is_hidden="os_hidden",
)
# NOTE: Do not add "self" support here. If you've used Python before,
# you know that self, while not being a reserved word, has special

View File

@ -140,25 +140,29 @@ class TestImage(base.TestCase):
self.assertTrue(sot.allow_delete)
self.assertTrue(sot.allow_list)
self.assertDictEqual({'created_at': 'created_at',
'is_hidden': 'os_hidden',
'limit': 'limit',
'marker': 'marker',
'member_status': 'member_status',
'name': 'name',
'owner': 'owner',
'protected': 'protected',
'size_max': 'size_max',
'size_min': 'size_min',
'sort': 'sort',
'sort_dir': 'sort_dir',
'sort_key': 'sort_key',
'status': 'status',
'tag': 'tag',
'updated_at': 'updated_at',
'visibility': 'visibility'
},
sot._query_mapping._mapping)
self.assertDictEqual(
{
'created_at': 'created_at',
'id': 'id',
'is_hidden': 'os_hidden',
'limit': 'limit',
'marker': 'marker',
'member_status': 'member_status',
'name': 'name',
'owner': 'owner',
'protected': 'protected',
'size_max': 'size_max',
'size_min': 'size_min',
'sort': 'sort',
'sort_dir': 'sort_dir',
'sort_key': 'sort_key',
'status': 'status',
'tag': 'tag',
'updated_at': 'updated_at',
'visibility': 'visibility'
},
sot._query_mapping._mapping,
)
def test_make_it(self):
sot = image.Image(**EXAMPLE)

View File

@ -0,0 +1,7 @@
---
features:
- |
It is now possible to filter ``openstack.image.v2.Image`` resources by ID
using the ``id`` filter. While this is of little value when used with
single IDs, it can be useful when combined with operators like ``in:``
to e.g. filter by multiple image IDs.