summaryrefslogtreecommitdiff
path: root/openstackclient/common
diff options
context:
space:
mode:
authorJude Cross <jucross@blizzard.com>2018-04-02 15:07:25 -0700
committerJude Cross <jucross@blizzard.com>2018-04-03 00:47:00 -0700
commit24b06ef273e193819624fd2e021282d2735977b0 (patch)
tree464eb71b2a22377f1c7bce2b02486f686e2baebc /openstackclient/common
parent180d012ca728112e518e53230612fe22a722e4b9 (diff)
downloadpython-openstackclient-24b06ef273e193819624fd2e021282d2735977b0.tar.gz
Fix limits show command without Nova and Cinder
This patch implements an endpoint lookup when showing limits. This addresses the issue when showing limits without both Nova and Cinder and will display limits if one is missing. Change-Id: I2214b281e0206f8fe117aae52de2bf4c4e2c6525 Closes-bug: #1707960
Diffstat (limited to 'openstackclient/common')
-rw-r--r--openstackclient/common/clientmanager.py19
-rw-r--r--openstackclient/common/limits.py32
2 files changed, 40 insertions, 11 deletions
diff --git a/openstackclient/common/clientmanager.py b/openstackclient/common/clientmanager.py
index 89781052..aa1045e4 100644
--- a/openstackclient/common/clientmanager.py
+++ b/openstackclient/common/clientmanager.py
@@ -125,6 +125,25 @@ class ClientManager(clientmanager.ClientManager):
# use Network API by default
return self.is_service_available('network') is not False
+ def is_compute_endpoint_enabled(self):
+ """Check if Compute endpoint is enabled"""
+
+ return self.is_service_available('compute') is not False
+
+ def is_volume_endpoint_enabled(self, volume_client):
+ """Check if volume endpoint is enabled"""
+ # NOTE(jcross): Cinder did some interesting things with their service
+ # name so we need to figure out which version to look
+ # for when calling is_service_available()
+ volume_version = volume_client.api_version.ver_major
+ if self.is_service_available(
+ "volumev%s" % volume_version) is not False:
+ return True
+ elif self.is_service_available('volume') is not False:
+ return True
+ else:
+ return False
+
# Plugin Support
diff --git a/openstackclient/common/limits.py b/openstackclient/common/limits.py
index 957f1d02..19db35d7 100644
--- a/openstackclient/common/limits.py
+++ b/openstackclient/common/limits.py
@@ -83,24 +83,34 @@ class ShowLimits(command.Lister):
project_id = utils.find_resource(identity_client.projects,
parsed_args.project).id
- compute_limits = compute_client.limits.get(parsed_args.is_reserved,
- tenant_id=project_id)
- volume_limits = volume_client.limits.get()
+ compute_limits = None
+ volume_limits = None
+ if self.app.client_manager.is_compute_endpoint_enabled():
+ compute_limits = compute_client.limits.get(parsed_args.is_reserved,
+ tenant_id=project_id)
+
+ if self.app.client_manager.is_volume_endpoint_enabled(volume_client):
+ volume_limits = volume_client.limits.get()
+
+ data = []
if parsed_args.is_absolute:
- compute_limits = compute_limits.absolute
- volume_limits = volume_limits.absolute
+ if compute_limits:
+ data.append(compute_limits.absolute)
+ if volume_limits:
+ data.append(volume_limits.absolute)
columns = ["Name", "Value"]
return (columns, (utils.get_item_properties(s, columns)
- for s in itertools.chain(compute_limits, volume_limits)))
+ for s in itertools.chain(*data)))
elif parsed_args.is_rate:
- compute_limits = compute_limits.rate
- volume_limits = volume_limits.rate
+ if compute_limits:
+ data.append(compute_limits.rate)
+ if volume_limits:
+ data.append(volume_limits.rate)
columns = ["Verb", "URI", "Value", "Remain", "Unit",
"Next Available"]
return (columns, (utils.get_item_properties(s, columns)
- for s in itertools.chain(compute_limits, volume_limits)))
-
+ for s in itertools.chain(*data)))
else:
- return ({}, {})
+ return {}, {}