Skip to content

Commit f873428

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "volume: Allow more versions"
2 parents 89f6d7b + 0f28588 commit f873428

1 file changed

Lines changed: 50 additions & 5 deletions

File tree

openstackclient/volume/client.py

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import logging
1717

18+
from osc_lib import exceptions
1819
from osc_lib import utils
1920

2021
from openstackclient.i18n import _
@@ -29,9 +30,11 @@
2930
"1": "cinderclient.v1.client.Client",
3031
"2": "cinderclient.v2.client.Client",
3132
"3": "cinderclient.v3.client.Client",
32-
"3.42": "cinderclient.v3.client.Client",
3333
}
3434

35+
# Save the microversion if in use
36+
_volume_api_version = None
37+
3538

3639
def make_client(instance):
3740
"""Returns a volume service client."""
@@ -52,10 +55,13 @@ def make_client(instance):
5255
except Exception:
5356
del API_VERSIONS['2']
5457

55-
version = instance._api_version[API_NAME]
56-
from cinderclient import api_versions
57-
# convert to APIVersion object
58-
version = api_versions.get_api_version(version)
58+
if _volume_api_version is not None:
59+
version = _volume_api_version
60+
else:
61+
version = instance._api_version[API_NAME]
62+
from cinderclient import api_versions
63+
# convert to APIVersion object
64+
version = api_versions.get_api_version(version)
5965

6066
if version.ver_major == '1':
6167
# Monkey patch for v1 cinderclient
@@ -103,3 +109,42 @@ def build_option_parser(parser):
103109
'(Env: OS_VOLUME_API_VERSION)') % DEFAULT_API_VERSION
104110
)
105111
return parser
112+
113+
114+
def check_api_version(check_version):
115+
"""Validate version supplied by user
116+
117+
Returns:
118+
119+
* True if version is OK
120+
* False if the version has not been checked and the previous plugin
121+
check should be performed
122+
* throws an exception if the version is no good
123+
"""
124+
125+
# Defer client imports until we actually need them
126+
from cinderclient import api_versions
127+
128+
global _volume_api_version
129+
130+
# Copy some logic from novaclient 3.3.0 for basic version detection
131+
# NOTE(dtroyer): This is only enough to resume operations using API
132+
# version 3.0 or any valid version supplied by the user.
133+
_volume_api_version = api_versions.get_api_version(check_version)
134+
135+
# Bypass X.latest format microversion
136+
if not _volume_api_version.is_latest():
137+
if _volume_api_version > api_versions.APIVersion("3.0"):
138+
if not _volume_api_version.matches(
139+
api_versions.MIN_VERSION,
140+
api_versions.MAX_VERSION,
141+
):
142+
msg = _("versions supported by client: %(min)s - %(max)s") % {
143+
"min": api_versions.MIN_VERSION,
144+
"max": api_versions.MAX_VERSION,
145+
}
146+
raise exceptions.CommandError(msg)
147+
148+
return True
149+
150+
return False

0 commit comments

Comments
 (0)