From 661231817d93f937af31700593ed707017ab48f7 Mon Sep 17 00:00:00 2001 From: Ken'ichi Ohmichi Date: Sat, 3 May 2014 13:33:39 +0900 Subject: [PATCH] Add extension-list command for v3 API Nova returns available extension list through its REST API. The command of v2 API has been implemented, and this patch adds the one of v3 API. Note: The command name of v2 is "nova list-extensions" but the one of v3, which this patch adds, is "nova extension-list" because the name fits to the other command names. Change-Id: Ibee712b0aa5898a94e362f20be71e8863500b195 --- novaclient/tests/v3/fakes.py | 28 +++++++++++++++++ novaclient/tests/v3/test_list_extensions.py | 33 +++++++++++++++++++++ novaclient/v3/client.py | 2 ++ novaclient/v3/list_extensions.py | 26 ++++++++++++++++ novaclient/v3/shell.py | 9 ++++++ 5 files changed, 98 insertions(+) create mode 100644 novaclient/tests/v3/test_list_extensions.py create mode 100644 novaclient/v3/list_extensions.py diff --git a/novaclient/tests/v3/fakes.py b/novaclient/tests/v3/fakes.py index 43b5e05e7..9aad01716 100644 --- a/novaclient/tests/v3/fakes.py +++ b/novaclient/tests/v3/fakes.py @@ -344,3 +344,31 @@ class FakeHTTPClient(fakes_v1_1.FakeHTTPClient): get_keypairs = fakes_v1_1.FakeHTTPClient.get_os_keypairs delete_keypairs_test = fakes_v1_1.FakeHTTPClient.delete_os_keypairs_test post_keypairs = fakes_v1_1.FakeHTTPClient.post_os_keypairs + + # + # List all extensions + # + def get_extensions(self, **kw): + exts = [ + { + "alias": "os-multinic", + "description": "Multiple network support", + "name": "Multinic", + "version": 1, + }, + { + "alias": "os-extended-server-attributes", + "description": "Extended Server Attributes support.", + "name": "ExtendedServerAttributes", + "version": 1, + }, + { + "alias": "os-extended-status", + "description": "Extended Status support", + "name": "ExtendedStatus", + "version": 1, + }, + ] + return (200, {}, { + "extensions": exts, + }) diff --git a/novaclient/tests/v3/test_list_extensions.py b/novaclient/tests/v3/test_list_extensions.py new file mode 100644 index 000000000..61d387c3c --- /dev/null +++ b/novaclient/tests/v3/test_list_extensions.py @@ -0,0 +1,33 @@ +# Copyright 2014 NEC Corporation. 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 extension +from novaclient.tests import utils +from novaclient.tests.v3 import fakes +from novaclient.v3 import list_extensions + + +extensions = [ + extension.Extension("list_extensions", 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/novaclient/v3/client.py b/novaclient/v3/client.py index 4f454e220..7af2e1f2b 100644 --- a/novaclient/v3/client.py +++ b/novaclient/v3/client.py @@ -24,6 +24,7 @@ from novaclient.v3 import hosts from novaclient.v3 import hypervisors from novaclient.v3 import images from novaclient.v3 import keypairs +from novaclient.v3 import list_extensions from novaclient.v3 import quotas from novaclient.v3 import servers from novaclient.v3 import services @@ -84,6 +85,7 @@ class Client(object): self.availability_zones = \ availability_zones.AvailabilityZoneManager(self) self.certs = certs.CertificateManager(self) + self.list_extensions = list_extensions.ListExtManager(self) self.hosts = hosts.HostManager(self) self.flavors = flavors.FlavorManager(self) self.flavor_access = flavor_access.FlavorAccessManager(self) diff --git a/novaclient/v3/list_extensions.py b/novaclient/v3/list_extensions.py new file mode 100644 index 000000000..bcc187494 --- /dev/null +++ b/novaclient/v3/list_extensions.py @@ -0,0 +1,26 @@ +# Copyright 2014 NEC Corporation. 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. +""" +extension interface +""" + +from novaclient.v1_1.contrib import list_extensions + + +class ListExtResource(list_extensions.ListExtResource): + pass + + +class ListExtManager(list_extensions.ListExtManager): + pass diff --git a/novaclient/v3/shell.py b/novaclient/v3/shell.py index f3710354c..3736bcb85 100644 --- a/novaclient/v3/shell.py +++ b/novaclient/v3/shell.py @@ -2584,6 +2584,15 @@ def do_credentials(cs, _args): utils.print_dict(catalog['access']['token'], "Token", wrap=int(_args.wrap)) +def do_extension_list(cs, _args): + """ + List all the os-api extensions that are available. + """ + extensions = cs.list_extensions.show_all() + fields = ["Name", "Summary", "Alias", "Version"] + utils.print_list(extensions, fields) + + @utils.arg('server', metavar='', help='Name or ID of server.') @utils.arg('--port', dest='port',