mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
mso_stae_subnet: Fix various issues (#53239)
This PR includes: - Rename 'ip' to 'subnet' as that's what we're managing - Use the correct module name in the examples - Small improvement in logic
This commit is contained in:
parent
85eb8c30a6
commit
12a949229d
1 changed files with 31 additions and 29 deletions
|
@ -41,11 +41,12 @@ options:
|
||||||
- The name of the EPG to manage.
|
- The name of the EPG to manage.
|
||||||
type: str
|
type: str
|
||||||
required: yes
|
required: yes
|
||||||
ip:
|
subnet:
|
||||||
description:
|
description:
|
||||||
- The IP range in CIDR notation.
|
- The IP range in CIDR notation.
|
||||||
type: str
|
type: str
|
||||||
required: true
|
required: true
|
||||||
|
aliases: [ ip ]
|
||||||
description:
|
description:
|
||||||
description:
|
description:
|
||||||
- The description of this subnet.
|
- The description of this subnet.
|
||||||
|
@ -77,7 +78,7 @@ extends_documentation_fragment: mso
|
||||||
|
|
||||||
EXAMPLES = r'''
|
EXAMPLES = r'''
|
||||||
- name: Add a new subnet to an EPG
|
- name: Add a new subnet to an EPG
|
||||||
mso_schema_template_anp_subnet:
|
mso_schema_template_anp_epg_subnet:
|
||||||
host: mso_host
|
host: mso_host
|
||||||
username: admin
|
username: admin
|
||||||
password: SomeSecretPassword
|
password: SomeSecretPassword
|
||||||
|
@ -85,12 +86,12 @@ EXAMPLES = r'''
|
||||||
template: Template 1
|
template: Template 1
|
||||||
anp: ANP 1
|
anp: ANP 1
|
||||||
epg: EPG 1
|
epg: EPG 1
|
||||||
ip: 10.0.0.0/24
|
subnet: 10.0.0.0/24
|
||||||
state: present
|
state: present
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: Remove an EPG
|
- name: Remove a subnet from an EPG
|
||||||
mso_schema_template_anp_epg:
|
mso_schema_template_anp_epg_subnet:
|
||||||
host: mso_host
|
host: mso_host
|
||||||
username: admin
|
username: admin
|
||||||
password: SomeSecretPassword
|
password: SomeSecretPassword
|
||||||
|
@ -98,12 +99,12 @@ EXAMPLES = r'''
|
||||||
template: Template 1
|
template: Template 1
|
||||||
anp: ANP 1
|
anp: ANP 1
|
||||||
epg: EPG 1
|
epg: EPG 1
|
||||||
ip: 10.0.0.0/24
|
subnet: 10.0.0.0/24
|
||||||
state: absent
|
state: absent
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
|
|
||||||
- name: Query a specific EPG
|
- name: Query a specific EPG subnet
|
||||||
mso_schema_template_anp_epg:
|
mso_schema_template_anp_epg_subnet:
|
||||||
host: mso_host
|
host: mso_host
|
||||||
username: admin
|
username: admin
|
||||||
password: SomeSecretPassword
|
password: SomeSecretPassword
|
||||||
|
@ -111,13 +112,13 @@ EXAMPLES = r'''
|
||||||
template: Template 1
|
template: Template 1
|
||||||
anp: ANP 1
|
anp: ANP 1
|
||||||
epg: EPG 1
|
epg: EPG 1
|
||||||
ip: 10.0.0.0/24
|
subnet: 10.0.0.0/24
|
||||||
state: query
|
state: query
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
register: query_result
|
register: query_result
|
||||||
|
|
||||||
- name: Query all EPGs
|
- name: Query all EPGs subnets
|
||||||
mso_schema_template_anp_epg:
|
mso_schema_template_anp_epg_subnet:
|
||||||
host: mso_host
|
host: mso_host
|
||||||
username: admin
|
username: admin
|
||||||
password: SomeSecretPassword
|
password: SomeSecretPassword
|
||||||
|
@ -151,8 +152,8 @@ def main():
|
||||||
argument_spec=argument_spec,
|
argument_spec=argument_spec,
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
required_if=[
|
required_if=[
|
||||||
['state', 'absent', ['ip']],
|
['state', 'absent', ['subnet']],
|
||||||
['state', 'present', ['ip']],
|
['state', 'present', ['subnet']],
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -160,7 +161,7 @@ def main():
|
||||||
template = module.params['template']
|
template = module.params['template']
|
||||||
anp = module.params['anp']
|
anp = module.params['anp']
|
||||||
epg = module.params['epg']
|
epg = module.params['epg']
|
||||||
ip = module.params['ip']
|
subnet = module.params['subnet']
|
||||||
description = module.params['description']
|
description = module.params['description']
|
||||||
scope = module.params['scope']
|
scope = module.params['scope']
|
||||||
shared = module.params['shared']
|
shared = module.params['shared']
|
||||||
|
@ -197,17 +198,17 @@ def main():
|
||||||
|
|
||||||
# Get Subnet
|
# Get Subnet
|
||||||
subnets = [s['ip'] for s in schema_obj['templates'][template_idx]['anps'][anp_idx]['epgs'][epg_idx]['subnets']]
|
subnets = [s['ip'] for s in schema_obj['templates'][template_idx]['anps'][anp_idx]['epgs'][epg_idx]['subnets']]
|
||||||
if ip in subnets:
|
if subnet in subnets:
|
||||||
ip_idx = subnets.index(ip)
|
subnet_idx = subnets.index(subnet)
|
||||||
# FIXME: Changes based on index are DANGEROUS
|
# FIXME: Changes based on index are DANGEROUS
|
||||||
subnet_path = '/templates/{0}/anps/{1}/epgs/{2}/subnets/{3}'.format(template, anp, epg, ip_idx)
|
subnet_path = '/templates/{0}/anps/{1}/epgs/{2}/subnets/{3}'.format(template, anp, epg, subnet_idx)
|
||||||
mso.existing = schema_obj['templates'][template_idx]['anps'][anp_idx]['epgs'][epg_idx]['subnets'][ip_idx]
|
mso.existing = schema_obj['templates'][template_idx]['anps'][anp_idx]['epgs'][epg_idx]['subnets'][subnet_idx]
|
||||||
|
|
||||||
if state == 'query':
|
if state == 'query':
|
||||||
if ip is None:
|
if subnet is None:
|
||||||
mso.existing = schema_obj['templates'][template_idx]['anps'][anp_idx]['epgs'][epg_idx]['subnets']
|
mso.existing = schema_obj['templates'][template_idx]['anps'][anp_idx]['epgs'][epg_idx]['subnets']
|
||||||
elif not mso.existing:
|
elif not mso.existing:
|
||||||
mso.fail_json(msg="Subnet '{ip}' not found".format(ip=ip))
|
mso.fail_json(msg="Subnet '{subnet}' not found".format(subnet=subnet))
|
||||||
mso.exit_json()
|
mso.exit_json()
|
||||||
|
|
||||||
subnets_path = '/templates/{0}/anps/{1}/epgs/{2}/subnets'.format(template, anp, epg)
|
subnets_path = '/templates/{0}/anps/{1}/epgs/{2}/subnets'.format(template, anp, epg)
|
||||||
|
@ -220,17 +221,18 @@ def main():
|
||||||
ops.append(dict(op='remove', path=subnet_path))
|
ops.append(dict(op='remove', path=subnet_path))
|
||||||
|
|
||||||
elif state == 'present':
|
elif state == 'present':
|
||||||
if description is None and not mso.existing:
|
if not mso.existing:
|
||||||
description = ip
|
if description is None:
|
||||||
if scope is None and not mso.existing:
|
description = subnet
|
||||||
scope = 'private'
|
if scope is None:
|
||||||
if shared is None and not mso.existing:
|
scope = 'private'
|
||||||
shared = False
|
if shared is None:
|
||||||
if no_default_gateway is None and not mso.existing:
|
shared = False
|
||||||
no_default_gateway = False
|
if no_default_gateway is None:
|
||||||
|
no_default_gateway = False
|
||||||
|
|
||||||
payload = dict(
|
payload = dict(
|
||||||
ip=ip,
|
ip=subnet,
|
||||||
description=description,
|
description=description,
|
||||||
scope=scope,
|
scope=scope,
|
||||||
shared=shared,
|
shared=shared,
|
||||||
|
|
Loading…
Reference in a new issue