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
This commit is contained in:
Mitsuhiro Tanino 2015-08-12 19:10:32 -04:00
parent 5dbac012e2
commit 471aea8e9f
6 changed files with 120 additions and 0 deletions

@ -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'},
}
}
)

@ -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)

@ -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')

@ -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)

@ -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:

@ -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")