Add support to list volume extensions

Since cinderclient has support to list extensions, we should add
some of the logic to our list extensions command.

Change-Id: I7dc7ca325ea9b82194bba6d875e7b8dc1884d77e
Closes-Bug: #1337687
This commit is contained in:
Steve Martinelli 2014-07-04 14:27:16 -04:00
parent 270c7fe967
commit 9b2e264ada
2 changed files with 21 additions and 2 deletions

View File

@ -47,6 +47,11 @@ class ListExtension(lister.Lister):
action='store_true', action='store_true',
default=False, default=False,
help='List extensions for the Compute API') help='List extensions for the Compute API')
parser.add_argument(
'--volume',
action='store_true',
default=False,
help='List extensions for the Volume API')
return parser return parser
def take_action(self, parsed_args): def take_action(self, parsed_args):
@ -63,7 +68,8 @@ 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 and compute are supported. # for now, only identity and compute are supported.
show_all = (not parsed_args.identity and not parsed_args.compute) show_all = (not parsed_args.identity and not parsed_args.compute
and not parsed_args.volume)
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
@ -81,6 +87,14 @@ class ListExtension(lister.Lister):
message = "Extensions list not supported by Compute API" message = "Extensions list not supported by Compute API"
self.log.warning(message) self.log.warning(message)
if parsed_args.volume or show_all:
volume_client = self.app.client_manager.volume
try:
data += volume_client.list_extensions.show_all()
except Exception:
message = "Extensions list not supported by Volume API"
self.log.warning(message)
return (columns, return (columns,
(utils.get_item_properties( (utils.get_item_properties(
s, columns, s, columns,

View File

@ -15,8 +15,11 @@
import logging import logging
from cinderclient import extension
from cinderclient.v1.contrib import list_extensions
from cinderclient.v1 import volume_snapshots from cinderclient.v1 import volume_snapshots
from cinderclient.v1 import volumes from cinderclient.v1 import volumes
from openstackclient.common import utils from openstackclient.common import utils
# Monkey patch for v1 cinderclient # Monkey patch for v1 cinderclient
@ -46,6 +49,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 = volume_client( client = volume_client(
username=instance._username, username=instance._username,
api_key=instance._password, api_key=instance._password,
@ -54,7 +58,8 @@ def make_client(instance):
cacert=instance._cacert, cacert=instance._cacert,
insecure=instance._insecure, insecure=instance._insecure,
region_name=instance._region_name, region_name=instance._region_name,
http_log_debug=http_log_debug extensions=extensions,
http_log_debug=http_log_debug,
) )
# Populate the Cinder client to skip another auth query to Identity # Populate the Cinder client to skip another auth query to Identity