summaryrefslogtreecommitdiff
path: root/openstackclient/volume/client.py
diff options
context:
space:
mode:
authorStephen Finucane <sfinucan@redhat.com>2021-05-24 20:37:33 +0100
committerJesse Pretorius <jesse@odyssey4.me>2023-01-11 17:45:09 +0000
commite1872e01bfcb2edc5cbd6e6f44a1cfa6443dea18 (patch)
tree6559b84b02c15ef729f9d5a32d59ac5bff3554fe /openstackclient/volume/client.py
parent92dafb3a19d19db87c81471a4a931b41d19e2c5a (diff)
downloadpython-openstackclient-e1872e01bfcb2edc5cbd6e6f44a1cfa6443dea18.tar.gz
volume: Allow more versions
Copy the API version checks from the 'openstackclient.compute.client' module. These will only be necessary until we migrate everything to SDK but it's very helpful until then. Change-Id: I2d9c68db5bf891ffa25fd5a7fc9e8953e44b73ab Signed-off-by: Stephen Finucane <sfinucan@redhat.com> (cherry picked from commit 0f28588e48c1e296f834e8684f293c2cdf4afc33)
Diffstat (limited to 'openstackclient/volume/client.py')
-rw-r--r--openstackclient/volume/client.py55
1 files changed, 50 insertions, 5 deletions
diff --git a/openstackclient/volume/client.py b/openstackclient/volume/client.py
index 64e8b9f3..f63d2ad5 100644
--- a/openstackclient/volume/client.py
+++ b/openstackclient/volume/client.py
@@ -15,6 +15,7 @@
import logging
+from osc_lib import exceptions
from osc_lib import utils
from openstackclient.i18n import _
@@ -29,9 +30,11 @@ API_VERSIONS = {
"1": "cinderclient.v1.client.Client",
"2": "cinderclient.v2.client.Client",
"3": "cinderclient.v3.client.Client",
- "3.42": "cinderclient.v3.client.Client",
}
+# Save the microversion if in use
+_volume_api_version = None
+
def make_client(instance):
"""Returns a volume service client."""
@@ -48,10 +51,13 @@ def make_client(instance):
except Exception:
del API_VERSIONS['1']
- version = instance._api_version[API_NAME]
- from cinderclient import api_versions
- # convert to APIVersion object
- version = api_versions.get_api_version(version)
+ if _volume_api_version is not None:
+ version = _volume_api_version
+ else:
+ version = instance._api_version[API_NAME]
+ from cinderclient import api_versions
+ # convert to APIVersion object
+ version = api_versions.get_api_version(version)
if version.ver_major == '1':
# Monkey patch for v1 cinderclient
@@ -99,3 +105,42 @@ def build_option_parser(parser):
'(Env: OS_VOLUME_API_VERSION)') % DEFAULT_API_VERSION
)
return parser
+
+
+def check_api_version(check_version):
+ """Validate version supplied by user
+
+ Returns:
+
+ * True if version is OK
+ * False if the version has not been checked and the previous plugin
+ check should be performed
+ * throws an exception if the version is no good
+ """
+
+ # Defer client imports until we actually need them
+ from cinderclient import api_versions
+
+ global _volume_api_version
+
+ # Copy some logic from novaclient 3.3.0 for basic version detection
+ # NOTE(dtroyer): This is only enough to resume operations using API
+ # version 3.0 or any valid version supplied by the user.
+ _volume_api_version = api_versions.get_api_version(check_version)
+
+ # Bypass X.latest format microversion
+ if not _volume_api_version.is_latest():
+ if _volume_api_version > api_versions.APIVersion("3.0"):
+ if not _volume_api_version.matches(
+ api_versions.MIN_VERSION,
+ api_versions.MAX_VERSION,
+ ):
+ msg = _("versions supported by client: %(min)s - %(max)s") % {
+ "min": api_versions.MIN_VERSION,
+ "max": api_versions.MAX_VERSION,
+ }
+ raise exceptions.CommandError(msg)
+
+ return True
+
+ return False