7from __future__
import absolute_import, division, print_function
10ANSIBLE_METADATA = {
'metadata_version':
'1.1',
11 'status': [
'preview'],
12 'supported_by':
'community'}
16module: mso_schema_site_bd_subnet
17short_description: Manage site-local BD subnets in schema template
19- Manage site-local BD subnets in schema template on Cisco ACI Multi-Site.
21- Dag Wieers (@dagwieers)
26 - The name of the schema.
31 - The name of the site.
36 - The name of the template.
46 - The IP range in CIDR notation.
52 - The description of this subnet.
56 - The scope of the subnet.
58 choices: [ private, public ]
61 - Whether this subnet
is shared between VRFs.
65 - Whether this subnet has a default gateway.
69 - Use C(present)
or C(absent)
for adding
or removing.
70 - Use C(query)
for listing an object
or multiple objects.
72 choices: [ absent, present, query ]
75- The ACI MultiSite PATCH API has a deficiency requiring some objects to be referenced by index.
76 This can cause silent corruption on concurrent access when changing/removing on object
as
77 the wrong object may be referenced. This module
is affected by this deficiency.
79- module: mso_schema_site_bd
80- module: mso_schema_template_bd
81extends_documentation_fragment: mso
85- name: Add a new site BD subnet
86 mso_schema_site_bd_subnet:
89 password: SomeSecretPassword
96 delegate_to: localhost
98- name: Remove a site BD subnet
99 mso_schema_site_bd_subnet:
102 password: SomeSecretPassword
107 subnet: 11.11.11.0/24
109 delegate_to: localhost
111- name: Query a specific site BD subnet
112 mso_schema_site_bd_subnet:
115 password: SomeSecretPassword
120 subnet: 11.11.11.0/24
122 delegate_to: localhost
123 register: query_result
125- name: Query all site BD subnets
126 mso_schema_site_bd_subnet:
129 password: SomeSecretPassword
135 delegate_to: localhost
136 register: query_result
142from ansible.module_utils.basic import AnsibleModule
143from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec, mso_subnet_spec
148 argument_spec.update(
149 schema=dict(type=
'str', required=
True),
150 site=dict(type=
'str', required=
True),
151 template=dict(type=
'str', required=
True),
152 bd=dict(type=
'str', aliases=[
'name']),
153 state=dict(type=
'str', default=
'present', choices=[
'absent',
'present',
'query']),
158 argument_spec=argument_spec,
159 supports_check_mode=
True,
161 [
'state',
'absent', [
'bd']],
162 [
'state',
'present', [
'bd']],
166 schema = module.params[
'schema']
167 site = module.params[
'site']
168 template = module.params[
'template']
169 bd = module.params[
'bd']
170 subnet = module.params[
'subnet']
171 description = module.params[
'description']
172 scope = module.params[
'scope']
173 shared = module.params[
'shared']
174 no_default_gateway = module.params[
'no_default_gateway']
175 state = module.params[
'state']
180 schema_obj = mso.get_obj(
'schemas', displayName=schema)
182 mso.fail_json(msg=
"Provided schema '{0}' does not exist".
format(schema))
184 schema_path =
'schemas/{id}'.
format(**schema_obj)
185 schema_id = schema_obj[
'id']
188 site_id = mso.lookup_site(site)
191 sites = [(s[
'siteId'], s[
'templateName'])
for s
in schema_obj[
'sites']]
192 if (site_id, template)
not in sites:
193 mso.fail_json(msg=
"Provided site/template '{0}-{1}' does not exist. Existing sites/templates: {2}".
format(site, template,
', '.join(sites)))
196 site_idx = sites.index((site_id, template))
198 site_template =
'{0}-{1}'.
format(site_id, template)
201 bd_ref = mso.bd_ref(schema_id=schema_id, template=template, bd=bd)
202 bds = [v[
'bdRef']
for v
in schema_obj[
'sites'][site_idx][
'bds']]
203 if bd_ref
not in bds:
204 mso.fail_json(msg=
"Provided BD '{0}' does not exist. Existing BDs: {1}".
format(bd,
', '.join(bds)))
205 bd_idx = bds.index(bd_ref)
208 subnets = [s[
'ip']
for s
in schema_obj[
'sites'][site_idx][
'bds'][bd_idx][
'subnets']]
209 if subnet
in subnets:
210 subnet_idx = subnets.index(subnet)
212 subnet_path =
'/sites/{0}/bds/{1}/subnets/{2}'.
format(site_template, bd, subnet_idx)
213 mso.existing = schema_obj[
'sites'][site_idx][
'bds'][bd_idx][
'subnets'][subnet_idx]
217 mso.existing = schema_obj[
'sites'][site_idx][
'bds'][bd_idx][
'subnets']
218 elif not mso.existing:
219 mso.fail_json(msg=
"Subnet IP '{subnet}' not found".
format(subnet=subnet))
222 subnets_path =
'/sites/{0}/bds/{1}/subnets'.
format(site_template, bd)
225 mso.previous = mso.existing
226 if state ==
'absent':
228 mso.sent = mso.existing = {}
229 ops.append(dict(op=
'remove', path=subnet_path))
231 elif state ==
'present':
233 if description
is None:
239 if no_default_gateway
is None:
240 no_default_gateway =
False
244 description=description,
247 noDefaultGateway=no_default_gateway,
250 mso.sanitize(payload, collate=
True)
253 ops.append(dict(op=
'replace', path=subnet_path, value=mso.sent))
255 ops.append(dict(op=
'add', path=subnets_path +
'/-', value=mso.sent))
257 mso.existing = mso.proposed
259 if not module.check_mode:
260 mso.request(schema_path, method=
'PATCH', data=ops)
265if __name__ ==
"__main__":