diff --git a/novaclient/v1_1/contrib/list_extensions.py b/novaclient/v1_1/contrib/list_extensions.py new file mode 100644 index 000000000..f184238dc --- /dev/null +++ b/novaclient/v1_1/contrib/list_extensions.py @@ -0,0 +1,46 @@ +# 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 novaclient import base +from novaclient 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') + + +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) diff --git a/tests/v1_1/contrib/__init__.py b/tests/v1_1/contrib/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/v1_1/contrib/test_list_extensions.py b/tests/v1_1/contrib/test_list_extensions.py new file mode 100644 index 000000000..8b0651158 --- /dev/null +++ b/tests/v1_1/contrib/test_list_extensions.py @@ -0,0 +1,21 @@ +from novaclient import extension +from novaclient.v1_1.contrib import list_extensions + +from tests import utils +from tests.v1_1 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) diff --git a/tests/v1_1/fakes.py b/tests/v1_1/fakes.py index 30af70f3b..fddd44416 100644 --- a/tests/v1_1/fakes.py +++ b/tests/v1_1/fakes.py @@ -25,7 +25,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) @@ -67,6 +68,53 @@ class FakeHTTPClient(base_client.HTTPClient): else: return httplib2.Response({"status": status}), body + # + # List all extensions + # + + def get_extensions(self, **kw): + exts = [ + { + "alias": "NMN", + "description": "Multiple network support", + "links": [], + "name": "Multinic", + "namespace": ("http://docs.openstack.org/" + "compute/ext/multinic/api/v1.1"), + "updated": "2011-06-09T00:00:00+00:00" + }, + { + "alias": "OS-DCF", + "description": "Disk Management Extension", + "links": [], + "name": "DiskConfig", + "namespace": ("http://docs.openstack.org/" + "compute/ext/disk_config/api/v1.1"), + "updated": "2011-09-27T00:00:00+00:00" + }, + { + "alias": "OS-EXT-SRV-ATTR", + "description": "Extended Server Attributes support.", + "links": [], + "name": "ExtendedServerAttributes", + "namespace": ("http://docs.openstack.org/" + "compute/ext/extended_status/api/v1.1"), + "updated": "2011-11-03T00:00:00+00:00" + }, + { + "alias": "OS-EXT-STS", + "description": "Extended Status support", + "links": [], + "name": "ExtendedStatus", + "namespace": ("http://docs.openstack.org/" + "compute/ext/extended_status/api/v1.1"), + "updated": "2011-11-03T00:00:00+00:00" + }, + ] + return (200, { + "extensions": exts, + }) + # # Limits #