Skip to content

Commit a5a343a

Browse files
committed
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
1 parent 4639148 commit a5a343a

2 files changed

Lines changed: 32 additions & 19 deletions

File tree

openstackclient/compute/client.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,18 @@ def make_client(instance):
4141
version = _compute_api_version
4242
else:
4343
version = instance._api_version[API_NAME]
44+
from novaclient import api_versions
45+
# convert to APIVersion object
46+
version = api_versions.get_api_version(version)
47+
48+
if version.is_latest():
49+
import novaclient
50+
# NOTE(RuiChen): executing version discovery make sense, but that need
51+
# an initialized REST client, it's not available now,
52+
# fallback to use the max version of novaclient side.
53+
version = novaclient.API_MAX_VERSION
4454

45-
LOG.debug('Instantiating compute client for V%s', version)
55+
LOG.debug('Instantiating compute client for %s', version)
4656

4757
# Set client http_log_debug to True if verbosity level is high enough
4858
http_log_debug = utils.get_effective_log_level() <= logging.DEBUG
@@ -91,30 +101,27 @@ def check_api_version(check_version):
91101
"""
92102

93103
# Defer client imports until we actually need them
94-
try:
95-
from novaclient import api_versions
96-
except ImportError:
97-
# Retain previous behaviour
98-
return False
99-
100104
import novaclient
105+
from novaclient import api_versions
101106

102107
global _compute_api_version
103108

104-
# Copy some logic from novaclient 2.27.0 for basic version detection
109+
# Copy some logic from novaclient 3.3.0 for basic version detection
105110
# NOTE(dtroyer): This is only enough to resume operations using API
106111
# version 2.0 or any valid version supplied by the user.
107112
_compute_api_version = api_versions.get_api_version(check_version)
108113

109-
if _compute_api_version > api_versions.APIVersion("2.0"):
110-
if not _compute_api_version.matches(
111-
novaclient.API_MIN_VERSION,
112-
novaclient.API_MAX_VERSION,
113-
):
114-
raise exceptions.CommandError(
115-
"versions supported by client: %s - %s" % (
116-
novaclient.API_MIN_VERSION.get_string(),
117-
novaclient.API_MAX_VERSION.get_string(),
118-
),
119-
)
114+
# Bypass X.latest format microversion
115+
if not _compute_api_version.is_latest():
116+
if _compute_api_version > api_versions.APIVersion("2.0"):
117+
if not _compute_api_version.matches(
118+
novaclient.API_MIN_VERSION,
119+
novaclient.API_MAX_VERSION,
120+
):
121+
raise exceptions.CommandError(
122+
"versions supported by client: %s - %s" % (
123+
novaclient.API_MIN_VERSION.get_string(),
124+
novaclient.API_MAX_VERSION.get_string(),
125+
),
126+
)
120127
return True
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
features:
3+
- Support X.latest format for OS_COMPUTE_API_VERSION in order to talk with
4+
the latest nova microversion API, that is very helpful shortcut usage to
5+
use new nova side features.
6+
[Bug `1561838 <https://bugs.launchpad.net/python-openstackclient/+bug/1561838>`_]

0 commit comments

Comments
 (0)