]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Allow specified backend capabilities to be retrieved
authorMitsuhiro Tanino <mitsuhiro.tanino@hds.com>
Mon, 10 Aug 2015 20:44:25 +0000 (16:44 -0400)
committerMitsuhiro Tanino <mitsuhiro.tanino@hds.com>
Tue, 1 Sep 2015 04:56:41 +0000 (04:56 +0000)
This change adds a new admin-api extension to allow admin to
fetch specified backend capabilities.
With this extension, admin can obtain what the current deployed
backend in Cinder is able to do from the endpoint.

The extension takes "host" as an parameter.
GET http://CINDER_API_ENDPOINT/v2/TENANT_ID/capabilities/<host>

DocImpact
Implements: blueprint get-volume-type-extra-specs
Change-Id: Ie8c3a3e554983f2e0819d52cf6d2db5efe7a0983

cinder/api/contrib/capabilities.py [new file with mode: 0644]
cinder/api/views/capabilities.py [new file with mode: 0644]
cinder/tests/unit/api/contrib/test_capabilities.py [new file with mode: 0644]
cinder/tests/unit/policy.json
etc/cinder/policy.json

diff --git a/cinder/api/contrib/capabilities.py b/cinder/api/contrib/capabilities.py
new file mode 100644 (file)
index 0000000..177d73a
--- /dev/null
@@ -0,0 +1,63 @@
+# Copyright (c) 2015 Hitachi Data Systems, Inc.
+# All Rights Reserved.
+#
+#    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 oslo_log import log as logging
+
+from cinder.api import extensions
+from cinder.api.openstack import wsgi
+from cinder.api.views import capabilities as capabilities_view
+from cinder.volume import rpcapi
+
+
+LOG = logging.getLogger(__name__)
+
+
+def authorize(context, action_name):
+    extensions.extension_authorizer('volume', action_name)(context)
+
+
+class CapabilitiesController(wsgi.Controller):
+    """The Capabilities controller for the OpenStack API."""
+
+    _view_builder_class = capabilities_view.ViewBuilder
+
+    def __init__(self):
+        self.volume_api = rpcapi.VolumeAPI()
+        super(CapabilitiesController, self).__init__()
+
+    def show(self, req, id):
+        """Return capabilities list of given backend."""
+        context = req.environ['cinder.context']
+        authorize(context, 'capabilities')
+        capabilities = self.volume_api.get_capabilities(context, id, False)
+        return self._view_builder.summary(req, capabilities, id)
+
+
+class Capabilities(extensions.ExtensionDescriptor):
+    """Capabilities support."""
+
+    name = "Capabilities"
+    alias = "capabilities"
+    namespace = "http://docs.openstack.org/volume/ext/capabilities/api/v2"
+    updated = "2015-08-31T00:00:00+00:00"
+
+    def get_resources(self):
+        resources = []
+        res = extensions.ResourceExtension(
+            Capabilities.alias,
+            CapabilitiesController())
+
+        resources.append(res)
+        return resources
diff --git a/cinder/api/views/capabilities.py b/cinder/api/views/capabilities.py
new file mode 100644 (file)
index 0000000..77266d0
--- /dev/null
@@ -0,0 +1,41 @@
+# Copyright (c) 2015 Hitachi Data Systems, Inc.
+# All Rights Reserved.
+#
+#    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 cinder.api import common
+
+
+class ViewBuilder(common.ViewBuilder):
+    """Model capabilities API responses as a python dictionary."""
+
+    _collection_name = "capabilities"
+
+    def __init__(self):
+        """Initialize view builder."""
+        super(ViewBuilder, self).__init__()
+
+    def summary(self, request, capabilities, id):
+        """Summary view of a backend capabilities."""
+        return {
+            'namespace': 'OS::Storage::Capabilities::%s' % id,
+            'vendor_name': capabilities.get('vendor_name'),
+            'volume_backend_name': capabilities.get('volume_backend_name'),
+            'pool_name': capabilities.get('pool_name'),
+            'driver_version': capabilities.get('driver_version'),
+            'storage_protocol': capabilities.get('storage_protocol'),
+            'display_name': capabilities.get('display_name'),
+            'description': capabilities.get('description'),
+            'visibility': capabilities.get('visibility'),
+            'properties': capabilities.get('properties'),
+        }
diff --git a/cinder/tests/unit/api/contrib/test_capabilities.py b/cinder/tests/unit/api/contrib/test_capabilities.py
new file mode 100644 (file)
index 0000000..c5467e7
--- /dev/null
@@ -0,0 +1,102 @@
+# Copyright (c) 2015 Hitachi Data Systems, Inc.
+# All Rights Reserved.
+#
+#    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.
+
+import mock
+
+from cinder.api.contrib import capabilities
+from cinder import context
+from cinder import test
+from cinder.tests.unit.api import fakes
+
+
+def rpcapi_get_capabilities(self, context, host, discover):
+    capabilities = dict(
+        vendor_name='OpenStack',
+        volume_backend_name='lvm',
+        pool_name='pool',
+        driver_version='2.0.0',
+        storage_protocol='iSCSI',
+        display_name='Capabilities of Cinder LVM driver',
+        description='These are volume type options provided by '
+                    'Cinder LVM driver, blah, blah.',
+        visibility='public',
+        properties = dict(
+            compression = dict(
+                title='Compression',
+                description='Enables compression.',
+                type='boolean'),
+            qos = dict(
+                title='QoS',
+                description='Enables QoS.',
+                type='boolean'),
+            replication = dict(
+                title='Replication',
+                description='Enables replication.',
+                type='boolean'),
+            thin_provisioning = dict(
+                title='Thin Provisioning',
+                description='Sets thin provisioning.',
+                type='boolean'),
+        )
+    )
+    return capabilities
+
+
+@mock.patch('cinder.volume.rpcapi.VolumeAPI.get_capabilities',
+            rpcapi_get_capabilities)
+class CapabilitiesAPITest(test.TestCase):
+    def setUp(self):
+        super(CapabilitiesAPITest, self).setUp()
+        self.flags(host='fake')
+        self.controller = capabilities.CapabilitiesController()
+        self.ctxt = context.RequestContext('admin', 'fake', True)
+
+    def test_capabilities_summary(self):
+        req = fakes.HTTPRequest.blank('/fake/capabilities/fake')
+        req.environ['cinder.context'] = self.ctxt
+        res = self.controller.show(req, 'fake')
+
+        expected = {
+            'namespace': 'OS::Storage::Capabilities::fake',
+            'vendor_name': 'OpenStack',
+            'volume_backend_name': 'lvm',
+            'pool_name': 'pool',
+            'driver_version': '2.0.0',
+            'storage_protocol': 'iSCSI',
+            'display_name': 'Capabilities of Cinder LVM driver',
+            'description': 'These are volume type options provided by '
+                           'Cinder LVM driver, blah, blah.',
+            'visibility': 'public',
+            'properties': {
+                'compression': {
+                    'title': 'Compression',
+                    'description': 'Enables compression.',
+                    'type': 'boolean'},
+                'qos': {
+                    'title': 'QoS',
+                    'description': 'Enables QoS.',
+                    'type': 'boolean'},
+                'replication': {
+                    'title': 'Replication',
+                    'description': 'Enables replication.',
+                    'type': 'boolean'},
+                'thin_provisioning': {
+                    'title': 'Thin Provisioning',
+                    'description': 'Sets thin provisioning.',
+                    'type': 'boolean'},
+            }
+        }
+
+        self.assertDictMatch(expected, res)
index 05b27d16deba88500cdbf36bb47d102c93591b2c..5cd0b06d073fc948fd02c1cd19b8fe7a4486df14 100644 (file)
@@ -70,6 +70,7 @@
     "volume_extension:services:update" : "rule:admin_api",
     "volume_extension:volume_manage": "rule:admin_api",
     "volume_extension:volume_unmanage": "rule:admin_api",
+    "volume_extension:capabilities": "rule:admin_api",
 
     "limits_extension:used_limits": "",
 
index efe3c0488a895b7815e76e6d143957a07fcd8821..e6ef41a7ee0099cd18a4ad07a03fb20bc3cededa 100644 (file)
@@ -56,6 +56,8 @@
     "volume_extension:volume_manage": "rule:admin_api",
     "volume_extension:volume_unmanage": "rule:admin_api",
 
+    "volume_extension:capabilities": "rule:admin_api",
+
     "volume:create_transfer": "",
     "volume:accept_transfer": "",
     "volume:delete_transfer": "",