7from __future__
import absolute_import, division, print_function
10ANSIBLE_METADATA = {
'metadata_version':
'1.1',
11 'status': [
'preview'],
12 'supported_by':
'community'}
16module: mso_schema_template_bd_subnet
17short_description: Manage BD subnets in schema templates
19- Manage BD subnets in schema templates on Cisco ACI Multi-Site.
21- Dag Wieers (@dagwieers)
26 - The name of the schema.
31 - The name of the template to change.
36 - The name of the BD to manage.
41 - The IP range in CIDR notation.
47 - The description of this subnet.
51 - The scope of the subnet.
53 choices: [ private, public ]
56 - Whether this subnet
is shared between VRFs.
60 - Whether this subnet has a default gateway.
64 - Use C(present)
or C(absent)
for adding
or removing.
65 - Use C(query)
for listing an object
or multiple objects.
67 choices: [ absent, present, query ]
70- Due to restrictions of the MSO REST API concurrent modifications to BD subnets can be dangerous
and corrupt data.
71extends_documentation_fragment: mso
75- name: Add a new subnet to a BD
76 mso_schema_template_bd_subnet:
79 password: SomeSecretPassword
85 delegate_to: localhost
87- name: Remove a subset from a BD
88 mso_schema_template_bd_subnet:
91 password: SomeSecretPassword
97 delegate_to: localhost
99- name: Query a specific BD subnet
100 mso_schema_template_bd_subnet:
103 password: SomeSecretPassword
109 delegate_to: localhost
110 register: query_result
112- name: Query all BD subnets
113 mso_schema_template_bd_subnet:
116 password: SomeSecretPassword
121 delegate_to: localhost
122 register: query_result
128from ansible.module_utils.basic import AnsibleModule
129from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec, mso_reference_spec, mso_subnet_spec
134 argument_spec.update(
135 schema=dict(type=
'str', required=
True),
136 template=dict(type=
'str', required=
True),
137 bd=dict(type=
'str', required=
True),
138 state=dict(type=
'str', default=
'present', choices=[
'absent',
'present',
'query']),
143 argument_spec=argument_spec,
144 supports_check_mode=
True,
146 [
'state',
'absent', [
'subnet']],
147 [
'state',
'present', [
'subnet']],
151 schema = module.params[
'schema']
152 template = module.params[
'template']
153 bd = module.params[
'bd']
154 subnet = module.params[
'subnet']
155 description = module.params[
'description']
156 scope = module.params[
'scope']
157 shared = module.params[
'shared']
158 no_default_gateway = module.params[
'no_default_gateway']
159 state = module.params[
'state']
164 schema_obj = mso.get_obj(
'schemas', displayName=schema)
166 mso.fail_json(msg=
"Provided schema '{0}' does not exist".
format(schema))
168 schema_path =
'schemas/{id}'.
format(**schema_obj)
171 templates = [t[
'name']
for t
in schema_obj[
'templates']]
172 if template
not in templates:
173 mso.fail_json(msg=
"Provided template '{0}' does not exist. Existing templates: {1}".
format(template,
', '.join(templates)))
174 template_idx = templates.index(template)
177 bds = [b[
'name']
for b
in schema_obj[
'templates'][template_idx][
'bds']]
179 mso.fail_json(msg=
"Provided BD '{0}' does not exist. Existing BDs: {1}".
format(bd,
', '.join(bds)))
180 bd_idx = bds.index(bd)
183 subnets = [s[
'ip']
for s
in schema_obj[
'templates'][template_idx][
'bds'][bd_idx][
'subnets']]
184 if subnet
in subnets:
185 subnet_idx = subnets.index(subnet)
187 subnet_path =
'/templates/{0}/bds/{1}/subnets/{2}'.
format(template, bd, subnet_idx)
188 mso.existing = schema_obj[
'templates'][template_idx][
'bds'][bd_idx][
'subnets'][subnet_idx]
192 mso.existing = schema_obj[
'templates'][template_idx][
'bds'][bd_idx][
'subnets']
193 elif not mso.existing:
194 mso.fail_json(msg=
"Subnet IP '{subnet}' not found".
format(subnet=subnet))
197 subnets_path =
'/templates/{0}/bds/{1}/subnets'.
format(template, bd)
200 mso.previous = mso.existing
201 if state ==
'absent':
203 mso.sent = mso.existing = {}
204 ops.append(dict(op=
'remove', path=subnet_path))
206 elif state ==
'present':
208 if description
is None:
214 if no_default_gateway
is None:
215 no_default_gateway =
False
219 description=description,
222 noDefaultGateway=no_default_gateway,
225 mso.sanitize(payload, collate=
True)
228 ops.append(dict(op=
'replace', path=subnet_path, value=mso.sent))
230 ops.append(dict(op=
'add', path=subnets_path +
'/-', value=mso.sent))
232 mso.existing = mso.proposed
234 if not module.check_mode:
235 mso.request(schema_path, method=
'PATCH', data=ops)
240if __name__ ==
"__main__":