Add 'resource_filters' API to support generalized filtering
This patch adds ``resource_filters`` API to retrieve
configured resource filters.
APIImpact
Partial: blueprint generalized-filtering-for-cinder-list-resource
Depends-On: ff3d41b15a
Change-Id: I387268b277c46c72624a3d3b5eabf03724a7a847
This commit is contained in:
parent
aa2ff12947
commit
8fcb809509
@ -41,6 +41,7 @@ Block Storage API V3 (CURRENT)
|
||||
.. include:: hosts.inc
|
||||
.. include:: limits.inc
|
||||
.. include:: messages.inc
|
||||
.. include:: resource-filters.inc
|
||||
.. include:: qos-specs-v3-qos-specs.inc
|
||||
.. quota-sets should arguably live closer to limits, but that would mess up
|
||||
our nice alphabetical ordering
|
||||
|
@ -113,6 +113,12 @@ qos_id:
|
||||
in: path
|
||||
required: false
|
||||
type: string
|
||||
resource:
|
||||
description: |
|
||||
Filter filters by resource name.
|
||||
in: path
|
||||
required: false
|
||||
type: string
|
||||
snapshot_id_1:
|
||||
description: |
|
||||
The UUID of the snapshot.
|
||||
@ -1586,6 +1592,18 @@ reset_status:
|
||||
in: body
|
||||
required: true
|
||||
type: object
|
||||
resource_1:
|
||||
description: |
|
||||
Resource which the filters will be applied to.
|
||||
in: body
|
||||
required: true
|
||||
type: string
|
||||
resource_filters:
|
||||
description: |
|
||||
The resource filter array.
|
||||
in: body
|
||||
required: true
|
||||
type: array
|
||||
resource_type:
|
||||
description: |
|
||||
The resource type corresponding to ``resource_uuid``.
|
||||
|
41
api-ref/source/v3/resource-filters.inc
Normal file
41
api-ref/source/v3/resource-filters.inc
Normal file
@ -0,0 +1,41 @@
|
||||
.. -*- rst -*-
|
||||
|
||||
Resource Filters
|
||||
================
|
||||
|
||||
Lists all resource filters, available since
|
||||
microversion 3.33.
|
||||
|
||||
|
||||
List resource filters
|
||||
~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. rest_method:: GET /v3/{project_id}/resource_filters
|
||||
|
||||
List filters.
|
||||
|
||||
Normal response codes: 200
|
||||
Error response codes:
|
||||
|
||||
|
||||
Request
|
||||
-------
|
||||
|
||||
.. rest_parameters:: parameters.yaml
|
||||
|
||||
- project_id: project_id_path
|
||||
- resource: resource
|
||||
|
||||
Response Parameters
|
||||
-------------------
|
||||
|
||||
.. rest_parameters:: parameters.yaml
|
||||
|
||||
- filters: resource_filters
|
||||
- resource: resource_1
|
||||
|
||||
Response Example
|
||||
----------------
|
||||
|
||||
.. literalinclude:: ./samples/resource-filters-list-response.json
|
||||
:language: javascript
|
@ -0,0 +1,21 @@
|
||||
{
|
||||
"resource_filters": [
|
||||
{
|
||||
"filters": [
|
||||
"name",
|
||||
"status",
|
||||
"image_metadata", "bootable",
|
||||
"migration_status"
|
||||
],
|
||||
"resource": "volume"
|
||||
},
|
||||
{
|
||||
"filters": [
|
||||
"name",
|
||||
"status",
|
||||
"volume_id"
|
||||
],
|
||||
"resource": "snapshot"
|
||||
}
|
||||
]
|
||||
}
|
@ -83,6 +83,9 @@ REST_API_VERSION_HISTORY = """
|
||||
* 3.30 - Support sort snapshots with "name".
|
||||
* 3.31 - Add support for configure resource query filters.
|
||||
* 3.32 - Add set-log and get-log service actions.
|
||||
* 3.33 - Add ``resource_filters`` API to retrieve configured
|
||||
resource filters.
|
||||
|
||||
"""
|
||||
|
||||
# The minimum and maximum versions of the API supported
|
||||
@ -90,7 +93,7 @@ REST_API_VERSION_HISTORY = """
|
||||
# minimum version of the API supported.
|
||||
# Explicitly using /v1 or /v2 endpoints will still work
|
||||
_MIN_API_VERSION = "3.0"
|
||||
_MAX_API_VERSION = "3.32"
|
||||
_MAX_API_VERSION = "3.33"
|
||||
_LEGACY_API_VERSION1 = "1.0"
|
||||
_LEGACY_API_VERSION2 = "2.0"
|
||||
|
||||
|
@ -304,3 +304,7 @@ user documentation.
|
||||
3.32
|
||||
----
|
||||
Added ``set-log`` and ``get-log`` service actions.
|
||||
|
||||
3.33
|
||||
----
|
||||
Add ``resource_filters`` API to retrieve configured resource filters.
|
||||
|
43
cinder/api/v3/resource_filters.py
Normal file
43
cinder/api/v3/resource_filters.py
Normal file
@ -0,0 +1,43 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""The resource filters api."""
|
||||
|
||||
from cinder.api import common
|
||||
from cinder.api.openstack import wsgi
|
||||
from cinder.api.v3.views import resource_filters as filter_views
|
||||
|
||||
|
||||
FILTER_API_VERSION = '3.33'
|
||||
|
||||
|
||||
class ResourceFiltersController(wsgi.Controller):
|
||||
"""The resource filter API controller for the OpenStack API."""
|
||||
|
||||
_view_builder_class = filter_views.ViewBuilder
|
||||
|
||||
def __init__(self, ext_mgr=None):
|
||||
"""Initialize controller class."""
|
||||
self.ext_mgr = ext_mgr
|
||||
super(ResourceFiltersController, self).__init__()
|
||||
|
||||
@wsgi.Controller.api_version(FILTER_API_VERSION)
|
||||
def index(self, req):
|
||||
"""Return a list of resource filters."""
|
||||
resource = req.params.get('resource', None)
|
||||
filters = common.get_enabled_resource_filters(resource=resource)
|
||||
return filter_views.ViewBuilder.list(filters)
|
||||
|
||||
|
||||
def create_resource(ext_mgr):
|
||||
"""Create the wsgi resource for this controller."""
|
||||
return wsgi.Resource(ResourceFiltersController(ext_mgr))
|
@ -33,6 +33,7 @@ from cinder.api.v3 import group_specs
|
||||
from cinder.api.v3 import group_types
|
||||
from cinder.api.v3 import groups
|
||||
from cinder.api.v3 import messages
|
||||
from cinder.api.v3 import resource_filters
|
||||
from cinder.api.v3 import snapshot_manage
|
||||
from cinder.api.v3 import snapshots
|
||||
from cinder.api.v3 import volume_manage
|
||||
@ -186,3 +187,8 @@ class APIRouter(cinder.api.openstack.APIRouter):
|
||||
mapper.resource('worker', 'workers',
|
||||
controller=self.resources['workers'],
|
||||
collection={'cleanup': 'POST'})
|
||||
|
||||
self.resources['resource_filters'] = resource_filters.create_resource(
|
||||
ext_mgr)
|
||||
mapper.resource('resource_filter', 'resource_filters',
|
||||
controller=self.resources['resource_filters'])
|
||||
|
35
cinder/api/v3/views/resource_filters.py
Normal file
35
cinder/api/v3/views/resource_filters.py
Normal file
@ -0,0 +1,35 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
|
||||
class ViewBuilder(object):
|
||||
"""Model an resource filters API response as a python dictionary."""
|
||||
|
||||
_collection_name = "resource_filters"
|
||||
|
||||
@classmethod
|
||||
def list(cls, filters):
|
||||
"""Build a view of a list of resource filters.
|
||||
|
||||
.. code-block:: json
|
||||
|
||||
{
|
||||
"resource_filters": [{
|
||||
"resource": 'resource_1',
|
||||
"filters": ['filter1', 'filter2', 'filter3']
|
||||
}]
|
||||
}
|
||||
"""
|
||||
|
||||
return {'resource_filters': [{
|
||||
'resource': fil[0],
|
||||
'filters': fil[1]} for fil in filters.items()]}
|
61
cinder/tests/unit/api/v3/test_resource_filters.py
Normal file
61
cinder/tests/unit/api/v3/test_resource_filters.py
Normal file
@ -0,0 +1,61 @@
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
"""
|
||||
Tests for resource filters API.
|
||||
"""
|
||||
|
||||
import ddt
|
||||
|
||||
from cinder.api import common
|
||||
from cinder.api.v3 import resource_filters as v3_filters
|
||||
from cinder import test
|
||||
from cinder.tests.unit.api import fakes
|
||||
from cinder.tests.unit import fake_constants as fake
|
||||
|
||||
FILTERS_MICRO_VERSION = '3.33'
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
class ResourceFiltersAPITestCase(test.TestCase):
|
||||
"""Test Case for filter API."""
|
||||
|
||||
def setUp(self):
|
||||
super(ResourceFiltersAPITestCase, self).setUp()
|
||||
self.controller = v3_filters.ResourceFiltersController()
|
||||
|
||||
@ddt.data({'filters': {'volume': ['key1']},
|
||||
'resource': 'volume',
|
||||
'expected_filters': [{'resource': 'volume',
|
||||
'filters': ['key1']}]},
|
||||
{'filters': {'volume': ['key1'], 'snapshot': ['key2']},
|
||||
'resource': None,
|
||||
'expected_filters': [{'resource': 'volume',
|
||||
'filters': ['key1']},
|
||||
{'resource': 'snapshot',
|
||||
'filters': ['key2']}]},
|
||||
{'filters': {'volume': ['key1', 'key2']},
|
||||
'resource': 'snapshot',
|
||||
'expected_filters': []})
|
||||
@ddt.unpack
|
||||
def test_get_allowed_filters(self, filters, resource, expected_filters):
|
||||
common._FILTERS_COLLECTION = filters
|
||||
request_url = '/v3/%s/resource_filters' % fake.PROJECT_ID
|
||||
if resource is not None:
|
||||
request_url += '?resource=%s' % resource
|
||||
req = fakes.HTTPRequest.blank(request_url,
|
||||
version=FILTERS_MICRO_VERSION)
|
||||
|
||||
result = self.controller.index(req)
|
||||
|
||||
expected = {'resource_filters': expected_filters}
|
||||
self.assertEqual(expected, result)
|
@ -0,0 +1,3 @@
|
||||
---
|
||||
features:
|
||||
- Added ``resource_filters`` API to retrieve configured resource filters.
|
Loading…
Reference in New Issue
Block a user