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
This commit is contained in:
parent
e43c0f2b9b
commit
270c7fe967
openstackclient
@ -19,16 +19,14 @@ import logging
|
|||||||
|
|
||||||
from cliff import lister
|
from cliff import lister
|
||||||
|
|
||||||
from openstackclient.common import exceptions as exc
|
|
||||||
from openstackclient.common import utils
|
from openstackclient.common import utils
|
||||||
|
|
||||||
|
|
||||||
class ListExtension(lister.Lister):
|
class ListExtension(lister.Lister):
|
||||||
"""List extension command"""
|
"""List extension command"""
|
||||||
|
|
||||||
# TODO(mfisch): add support for volume and compute
|
# TODO(mfisch): add support for volume and network
|
||||||
# when the underlying APIs support it. Add support
|
# when the underlying APIs support it.
|
||||||
# for network when it's added to openstackclient.
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__ + '.ListExtension')
|
log = logging.getLogger(__name__ + '.ListExtension')
|
||||||
|
|
||||||
@ -44,6 +42,11 @@ class ListExtension(lister.Lister):
|
|||||||
action='store_true',
|
action='store_true',
|
||||||
default=False,
|
default=False,
|
||||||
help='List extensions for the Identity API')
|
help='List extensions for the Identity API')
|
||||||
|
parser.add_argument(
|
||||||
|
'--compute',
|
||||||
|
action='store_true',
|
||||||
|
default=False,
|
||||||
|
help='List extensions for the Compute API')
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
def take_action(self, parsed_args):
|
def take_action(self, parsed_args):
|
||||||
@ -59,17 +62,24 @@ class ListExtension(lister.Lister):
|
|||||||
|
|
||||||
# by default we want to show everything, unless the
|
# by default we want to show everything, unless the
|
||||||
# user specifies one or more of the APIs to show
|
# user specifies one or more of the APIs to show
|
||||||
# for now, only identity is supported
|
# for now, only identity and compute are supported.
|
||||||
show_all = (not parsed_args.identity)
|
show_all = (not parsed_args.identity and not parsed_args.compute)
|
||||||
|
|
||||||
if parsed_args.identity or show_all:
|
if parsed_args.identity or show_all:
|
||||||
identity_client = self.app.client_manager.identity
|
identity_client = self.app.client_manager.identity
|
||||||
try:
|
try:
|
||||||
data += identity_client.extensions.list()
|
data += identity_client.extensions.list()
|
||||||
except Exception:
|
except Exception:
|
||||||
raise exc.CommandError(
|
message = "Extensions list not supported by Identity API"
|
||||||
"Extensions list not supported by"
|
self.log.warning(message)
|
||||||
" identity API")
|
|
||||||
|
if parsed_args.compute or show_all:
|
||||||
|
compute_client = self.app.client_manager.compute
|
||||||
|
try:
|
||||||
|
data += compute_client.list_extensions.show_all()
|
||||||
|
except Exception:
|
||||||
|
message = "Extensions list not supported by Compute API"
|
||||||
|
self.log.warning(message)
|
||||||
|
|
||||||
return (columns,
|
return (columns,
|
||||||
(utils.get_item_properties(
|
(utils.get_item_properties(
|
||||||
|
@ -15,6 +15,9 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from novaclient import extension
|
||||||
|
from novaclient.v1_1.contrib import list_extensions
|
||||||
|
|
||||||
from openstackclient.common import utils
|
from openstackclient.common import utils
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@ -39,6 +42,7 @@ def make_client(instance):
|
|||||||
# Set client http_log_debug to True if verbosity level is high enough
|
# Set client http_log_debug to True if verbosity level is high enough
|
||||||
http_log_debug = utils.get_effective_log_level() <= logging.DEBUG
|
http_log_debug = utils.get_effective_log_level() <= logging.DEBUG
|
||||||
|
|
||||||
|
extensions = [extension.Extension('list_extensions', list_extensions)]
|
||||||
client = compute_client(
|
client = compute_client(
|
||||||
username=instance._username,
|
username=instance._username,
|
||||||
api_key=instance._password,
|
api_key=instance._password,
|
||||||
@ -49,8 +53,7 @@ def make_client(instance):
|
|||||||
region_name=instance._region_name,
|
region_name=instance._region_name,
|
||||||
# FIXME(dhellmann): get endpoint_type from option?
|
# FIXME(dhellmann): get endpoint_type from option?
|
||||||
endpoint_type='publicURL',
|
endpoint_type='publicURL',
|
||||||
# FIXME(dhellmann): add extension discovery
|
extensions=extensions,
|
||||||
extensions=[],
|
|
||||||
service_type=API_NAME,
|
service_type=API_NAME,
|
||||||
# FIXME(dhellmann): what is service_name?
|
# FIXME(dhellmann): what is service_name?
|
||||||
service_name='',
|
service_name='',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user