summaryrefslogtreecommitdiff
path: root/openstackclient/common
diff options
context:
space:
mode:
Diffstat (limited to 'openstackclient/common')
-rw-r--r--openstackclient/common/clientmanager.py5
-rw-r--r--openstackclient/common/extension.py42
-rw-r--r--openstackclient/common/restapi.py4
-rw-r--r--openstackclient/common/timing.py44
-rw-r--r--openstackclient/common/utils.py4
5 files changed, 83 insertions, 16 deletions
diff --git a/openstackclient/common/clientmanager.py b/openstackclient/common/clientmanager.py
index b310f3ac..a2f85aff 100644
--- a/openstackclient/common/clientmanager.py
+++ b/openstackclient/common/clientmanager.py
@@ -49,7 +49,7 @@ class ClientManager(object):
user_domain_id=None, user_domain_name=None,
project_domain_id=None, project_domain_name=None,
region_name=None, api_version=None, verify=True,
- trust_id=None):
+ trust_id=None, timing=None):
self._token = token
self._url = url
self._auth_url = auth_url
@@ -67,6 +67,7 @@ class ClientManager(object):
self._api_version = api_version
self._trust_id = trust_id
self._service_catalog = None
+ self.timing = timing
# verify is the Requests-compatible form
self._verify = verify
@@ -116,7 +117,7 @@ def get_extension_modules(group):
setattr(
ClientManager,
- ep.name,
+ module.API_NAME,
ClientCache(
getattr(sys.modules[ep.module_name], 'make_client', None)
),
diff --git a/openstackclient/common/extension.py b/openstackclient/common/extension.py
index a8b1a6b0..91ee228b 100644
--- a/openstackclient/common/extension.py
+++ b/openstackclient/common/extension.py
@@ -19,16 +19,14 @@ import logging
from cliff import lister
-from openstackclient.common import exceptions as exc
from openstackclient.common import utils
class ListExtension(lister.Lister):
"""List extension command"""
- # TODO(mfisch): add support for volume and compute
- # when the underlying APIs support it. Add support
- # for network when it's added to openstackclient.
+ # TODO(mfisch): add support for volume and network
+ # when the underlying APIs support it.
log = logging.getLogger(__name__ + '.ListExtension')
@@ -44,6 +42,16 @@ class ListExtension(lister.Lister):
action='store_true',
default=False,
help='List extensions for the Identity API')
+ parser.add_argument(
+ '--compute',
+ action='store_true',
+ default=False,
+ 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
def take_action(self, parsed_args):
@@ -59,17 +67,33 @@ class ListExtension(lister.Lister):
# by default we want to show everything, unless the
# user specifies one or more of the APIs to show
- # for now, only identity is supported
- show_all = (not parsed_args.identity)
+ # for now, only identity and compute are supported.
+ show_all = (not parsed_args.identity and not parsed_args.compute
+ and not parsed_args.volume)
if parsed_args.identity or show_all:
identity_client = self.app.client_manager.identity
try:
data += identity_client.extensions.list()
except Exception:
- raise exc.CommandError(
- "Extensions list not supported by"
- " identity API")
+ message = "Extensions list not supported by Identity API"
+ self.log.warning(message)
+
+ 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)
+
+ 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,
(utils.get_item_properties(
diff --git a/openstackclient/common/restapi.py b/openstackclient/common/restapi.py
index f20ad23d..a4822a10 100644
--- a/openstackclient/common/restapi.py
+++ b/openstackclient/common/restapi.py
@@ -20,9 +20,9 @@ import logging
import requests
try:
- from urllib.parse import urlencode
+ from urllib.parse import urlencode # noqa
except ImportError:
- from urllib import urlencode
+ from urllib import urlencode # noqa
USER_AGENT = 'RAPI'
diff --git a/openstackclient/common/timing.py b/openstackclient/common/timing.py
new file mode 100644
index 00000000..1c94682c
--- /dev/null
+++ b/openstackclient/common/timing.py
@@ -0,0 +1,44 @@
+# 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.
+#
+
+"""Timing Implementation"""
+
+import logging
+
+from cliff import lister
+
+
+class Timing(lister.Lister):
+ """Show timing data"""
+
+ log = logging.getLogger(__name__ + '.Timing')
+
+ def take_action(self, parsed_args):
+ self.log.debug('take_action(%s)' % parsed_args)
+
+ column_headers = (
+ 'URL',
+ 'Seconds',
+ )
+
+ results = []
+ total = 0.0
+ for url, start, end in self.app.timing_data:
+ seconds = end - start
+ total += seconds
+ results.append((url, seconds))
+ results.append(('Total', total))
+ return (
+ column_headers,
+ results,
+ )
diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py
index 0258f931..51c3ed4b 100644
--- a/openstackclient/common/utils.py
+++ b/openstackclient/common/utils.py
@@ -23,7 +23,6 @@ import sys
import time
from openstackclient.common import exceptions
-from openstackclient.openstack.common import strutils
def find_resource(manager, name_or_id):
@@ -79,8 +78,7 @@ def format_dict(data):
output = ""
for s in data:
- output = output + s + "='" + \
- strutils.safe_encode(six.text_type(data[s])) + "', "
+ output = output + s + "='" + six.text_type(data[s]) + "', "
return output[:-2]