Add list-extensions capability to cinderclient.
Implements the list extension functionality from novaclient written by harlowja (Change-Id: I5b72f5ea73c00f1c1a0f09f670d744c820e05837) This provides a mechanism to view available extensions, and also starts actually using the cinderclient contrib dir. Original Author: harlowja Change-Id: I4f9d04cb8a2aa05c978a2a5a926c9175ee3614bb
This commit is contained in:
47
cinderclient/v1/contrib/list_extensions.py
Normal file
47
cinderclient/v1/contrib/list_extensions.py
Normal file
@@ -0,0 +1,47 @@
|
||||
# Copyright 2011 OpenStack LLC.
|
||||
# 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 import base
|
||||
from cinderclient import utils
|
||||
|
||||
|
||||
class ListExtResource(base.Resource):
|
||||
@property
|
||||
def summary(self):
|
||||
descr = self.description.strip()
|
||||
if not descr:
|
||||
return '??'
|
||||
lines = descr.split("\n")
|
||||
if len(lines) == 1:
|
||||
return lines[0]
|
||||
else:
|
||||
return lines[0] + "..."
|
||||
|
||||
|
||||
class ListExtManager(base.Manager):
|
||||
resource_class = ListExtResource
|
||||
|
||||
def show_all(self):
|
||||
return self._list("/extensions", 'extensions')
|
||||
|
||||
|
||||
@utils.service_type('volume')
|
||||
def do_list_extensions(client, _args):
|
||||
"""
|
||||
List all the os-api extensions that are available.
|
||||
"""
|
||||
extensions = client.list_extensions.show_all()
|
||||
fields = ["Name", "Summary", "Alias", "Updated"]
|
||||
utils.print_list(extensions, fields)
|
||||
0
tests/v1/contrib/__init__.py
Normal file
0
tests/v1/contrib/__init__.py
Normal file
21
tests/v1/contrib/test_list_extensions.py
Normal file
21
tests/v1/contrib/test_list_extensions.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from cinderclient import extension
|
||||
from cinderclient.v1.contrib import list_extensions
|
||||
|
||||
from tests import utils
|
||||
from tests.v1 import fakes
|
||||
|
||||
|
||||
extensions = [
|
||||
extension.Extension(list_extensions.__name__.split(".")[-1],
|
||||
list_extensions),
|
||||
]
|
||||
cs = fakes.FakeClient(extensions=extensions)
|
||||
|
||||
|
||||
class ListExtensionsTests(utils.TestCase):
|
||||
def test_list_extensions(self):
|
||||
all_exts = cs.list_extensions.show_all()
|
||||
cs.assert_called('GET', '/extensions')
|
||||
self.assertTrue(len(all_exts) > 0)
|
||||
for r in all_exts:
|
||||
self.assertTrue(len(r.summary) > 0)
|
||||
@@ -61,7 +61,8 @@ class FakeClient(fakes.FakeClient, client.Client):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
client.Client.__init__(self, 'username', 'password',
|
||||
'project_id', 'auth_url')
|
||||
'project_id', 'auth_url',
|
||||
extensions=kwargs.get('extensions'))
|
||||
self.client = FakeHTTPClient(**kwargs)
|
||||
|
||||
|
||||
@@ -96,7 +97,6 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
|
||||
# Note the call
|
||||
self.callstack.append((method, url, kwargs.get('body', None)))
|
||||
|
||||
status, headers, body = getattr(self, callback)(**kwargs)
|
||||
r = utils.TestResponse({
|
||||
"status_code": status,
|
||||
@@ -267,3 +267,29 @@ class FakeHTTPClient(base_client.HTTPClient):
|
||||
|
||||
def delete_types_1(self, **kw):
|
||||
return (202, {}, None)
|
||||
|
||||
#
|
||||
# List all extensions
|
||||
#
|
||||
def get_extensions(self, **kw):
|
||||
exts = [
|
||||
{
|
||||
"alias": "FAKE-1",
|
||||
"description": "Fake extension number 1",
|
||||
"links": [],
|
||||
"name": "Fake1",
|
||||
"namespace": ("http://docs.openstack.org/"
|
||||
"/ext/fake1/api/v1.1"),
|
||||
"updated": "2011-06-09T00:00:00+00:00"
|
||||
},
|
||||
{
|
||||
"alias": "FAKE-2",
|
||||
"description": "Fake extension number 2",
|
||||
"links": [],
|
||||
"name": "Fake2",
|
||||
"namespace": ("http://docs.openstack.org/"
|
||||
"/ext/fake1/api/v1.1"),
|
||||
"updated": "2011-06-09T00:00:00+00:00"
|
||||
},
|
||||
]
|
||||
return (200, {}, {"extensions": exts, })
|
||||
|
||||
Reference in New Issue
Block a user