[backport 2.8] Bump min openstacksdk version for os_network/port_security_enabled
To make use of the port_security_enabled [a] parameter, [b] needs to be present in the openstacksdk or the os_network module will return an error like: TypeError: create_network() got an unexpected keyword argument 'port_security_enabled' To handle this, we fail the module if one of the arguments are used and the minimum openstacksdk version for that argument is not met. [a]eaf238b033[b]8eb788af07Backport-of: https://review.opendev.org/708119 Fixes: #62062
This commit is contained in:
committed by
Matt Clay
parent
b4614c949e
commit
e9a190e9c1
@ -0,0 +1,3 @@
|
||||
bugfixes:
|
||||
- Bump the minimum openstacksdk version to 0.18.0 when os_network
|
||||
uses the port_security_enabled argument.
|
||||
@ -117,6 +117,11 @@ def openstack_cloud_from_module(module, min_version='0.12.0'):
|
||||
except ImportError:
|
||||
module.fail_json(msg='openstacksdk is required for this module')
|
||||
|
||||
if min_version:
|
||||
min_version = max(StrictVersion('0.12.0'), StrictVersion(min_version))
|
||||
else:
|
||||
min_version = StrictVersion('0.12.0')
|
||||
|
||||
if min_version:
|
||||
if StrictVersion(sdk.version.__version__) < StrictVersion(min_version):
|
||||
module.fail_json(
|
||||
|
||||
@ -73,7 +73,7 @@ options:
|
||||
description:
|
||||
- Whether port security is enabled on the network or not.
|
||||
Network will use OpenStack defaults if this option is
|
||||
not utilised.
|
||||
not utilised. Requires openstacksdk>=0.18.
|
||||
type: bool
|
||||
version_added: "2.8"
|
||||
requirements:
|
||||
@ -179,9 +179,15 @@ def main():
|
||||
provider_network_type = module.params['provider_network_type']
|
||||
provider_segmentation_id = module.params['provider_segmentation_id']
|
||||
project = module.params.get('project')
|
||||
port_security_enabled = module.params.get('port_security_enabled')
|
||||
|
||||
sdk, cloud = openstack_cloud_from_module(module)
|
||||
net_create_kwargs = {}
|
||||
min_version = None
|
||||
|
||||
if module.params['port_security_enabled'] is not None:
|
||||
min_version = '0.18.0'
|
||||
net_create_kwargs['port_security_enabled'] = module.params['port_security_enabled']
|
||||
|
||||
sdk, cloud = openstack_cloud_from_module(module, min_version)
|
||||
try:
|
||||
if project is not None:
|
||||
proj = cloud.get_project(project)
|
||||
@ -207,11 +213,11 @@ def main():
|
||||
if project_id is not None:
|
||||
net = cloud.create_network(name, shared, admin_state_up,
|
||||
external, provider, project_id,
|
||||
port_security_enabled=port_security_enabled)
|
||||
**net_create_kwargs)
|
||||
else:
|
||||
net = cloud.create_network(name, shared, admin_state_up,
|
||||
external, provider,
|
||||
port_security_enabled=port_security_enabled)
|
||||
**net_create_kwargs)
|
||||
changed = True
|
||||
else:
|
||||
changed = False
|
||||
|
||||
Reference in New Issue
Block a user