Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mso_st_bd_subnet: Fix various issues #53240

Merged
merged 1 commit into from
Mar 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 25 additions & 23 deletions lib/ansible/modules/network/aci/mso_schema_template_bd_subnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@
- The name of the BD to manage.
type: str
required: yes
ip:
subnet:
description:
- The IP range in CIDR notation.
type: str
required: true
aliases: [ ip ]
description:
description:
- The description of this subnet.
Expand Down Expand Up @@ -79,7 +80,7 @@
schema: Schema 1
template: Template 1
bd: BD 1
ip: 10.0.0.0/24
subnet: 10.0.0.0/24
state: present
delegate_to: localhost

Expand All @@ -91,7 +92,7 @@
schema: Schema 1
template: Template 1
bd: BD 1
ip: 10.0.0.0/24
subnet: 10.0.0.0/24
state: absent
delegate_to: localhost

Expand All @@ -103,7 +104,7 @@
schema: Schema 1
template: Template 1
bd: BD 1
ip: 10.0.0.0/24
subnet: 10.0.0.0/24
state: query
delegate_to: localhost
register: query_result
Expand Down Expand Up @@ -142,15 +143,15 @@ def main():
argument_spec=argument_spec,
supports_check_mode=True,
required_if=[
['state', 'absent', ['ip']],
['state', 'present', ['ip']],
['state', 'absent', ['subnet']],
['state', 'present', ['subnet']],
],
)

schema = module.params['schema']
template = module.params['template']
bd = module.params['bd']
ip = module.params['ip']
subnet = module.params['subnet']
description = module.params['description']
scope = module.params['scope']
shared = module.params['shared']
Expand All @@ -172,25 +173,25 @@ def main():
mso.fail_json(msg="Provided template '{0}' does not exist. Existing templates: {1}".format(template, ', '.join(templates)))
template_idx = templates.index(template)

# Get EPG
# Get BD
bds = [b['name'] for b in schema_obj['templates'][template_idx]['bds']]
if bd not in bds:
mso.fail_json(msg="Provided BD '{0}' does not exist. Existing BDs: {1}".format(bd, ', '.join(bds)))
bd_idx = bds.index(bd)

# Get Subnet
subnets = [s['ip'] for s in schema_obj['templates'][template_idx]['bds'][bd_idx]['subnets']]
if ip in subnets:
ip_idx = subnets.index(ip)
if subnet in subnets:
subnet_idx = subnets.index(subnet)
# FIXME: Changes based on index are DANGEROUS
subnet_path = '/templates/{0}/bds/{1}/subnets/{2}'.format(template, bd, ip_idx)
mso.existing = schema_obj['templates'][template_idx]['bds'][bd_idx]['subnets'][ip_idx]
subnet_path = '/templates/{0}/bds/{1}/subnets/{2}'.format(template, bd, subnet_idx)
mso.existing = schema_obj['templates'][template_idx]['bds'][bd_idx]['subnets'][subnet_idx]

if state == 'query':
if ip is None:
if subnet is None:
mso.existing = schema_obj['templates'][template_idx]['bds'][bd_idx]['subnets']
elif not mso.existing:
mso.fail_json(msg="Subnet '{ip}' not found".format(ip=ip))
mso.fail_json(msg="Subnet IP '{subnet}' not found".format(subnet=subnet))
mso.exit_json()

subnets_path = '/templates/{0}/bds/{1}/subnets'.format(template, bd)
Expand All @@ -203,17 +204,18 @@ def main():
ops.append(dict(op='remove', path=subnet_path))

elif state == 'present':
if description is None and not mso.existing:
description = ip
if scope is None and not mso.existing:
scope = 'private'
if shared is None and not mso.existing:
shared = False
if no_default_gateway is None and not mso.existing:
no_default_gateway = False
if not mso.existing:
if description is None:
description = subnet
if scope is None:
scope = 'private'
if shared is None:
shared = False
if no_default_gateway is None:
no_default_gateway = False

payload = dict(
ip=ip,
ip=subnet,
description=description,
scope=scope,
shared=shared,
Expand Down