Skip to content

Commit 270c7fe

Browse files
author
Steve Martinelli
committed
Add support to list compute extensions
Since novaclient has support to list extensions, we should add some of the logic to our list extensions command. Closes-Bug: #1337684 Change-Id: I3074225780142df265a34add03e60c0f7c64c711
1 parent e43c0f2 commit 270c7fe

2 files changed

Lines changed: 24 additions & 11 deletions

File tree

‎openstackclient/common/extension.py‎

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,14 @@
1919

2020
from cliff import lister
2121

22-
from openstackclient.common import exceptions as exc
2322
from openstackclient.common import utils
2423

2524

2625
class ListExtension(lister.Lister):
2726
"""List extension command"""
2827

29-
# TODO(mfisch): add support for volume and compute
30-
# when the underlying APIs support it. Add support
31-
# for network when it's added to openstackclient.
28+
# TODO(mfisch): add support for volume and network
29+
# when the underlying APIs support it.
3230

3331
log = logging.getLogger(__name__ + '.ListExtension')
3432

@@ -44,6 +42,11 @@ def get_parser(self, prog_name):
4442
action='store_true',
4543
default=False,
4644
help='List extensions for the Identity API')
45+
parser.add_argument(
46+
'--compute',
47+
action='store_true',
48+
default=False,
49+
help='List extensions for the Compute API')
4750
return parser
4851

4952
def take_action(self, parsed_args):
@@ -59,17 +62,24 @@ def take_action(self, parsed_args):
5962

6063
# by default we want to show everything, unless the
6164
# user specifies one or more of the APIs to show
62-
# for now, only identity is supported
63-
show_all = (not parsed_args.identity)
65+
# for now, only identity and compute are supported.
66+
show_all = (not parsed_args.identity and not parsed_args.compute)
6467

6568
if parsed_args.identity or show_all:
6669
identity_client = self.app.client_manager.identity
6770
try:
6871
data += identity_client.extensions.list()
6972
except Exception:
70-
raise exc.CommandError(
71-
"Extensions list not supported by"
72-
" identity API")
73+
message = "Extensions list not supported by Identity API"
74+
self.log.warning(message)
75+
76+
if parsed_args.compute or show_all:
77+
compute_client = self.app.client_manager.compute
78+
try:
79+
data += compute_client.list_extensions.show_all()
80+
except Exception:
81+
message = "Extensions list not supported by Compute API"
82+
self.log.warning(message)
7383

7484
return (columns,
7585
(utils.get_item_properties(

‎openstackclient/compute/client.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
import logging
1717

18+
from novaclient import extension
19+
from novaclient.v1_1.contrib import list_extensions
20+
1821
from openstackclient.common import utils
1922

2023
LOG = logging.getLogger(__name__)
@@ -39,6 +42,7 @@ def make_client(instance):
3942
# Set client http_log_debug to True if verbosity level is high enough
4043
http_log_debug = utils.get_effective_log_level() <= logging.DEBUG
4144

45+
extensions = [extension.Extension('list_extensions', list_extensions)]
4246
client = compute_client(
4347
username=instance._username,
4448
api_key=instance._password,
@@ -49,8 +53,7 @@ def make_client(instance):
4953
region_name=instance._region_name,
5054
# FIXME(dhellmann): get endpoint_type from option?
5155
endpoint_type='publicURL',
52-
# FIXME(dhellmann): add extension discovery
53-
extensions=[],
56+
extensions=extensions,
5457
service_type=API_NAME,
5558
# FIXME(dhellmann): what is service_name?
5659
service_name='',

0 commit comments

Comments
 (0)