Add extra_specs to os_subnet module
PR #39373 * Add extra_specs to os_subnet module This change removes the parameter limitation on `os_subnet` module for Neutron subnet creation. This way, any key value passed via `extra_specs` argument is included in shade's API call. Signed-off-by: Mário Santos <mario.rf.santos@gmail.com> * Set default value of extra_specs to None Signed-off-by: Mário Santos <mario.rf.santos@gmail.com> * Raise ValueError in case of duplicate keys found Signed-off-by: Mário Santos <mario.rf.santos@gmail.com> * Update docs default value of extra_specs to {} * Move cidr to kwargs to avoid positional argument Signed-off-by: Mário Santos <mario.rf.santos@gmail.com> * Print explicit list of duplicate keys Signed-off-by: Mário Santos <mario.rf.santos@gmail.com> * Fix precedence on the dict merge Signed-off-by: Mário Santos <mario.rf.santos@gmail.com> * Bump version_added of the extra_specs parameter Signed-off-by: Mário Santos <mario.rf.santos@gmail.com>
This commit is contained in:
parent
4ae4e80cc3
commit
9d52e54ae6
1 changed files with 15 additions and 1 deletions
|
@ -95,6 +95,12 @@ options:
|
|||
availability_zone:
|
||||
description:
|
||||
- Ignored. Present for backwards compatibility
|
||||
extra_specs:
|
||||
description:
|
||||
- Dictionary with extra key/value pairs passed to the API
|
||||
required: false
|
||||
default: {}
|
||||
version_added: "2.7"
|
||||
requirements:
|
||||
- "python >= 2.6"
|
||||
- "openstacksdk"
|
||||
|
@ -231,6 +237,7 @@ def main():
|
|||
ipv6_ra_mode=dict(default=None, choice=ipv6_mode_choices),
|
||||
ipv6_address_mode=dict(default=None, choice=ipv6_mode_choices),
|
||||
use_default_subnetpool=dict(default=False, type='bool'),
|
||||
extra_specs=dict(required=False, default=dict(), type='dict'),
|
||||
state=dict(default='present', choices=['absent', 'present']),
|
||||
project=dict(default=None)
|
||||
)
|
||||
|
@ -256,6 +263,7 @@ def main():
|
|||
ipv6_a_mode = module.params['ipv6_address_mode']
|
||||
use_default_subnetpool = module.params['use_default_subnetpool']
|
||||
project = module.params.pop('project')
|
||||
extra_specs = module.params['extra_specs']
|
||||
|
||||
# Check for required parameters when state == 'present'
|
||||
if state == 'present':
|
||||
|
@ -296,6 +304,7 @@ def main():
|
|||
if state == 'present':
|
||||
if not subnet:
|
||||
kwargs = dict(
|
||||
cidr=cidr,
|
||||
ip_version=ip_version,
|
||||
enable_dhcp=enable_dhcp,
|
||||
subnet_name=subnet_name,
|
||||
|
@ -307,9 +316,14 @@ def main():
|
|||
ipv6_ra_mode=ipv6_ra_mode,
|
||||
ipv6_address_mode=ipv6_a_mode,
|
||||
tenant_id=project_id)
|
||||
dup_args = set(kwargs.keys()) & set(extra_specs.keys())
|
||||
if dup_args:
|
||||
raise ValueError('Duplicate key(s) {0} in extra_specs'
|
||||
.format(list(dup_args)))
|
||||
if use_default_subnetpool:
|
||||
kwargs['use_default_subnetpool'] = use_default_subnetpool
|
||||
subnet = cloud.create_subnet(network_name, cidr, **kwargs)
|
||||
kwargs = dict(kwargs, **extra_specs)
|
||||
subnet = cloud.create_subnet(network_name, **kwargs)
|
||||
changed = True
|
||||
else:
|
||||
if _needs_update(subnet, module, cloud):
|
||||
|
|
Loading…
Reference in a new issue