summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMitsuhiro Tanino <mitsuhiro.tanino@hds.com>2015-08-12 19:10:32 -0400
committerMitsuhiro Tanino <mitsuhiro.tanino@hds.com>2015-09-02 00:53:40 +0000
commit471aea8e9f3c0ab22da1ef96db100400e6510227 (patch)
treec4a75df150e6d7ec700de23b5d8511188a464d56
parent5dbac012e27442ced994e25f685f73cbd1ae7a2e (diff)
downloadpython-cinderclient-471aea8e9f3c0ab22da1ef96db100400e6510227.tar.gz
Adds command to fetch specified backend capabilities
This change adds a new admin-api to allow admin to fetch specified backend capabilities which includes volume stats and vendor unique properties. With this command, admin can obtain what the current deployed backend in Cinder is able to do from the endpoint. DocImpact Implements: blueprint get-volume-type-extra-specs Change-Id: I355a5b57994d1407a088c86530d7ef362ecd31ed
-rw-r--r--cinderclient/tests/unit/v2/fakes.py17
-rw-r--r--cinderclient/tests/unit/v2/test_capabilities.py41
-rw-r--r--cinderclient/tests/unit/v2/test_shell.py4
-rw-r--r--cinderclient/v2/capabilities.py39
-rw-r--r--cinderclient/v2/client.py2
-rw-r--r--cinderclient/v2/shell.py17
6 files changed, 120 insertions, 0 deletions
diff --git a/cinderclient/tests/unit/v2/fakes.py b/cinderclient/tests/unit/v2/fakes.py
index a34bf47..8182505 100644
--- a/cinderclient/tests/unit/v2/fakes.py
+++ b/cinderclient/tests/unit/v2/fakes.py
@@ -1067,3 +1067,20 @@ class FakeHTTPClient(base_client.HTTPClient):
},
]
return (200, {}, {"pools": stats})
+
+ def get_capabilities_host(self, **kw):
+ return (200, {},
+ {
+ 'namespace': 'OS::Storage::Capabilities::fake',
+ 'vendor_name': 'OpenStack',
+ 'volume_backend_name': 'lvm',
+ 'pool_name': 'pool',
+ 'storage_protocol': 'iSCSI',
+ 'properties': {
+ 'compression': {
+ 'title': 'Compression',
+ 'description': 'Enables compression.',
+ 'type': 'boolean'},
+ }
+ }
+ )
diff --git a/cinderclient/tests/unit/v2/test_capabilities.py b/cinderclient/tests/unit/v2/test_capabilities.py
new file mode 100644
index 0000000..d23bdcd
--- /dev/null
+++ b/cinderclient/tests/unit/v2/test_capabilities.py
@@ -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 cinderclient.tests.unit import utils
+from cinderclient.tests.unit.v2 import fakes
+
+cs = fakes.FakeClient()
+
+
+class CapabilitiesTest(utils.TestCase):
+
+ def test_get_capabilities(self):
+ expected = {
+ 'namespace': 'OS::Storage::Capabilities::fake',
+ 'vendor_name': 'OpenStack',
+ 'volume_backend_name': 'lvm',
+ 'pool_name': 'pool',
+ 'storage_protocol': 'iSCSI',
+ 'properties': {
+ 'compression': {
+ 'title': 'Compression',
+ 'description': 'Enables compression.',
+ 'type': 'boolean'},
+ }
+ }
+
+ capabilities = cs.capabilities.get('host')
+ cs.assert_called('GET', '/capabilities/host')
+ self.assertEqual(expected, capabilities._info)
diff --git a/cinderclient/tests/unit/v2/test_shell.py b/cinderclient/tests/unit/v2/test_shell.py
index 6ba1a03..4cb3f63 100644
--- a/cinderclient/tests/unit/v2/test_shell.py
+++ b/cinderclient/tests/unit/v2/test_shell.py
@@ -1045,3 +1045,7 @@ class ShellTest(utils.TestCase):
def test_backup_list(self):
self.run_command('backup-list')
self.assert_called('GET', '/backups/detail')
+
+ def test_get_capabilities(self):
+ self.run_command('get-capabilities host')
+ self.assert_called('GET', '/capabilities/host')
diff --git a/cinderclient/v2/capabilities.py b/cinderclient/v2/capabilities.py
new file mode 100644
index 0000000..a30c155
--- /dev/null
+++ b/cinderclient/v2/capabilities.py
@@ -0,0 +1,39 @@
+# 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.
+
+"""Capabilities interface (v2 extension)"""
+
+
+from cinderclient import base
+
+
+class Capabilities(base.Resource):
+ NAME_ATTR = 'name'
+
+ def __repr__(self):
+ return "<Capabilities: %s>" % self.name
+
+
+class CapabilitiesManager(base.Manager):
+ """Manage :class:`Capabilities` resources."""
+ resource_class = Capabilities
+
+ def get(self, host):
+ """Show backend volume stats and properties.
+
+ :param host: Specified backend to obtain volume stats and properties.
+ :rtype: :class:`Capabilities`
+ """
+ return self._get('/capabilities/%s' % host, None)
diff --git a/cinderclient/v2/client.py b/cinderclient/v2/client.py
index 01c57de..0d9abeb 100644
--- a/cinderclient/v2/client.py
+++ b/cinderclient/v2/client.py
@@ -17,6 +17,7 @@ from cinderclient import client
from cinderclient.v2 import availability_zones
from cinderclient.v2 import cgsnapshots
from cinderclient.v2 import consistencygroups
+from cinderclient.v2 import capabilities
from cinderclient.v2 import limits
from cinderclient.v2 import pools
from cinderclient.v2 import qos_specs
@@ -80,6 +81,7 @@ class Client(object):
self.availability_zones = \
availability_zones.AvailabilityZoneManager(self)
self.pools = pools.PoolManager(self)
+ self.capabilities = capabilities.CapabilitiesManager(self)
# Add in any extensions...
if extensions:
diff --git a/cinderclient/v2/shell.py b/cinderclient/v2/shell.py
index 7087f9f..f041be8 100644
--- a/cinderclient/v2/shell.py
+++ b/cinderclient/v2/shell.py
@@ -2317,3 +2317,20 @@ def do_get_pools(cs, args):
if args.detail:
backend.update(info['capabilities'])
utils.print_dict(backend)
+
+
+@utils.arg('host',
+ metavar='<host>',
+ help='Cinder host to show backend volume stats and properties; '
+ 'takes the form: host@backend-name')
+@utils.service_type('volumev2')
+def do_get_capabilities(cs, args):
+ """Show backend volume stats and properties. Admin only."""
+
+ capabilities = cs.capabilities.get(args.host)
+ infos = dict()
+ infos.update(capabilities._info)
+
+ prop = infos.pop('properties', None)
+ utils.print_dict(infos, "Volume stats")
+ utils.print_dict(prop, "Backend properties")