Merge "Add support for Resource Filters"
This commit is contained in:
commit
4ac86afb45
openstack
block_storage/v3
tests
functional/block_storage/v3
unit/block_storage/v3
@ -15,6 +15,7 @@ from openstack.block_storage.v3 import availability_zone
|
||||
from openstack.block_storage.v3 import backup as _backup
|
||||
from openstack.block_storage.v3 import capabilities as _capabilities
|
||||
from openstack.block_storage.v3 import limits as _limits
|
||||
from openstack.block_storage.v3 import resource_filter as _resource_filter
|
||||
from openstack.block_storage.v3 import snapshot as _snapshot
|
||||
from openstack.block_storage.v3 import stats as _stats
|
||||
from openstack.block_storage.v3 import type as _type
|
||||
@ -589,6 +590,13 @@ class Proxy(_base_proxy.BaseBlockStorageProxy):
|
||||
"""
|
||||
return resource.wait_for_delete(self, res, interval, wait)
|
||||
|
||||
def resource_filters(self, **query):
|
||||
"""Retrieve a generator of resource filters
|
||||
|
||||
:returns: A generator of resource filters.
|
||||
"""
|
||||
return self._list(_resource_filter.ResourceFilter, **query)
|
||||
|
||||
def _get_cleanup_dependencies(self):
|
||||
return {
|
||||
'block_storage': {
|
||||
|
33
openstack/block_storage/v3/resource_filter.py
Normal file
33
openstack/block_storage/v3/resource_filter.py
Normal file
@ -0,0 +1,33 @@
|
||||
# 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.
|
||||
|
||||
from openstack import resource
|
||||
|
||||
|
||||
class ResourceFilter(resource.Resource):
|
||||
"""Resource Filter"""
|
||||
resources_key = "resource_filters"
|
||||
base_path = "/resource_filters"
|
||||
|
||||
_query_mapping = resource.QueryParameters('resource')
|
||||
|
||||
# Capabilities
|
||||
allow_list = True
|
||||
|
||||
# resource_filters introduced in 3.33
|
||||
_max_microversion = '3.33'
|
||||
|
||||
#: Properties
|
||||
#: The list of filters that are applicable to the specified resource.
|
||||
filters = resource.Body('filters', type=list)
|
||||
#: The resource that the filters will be applied to.
|
||||
resource = resource.Body('resource', type=str)
|
@ -0,0 +1,24 @@
|
||||
# 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.
|
||||
|
||||
|
||||
from openstack.tests.functional.block_storage.v3 import base
|
||||
|
||||
|
||||
class ResourceFilters(base.BaseBlockStorageTest):
|
||||
|
||||
def test_get(self):
|
||||
resource_filters = list(self.conn.block_storage.resource_filters())
|
||||
|
||||
for rf in resource_filters:
|
||||
self.assertIsInstance(rf.filters, list)
|
||||
self.assertIsInstance(rf.resource, str)
|
@ -15,6 +15,7 @@ from openstack.block_storage.v3 import _proxy
|
||||
from openstack.block_storage.v3 import backup
|
||||
from openstack.block_storage.v3 import capabilities
|
||||
from openstack.block_storage.v3 import limits
|
||||
from openstack.block_storage.v3 import resource_filter
|
||||
from openstack.block_storage.v3 import snapshot
|
||||
from openstack.block_storage.v3 import stats
|
||||
from openstack.block_storage.v3 import type
|
||||
@ -240,3 +241,7 @@ class TestVolumeProxy(test_proxy_base.TestProxyBase):
|
||||
|
||||
def test_capabilites_get(self):
|
||||
self.verify_get(self.proxy.get_capabilities, capabilities.Capabilities)
|
||||
|
||||
def test_resource_filters(self):
|
||||
self.verify_list(self.proxy.resource_filters,
|
||||
resource_filter.ResourceFilter)
|
||||
|
@ -0,0 +1,52 @@
|
||||
# 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.
|
||||
|
||||
from openstack.block_storage.v3 import resource_filter
|
||||
from openstack.tests.unit import base
|
||||
|
||||
RESOURCE_FILTER = {
|
||||
'filters': [
|
||||
'name',
|
||||
'status',
|
||||
'image_metadata',
|
||||
'bootable',
|
||||
'migration_status'
|
||||
],
|
||||
'resource': 'volume'
|
||||
}
|
||||
|
||||
|
||||
class TestResourceFilter(base.TestCase):
|
||||
|
||||
def test_basic(self):
|
||||
resource = resource_filter.ResourceFilter()
|
||||
self.assertEqual('resource_filters',
|
||||
resource.resources_key)
|
||||
self.assertEqual('/resource_filters',
|
||||
resource.base_path)
|
||||
self.assertFalse(resource.allow_create)
|
||||
self.assertFalse(resource.allow_fetch)
|
||||
self.assertFalse(resource.allow_commit)
|
||||
self.assertFalse(resource.allow_delete)
|
||||
self.assertTrue(resource.allow_list)
|
||||
|
||||
self.assertDictEqual({"resource": "resource",
|
||||
"limit": "limit",
|
||||
"marker": "marker"},
|
||||
resource._query_mapping._mapping)
|
||||
|
||||
def test_make_resource_filter(self):
|
||||
resource = resource_filter.ResourceFilter(
|
||||
**RESOURCE_FILTER)
|
||||
self.assertEqual(
|
||||
RESOURCE_FILTER['filters'], resource.filters)
|
||||
self.assertEqual(
|
||||
RESOURCE_FILTER['resource'], resource.resource)
|
Loading…
x
Reference in New Issue
Block a user