mirror of
https://opendev.org/openstack/ansible-collections-openstack.git
synced 2026-05-08 06:13:13 +00:00
OpenStackModule: Support defining a minimum version of the SDK
While it's currently possible to set min_ver and max_ver for specific parameter, there are times when the whole module needs to specify a minimum version: - When the object isn't supported at all prior to a version - When major features are missing from the SDK prior to a version Change-Id: I94bbff7c54621e8a4786ebc7eb030103255dcb17
This commit is contained in:
@@ -67,6 +67,8 @@ OVERRIDES = {'os_client_config': 'config',
|
|||||||
|
|
||||||
CUSTOM_VAR_PARAMS = ['min_ver', 'max_ver']
|
CUSTOM_VAR_PARAMS = ['min_ver', 'max_ver']
|
||||||
|
|
||||||
|
MINIMUM_SDK_VERSION = '0.12.0'
|
||||||
|
|
||||||
|
|
||||||
def openstack_argument_spec():
|
def openstack_argument_spec():
|
||||||
# DEPRECATED: This argument spec is only used for the deprecated old
|
# DEPRECATED: This argument spec is only used for the deprecated old
|
||||||
@@ -150,7 +152,7 @@ def openstack_module_kwargs(**kwargs):
|
|||||||
|
|
||||||
|
|
||||||
# for compatibility with old versions
|
# for compatibility with old versions
|
||||||
def openstack_cloud_from_module(module, min_version='0.12.0'):
|
def openstack_cloud_from_module(module, min_version=None):
|
||||||
try:
|
try:
|
||||||
# Due to the name shadowing we should import other way
|
# Due to the name shadowing we should import other way
|
||||||
sdk = importlib.import_module('openstack')
|
sdk = importlib.import_module('openstack')
|
||||||
@@ -159,9 +161,10 @@ def openstack_cloud_from_module(module, min_version='0.12.0'):
|
|||||||
module.fail_json(msg='openstacksdk is required for this module')
|
module.fail_json(msg='openstacksdk is required for this module')
|
||||||
|
|
||||||
if min_version:
|
if min_version:
|
||||||
min_version = max(StrictVersion('0.12.0'), StrictVersion(min_version))
|
min_version = max(StrictVersion(MINIMUM_SDK_VERSION),
|
||||||
|
StrictVersion(min_version))
|
||||||
else:
|
else:
|
||||||
min_version = StrictVersion('0.12.0')
|
min_version = StrictVersion(MINIMUM_SDK_VERSION)
|
||||||
|
|
||||||
if StrictVersion(sdk_version.__version__) < min_version:
|
if StrictVersion(sdk_version.__version__) < min_version:
|
||||||
module.fail_json(
|
module.fail_json(
|
||||||
@@ -240,6 +243,7 @@ class OpenStackModule:
|
|||||||
deprecated_names = ()
|
deprecated_names = ()
|
||||||
argument_spec = {}
|
argument_spec = {}
|
||||||
module_kwargs = {}
|
module_kwargs = {}
|
||||||
|
module_min_sdk_version = None
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Initialize Openstack base class.
|
"""Initialize Openstack base class.
|
||||||
@@ -300,6 +304,19 @@ class OpenStackModule:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
self.fail_json(msg='openstacksdk is required for this module')
|
self.fail_json(msg='openstacksdk is required for this module')
|
||||||
|
|
||||||
|
# Fail if the available SDK version doesn't meet the minimum version
|
||||||
|
# requirements
|
||||||
|
if self.module_min_sdk_version:
|
||||||
|
min_version = max(StrictVersion(MINIMUM_SDK_VERSION),
|
||||||
|
StrictVersion(self.module_min_sdk_version))
|
||||||
|
else:
|
||||||
|
min_version = StrictVersion(MINIMUM_SDK_VERSION)
|
||||||
|
if StrictVersion(self.sdk_version) < min_version:
|
||||||
|
self.fail(
|
||||||
|
msg="To utilize this module, the installed version of "
|
||||||
|
"the openstacksdk library MUST be >={min_version}.".format(
|
||||||
|
min_version=min_version))
|
||||||
|
|
||||||
# Fail if there are set unsupported for this version parameters
|
# Fail if there are set unsupported for this version parameters
|
||||||
# New parameters should NOT use 'default' but rely on SDK defaults
|
# New parameters should NOT use 'default' but rely on SDK defaults
|
||||||
for param in self.argument_spec:
|
for param in self.argument_spec:
|
||||||
|
|||||||
Reference in New Issue
Block a user