summaryrefslogtreecommitdiff
path: root/openstackclient/common
diff options
context:
space:
mode:
authorAnkur Gupta <ankur.gupta@intel.com>2017-03-24 12:39:22 -0500
committerRui Chen <chenrui.momo@gmail.com>2017-05-18 11:33:45 +0800
commitacc2d106abfb4fed0ff5d0d0c246d69f9ea1758b (patch)
tree9743c7f9fcf87b05b1f09598a9451a2cc8a38214 /openstackclient/common
parent0181de38afc8cc4b96f226b00e173fb0c0d2e4dc (diff)
downloadpython-openstackclient-acc2d106abfb4fed0ff5d0d0c246d69f9ea1758b.tar.gz
Refactor Extension show and list command
1.keep the column display order consist in extension list with and without "--long" option. 2.rework for network extentsion list, openstacksdk return object, so the logic should be same with other service. 3.add some unit test cases, like: extension list --network --long, extension list --network --compute, to cover regular use cases. 4.raise exact exception when network extension don't exist, avoid internal TypeError in "extension show" commands. Change-Id: I2e23ced80d8da8aa1106b22472db850367b351ce Closes-Bug: #1689233
Diffstat (limited to 'openstackclient/common')
-rw-r--r--openstackclient/common/extension.py49
1 files changed, 14 insertions, 35 deletions
diff --git a/openstackclient/common/extension.py b/openstackclient/common/extension.py
index d5b72238..139f43ab 100644
--- a/openstackclient/common/extension.py
+++ b/openstackclient/common/extension.py
@@ -15,7 +15,6 @@
"""Extension action implementations"""
-import itertools
import logging
from osc_lib.command import command
@@ -66,8 +65,8 @@ class ListExtension(command.Lister):
def take_action(self, parsed_args):
if parsed_args.long:
- columns = ('Name', 'Namespace', 'Description',
- 'Alias', 'Updated', 'Links')
+ columns = ('Name', 'Alias', 'Description',
+ 'Namespace', 'Updated', 'Links')
else:
columns = ('Name', 'Alias', 'Description')
@@ -104,35 +103,22 @@ class ListExtension(command.Lister):
"Block Storage API")
LOG.warning(message)
- # Resource classes for the above
+ if parsed_args.network or show_all:
+ network_client = self.app.client_manager.network
+ try:
+ data += network_client.extensions()
+ except Exception:
+ message = _("Failed to retrieve extensions list "
+ "from Network API")
+ LOG.warning(message)
+
extension_tuples = (
utils.get_item_properties(
s,
columns,
- formatters={},
) for s in data
)
- # Dictionaries for the below
- if parsed_args.network or show_all:
- network_client = self.app.client_manager.network
- try:
- data = network_client.extensions()
- dict_tuples = (
- utils.get_item_properties(
- s,
- columns,
- formatters={},
- ) for s in data
- )
- extension_tuples = itertools.chain(
- extension_tuples,
- dict_tuples
- )
- except Exception:
- message = _("Extensions list not supported by Network API")
- LOG.warning(message)
-
return (columns, extension_tuples)
@@ -152,14 +138,7 @@ class ShowExtension(command.ShowOne):
def take_action(self, parsed_args):
client = self.app.client_manager.network
- columns = ('Alias', 'Description', 'Links', 'Name',
- 'Namespace', 'Updated')
ext = str(parsed_args.extension)
- obj = client.find_extension(ext)
- dict_tuples = (utils.get_item_properties(
- obj,
- columns,
- formatters={},)
- )
-
- return columns, dict_tuples
+ obj = client.find_extension(ext, ignore_missing=False).to_dict()
+
+ return zip(*sorted(obj.items()))