summaryrefslogtreecommitdiff
path: root/openstackclient/shell.py
diff options
context:
space:
mode:
authorDean Troyer <dtroyer@gmail.com>2015-09-04 16:22:33 -0500
committerDean Troyer <dtroyer@gmail.com>2015-09-04 16:25:55 -0500
commit3abfea083a13c9aa69bedd10ea0286353d2f5887 (patch)
tree09e5bffc7e907eeb3d51be42f7670620d38655ed /openstackclient/shell.py
parent9210cac86a2d5d3df9989f40b1fcc605e5f78ed8 (diff)
downloadpython-openstackclient-3abfea083a13c9aa69bedd10ea0286353d2f5887.tar.gz
Fix compute API version snafu
novaclient 2.27.0 introduced the API microversion discovery and client.Client now wants an api_version argument to properly work out the correct API version in use. OSC needs to provide this when required. Letting the compute client plugin do the version validity checking makes more sense than encoding it into shell.py, so I've added a new OSC plugin interface function check_api_version() that is called from shell.py if it exists. If it either does not exist or it returns False the previous version checking using API_VERSIONS is still performed. compute.client.check_api_version() conditionally imports the new novaclient.api_versions module and uses it if successful. Otherwise check_api_version() returns False and the previous code path is resumed. One side-effect of this is that it is now valid to use --os-compute-api-version with any valid microversion supported by the installed python-novaclient. Closes-Bug: #1492467 Change-Id: I4535b38a5639a03a9597bf83f6394f9bb45c2b9e
Diffstat (limited to 'openstackclient/shell.py')
-rw-r--r--openstackclient/shell.py22
1 files changed, 17 insertions, 5 deletions
diff --git a/openstackclient/shell.py b/openstackclient/shell.py
index a8b5ac4c..27bcba48 100644
--- a/openstackclient/shell.py
+++ b/openstackclient/shell.py
@@ -304,11 +304,23 @@ class OpenStackShell(app.App):
if version_opt:
api = mod.API_NAME
self.api_version[api] = version_opt
- if version_opt not in mod.API_VERSIONS:
- self.log.warning(
- "The %s version <%s> is not in supported versions <%s>"
- % (api, version_opt,
- ', '.join(mod.API_VERSIONS.keys())))
+
+ # Add a plugin interface to let the module validate the version
+ # requested by the user
+ skip_old_check = False
+ mod_check_api_version = getattr(mod, 'check_api_version', None)
+ if mod_check_api_version:
+ # this throws an exception if invalid
+ skip_old_check = mod_check_api_version(version_opt)
+
+ mod_versions = getattr(mod, 'API_VERSIONS', None)
+ if not skip_old_check and mod_versions:
+ if version_opt not in mod_versions:
+ self.log.warning(
+ "%s version %s is not in supported versions %s"
+ % (api, version_opt,
+ ', '.join(mod.API_VERSIONS.keys())))
+
# Command groups deal only with major versions
version = '.v' + version_opt.replace('.', '_').split('_')[0]
cmd_group = 'openstack.' + api.replace('-', '_') + version