Do not enforce optional params in network module

It is wrong to enforce values of optional networking parameters. In the
clouds where those optional extensions are not installed this leads to
failures. Instead only pass params down to SDK if user explicitly set
them.

Change-Id: I5660eb8a4a65dd365ae7ce8c09825bbed8d2fdde
This commit is contained in:
Artem Goncharov 2022-10-18 16:51:03 +02:00
parent 7bad5cfd42
commit f51898bd2f

View File

@ -22,17 +22,14 @@ options:
description: description:
- Whether this network is shared or not. - Whether this network is shared or not.
type: bool type: bool
default: 'no'
admin_state_up: admin_state_up:
description: description:
- Whether the state should be marked as up or down. - Whether the state should be marked as up or down.
type: bool type: bool
default: 'yes'
external: external:
description: description:
- Whether this network is externally accessible. - Whether this network is externally accessible.
type: bool type: bool
default: 'no'
state: state:
description: description:
- Indicate desired state of the resource. - Indicate desired state of the resource.
@ -194,9 +191,9 @@ class NetworkModule(OpenStackModule):
argument_spec = dict( argument_spec = dict(
name=dict(required=True), name=dict(required=True),
shared=dict(default=False, type='bool'), shared=dict(type='bool'),
admin_state_up=dict(default=True, type='bool'), admin_state_up=dict(type='bool'),
external=dict(default=False, type='bool'), external=dict(type='bool'),
provider_physical_network=dict(), provider_physical_network=dict(),
provider_network_type=dict(), provider_network_type=dict(),
provider_segmentation_id=dict(type='int'), provider_segmentation_id=dict(type='int'),
@ -245,8 +242,11 @@ class NetworkModule(OpenStackModule):
if project_id is not None: if project_id is not None:
kwargs['project_id'] = project_id kwargs['project_id'] = project_id
if shared is not None:
kwargs["shared"] = shared kwargs["shared"] = shared
if admin_state_up is not None:
kwargs["admin_state_up"] = admin_state_up kwargs["admin_state_up"] = admin_state_up
if external is not None:
kwargs["is_router_external"] = external kwargs["is_router_external"] = external
if not net: if not net:
@ -276,7 +276,13 @@ class NetworkModule(OpenStackModule):
for arg in ["shared", "admin_state_up", "is_router_external", for arg in ["shared", "admin_state_up", "is_router_external",
"mtu", "port_security_enabled", "dns_domain", "mtu", "port_security_enabled", "dns_domain",
"provider_segmentation_id"]: "provider_segmentation_id"]:
if arg in kwargs and kwargs[arg] != net[arg]: if (
arg in kwargs
# ensure user wants something specific
and kwargs[arg] is not None
# and this is not what we have right now
and kwargs[arg] != net[arg]
):
update_kwargs[arg] = kwargs[arg] update_kwargs[arg] = kwargs[arg]
if update_kwargs: if update_kwargs: