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
This commit is contained in:
Ken'ichi Ohmichi 2014-05-03 13:33:39 +09:00
parent b23c97d634
commit 661231817d
5 changed files with 98 additions and 0 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -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='<server>', help='Name or ID of server.')
@utils.arg('--port',
dest='port',