diff options
| author | Rui Chen <chenrui.momo@gmail.com> | 2016-03-25 14:51:06 +0800 |
|---|---|---|
| committer | Rui Chen <chenrui.momo@gmail.com> | 2016-04-20 03:24:47 +0000 |
| commit | a5a343a5a86658246cc136a330eee951e32c7b56 (patch) | |
| tree | 29ee88db5347fb2b641e39fe2fa34013d6d6fa8d /openstackclient/compute/client.py | |
| parent | 4639148b1dc059efab0d00a886e3f05f547a439f (diff) | |
| download | python-openstackclient-a5a343a5a86658246cc136a330eee951e32c7b56.tar.gz | |
Support X.latest format for OS_COMPUTE_API_VERSION
OSC don't support to use "X.latest" format in order to talk with the
latest nova microversion API, that is very helpful shortcut usage to
use new nova side features, this patch implement it.
Change-Id: I87918addff1f50fbc6eb72ca82b31813330753b5
Closes-Bug: #1561838
Diffstat (limited to 'openstackclient/compute/client.py')
| -rw-r--r-- | openstackclient/compute/client.py | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/openstackclient/compute/client.py b/openstackclient/compute/client.py index 1481ed65..82f09cec 100644 --- a/openstackclient/compute/client.py +++ b/openstackclient/compute/client.py @@ -41,8 +41,18 @@ def make_client(instance): version = _compute_api_version else: version = instance._api_version[API_NAME] + from novaclient import api_versions + # convert to APIVersion object + version = api_versions.get_api_version(version) + + if version.is_latest(): + import novaclient + # NOTE(RuiChen): executing version discovery make sense, but that need + # an initialized REST client, it's not available now, + # fallback to use the max version of novaclient side. + version = novaclient.API_MAX_VERSION - LOG.debug('Instantiating compute client for V%s', version) + LOG.debug('Instantiating compute client for %s', version) # Set client http_log_debug to True if verbosity level is high enough http_log_debug = utils.get_effective_log_level() <= logging.DEBUG @@ -91,30 +101,27 @@ def check_api_version(check_version): """ # Defer client imports until we actually need them - try: - from novaclient import api_versions - except ImportError: - # Retain previous behaviour - return False - import novaclient + from novaclient import api_versions global _compute_api_version - # Copy some logic from novaclient 2.27.0 for basic version detection + # Copy some logic from novaclient 3.3.0 for basic version detection # NOTE(dtroyer): This is only enough to resume operations using API # version 2.0 or any valid version supplied by the user. _compute_api_version = api_versions.get_api_version(check_version) - if _compute_api_version > api_versions.APIVersion("2.0"): - if not _compute_api_version.matches( - novaclient.API_MIN_VERSION, - novaclient.API_MAX_VERSION, - ): - raise exceptions.CommandError( - "versions supported by client: %s - %s" % ( - novaclient.API_MIN_VERSION.get_string(), - novaclient.API_MAX_VERSION.get_string(), - ), - ) + # Bypass X.latest format microversion + if not _compute_api_version.is_latest(): + if _compute_api_version > api_versions.APIVersion("2.0"): + if not _compute_api_version.matches( + novaclient.API_MIN_VERSION, + novaclient.API_MAX_VERSION, + ): + raise exceptions.CommandError( + "versions supported by client: %s - %s" % ( + novaclient.API_MIN_VERSION.get_string(), + novaclient.API_MAX_VERSION.get_string(), + ), + ) return True |
