From a5a343a5a86658246cc136a330eee951e32c7b56 Mon Sep 17 00:00:00 2001 From: Rui Chen Date: Fri, 25 Mar 2016 14:51:06 +0800 Subject: [PATCH] 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 --- openstackclient/compute/client.py | 45 +++++++++++-------- .../notes/bug-1561838-3a006a8263d7536d.yaml | 6 +++ 2 files changed, 32 insertions(+), 19 deletions(-) create mode 100644 releasenotes/notes/bug-1561838-3a006a8263d7536d.yaml diff --git a/openstackclient/compute/client.py b/openstackclient/compute/client.py index 1481ed6535..82f09cec0f 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) - LOG.debug('Instantiating compute client for V%s', 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 %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 diff --git a/releasenotes/notes/bug-1561838-3a006a8263d7536d.yaml b/releasenotes/notes/bug-1561838-3a006a8263d7536d.yaml new file mode 100644 index 0000000000..71e5ba26c5 --- /dev/null +++ b/releasenotes/notes/bug-1561838-3a006a8263d7536d.yaml @@ -0,0 +1,6 @@ +--- +features: + - Support X.latest format for OS_COMPUTE_API_VERSION in order to talk with + the latest nova microversion API, that is very helpful shortcut usage to + use new nova side features. + [Bug `1561838 `_]