Expose container filters via API
Right now, in DB layer, we support to filter containers with certain attributes. In particular, we support filter containers by attributes such as name, image, project_id, status, etc. [1]. It is better to expose this filter via REST API level. For example: GET /v1/containers?project_id=<my_project_id> This should return a list of containers in particular project. [1] https://github.com/openstack/zun/blob/master/zun/db/sqlalchemy/api.py#L132 Change-Id: I599a9f48a966d564da718b97bdad7cfac6ae4dfe Closes-Bug: #1750208
This commit is contained in:
parent
4ef02ca76c
commit
00916cfdff
@ -124,7 +124,14 @@ class ContainersController(base.Controller):
|
||||
resource_url = kwargs.get('resource_url')
|
||||
expand = kwargs.get('expand')
|
||||
|
||||
filters = None
|
||||
container_allowed_filters = ['name', 'image', 'project_id', 'user_id',
|
||||
'memory', 'host', 'task_state', 'status',
|
||||
'auto_remove']
|
||||
filters = {}
|
||||
for filter_key in container_allowed_filters:
|
||||
if filter_key in kwargs:
|
||||
filter_value = kwargs[filter_key]
|
||||
filters[filter_key] = filter_value
|
||||
marker_obj = None
|
||||
marker = kwargs.get('marker')
|
||||
if marker:
|
||||
|
@ -802,7 +802,7 @@ class TestContainerController(api_base.FunctionalTest):
|
||||
|
||||
mock_container_list.assert_called_once_with(mock.ANY,
|
||||
1000, None, 'id', 'asc',
|
||||
filters=None)
|
||||
filters={})
|
||||
context = mock_container_list.call_args[0][0]
|
||||
self.assertIs(False, context.all_projects)
|
||||
self.assertEqual(200, response.status_int)
|
||||
@ -826,7 +826,7 @@ class TestContainerController(api_base.FunctionalTest):
|
||||
|
||||
mock_container_list.assert_called_once_with(mock.ANY,
|
||||
1000, None, 'id', 'asc',
|
||||
filters=None)
|
||||
filters={})
|
||||
context = mock_container_list.call_args[0][0]
|
||||
self.assertIs(True, context.all_projects)
|
||||
self.assertEqual(200, response.status_int)
|
||||
@ -884,7 +884,7 @@ class TestContainerController(api_base.FunctionalTest):
|
||||
response = self.get('/v1/containers/')
|
||||
mock_container_list.assert_called_once_with(mock.ANY,
|
||||
1000, None, 'id', 'asc',
|
||||
filters=None)
|
||||
filters={})
|
||||
self.assertEqual(200, response.status_int)
|
||||
actual_containers = response.json['containers']
|
||||
self.assertEqual(1, len(actual_containers))
|
||||
|
Loading…
x
Reference in New Issue
Block a user