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_vrf_region_cidr_subnet
17short_description: Manage site-local VRF regions in schema template
19- Manage site-local VRF regions 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.
41 - The name of the VRF.
45 - The name of the region.
49 - The IP range of for the region CIDR.
53 - The IP subnet of this region CIDR.
58 - The name of the zone
for the region CIDR subnet.
63 - Use C(present)
or C(absent)
for adding
or removing.
64 - Use C(query)
for listing an object
or multiple objects.
66 choices: [ absent, present, query ]
69- The ACI MultiSite PATCH API has a deficiency requiring some objects to be referenced by index.
70 This can cause silent corruption on concurrent access when changing/removing on object
as
71 the wrong object may be referenced. This module
is affected by this deficiency.
73- module: mso_schema_site_vrf_region_cidr
74- module: mso_schema_template_vrf
75extends_documentation_fragment: mso
79- name: Add a new site VRF region CIDR subnet
80 mso_schema_template_vrf_region_cidr_subnet:
83 password: SomeSecretPassword
93 delegate_to: localhost
95- name: Remove a site VRF region CIDR subnet
96 mso_schema_site_vrf_region_cidr_subnet:
99 password: SomeSecretPassword
106 subnet: 14.14.14.2/24
108 delegate_to: localhost
110- name: Query a specific site VRF region CIDR subnet
111 mso_schema_site_vrf_region_cidr_subnet:
114 password: SomeSecretPassword
121 subnet: 14.14.14.2/24
123 delegate_to: localhost
124 register: query_result
126- name: Query all site VRF region CIDR subnet
127 mso_schema_site_vrf_region_cidr_subnet:
130 password: SomeSecretPassword
138 delegate_to: localhost
139 register: query_result
145from ansible.module_utils.basic import AnsibleModule
146from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec
151 argument_spec.update(
152 schema=dict(type=
'str', required=
True),
153 site=dict(type=
'str', required=
True),
154 template=dict(type=
'str', required=
True),
155 vrf=dict(type=
'str', required=
True),
156 region=dict(type=
'str', required=
True),
157 cidr=dict(type=
'str', required=
True),
158 subnet=dict(type=
'str', aliases=[
'ip']),
159 zone=dict(type=
'str', aliases=[
'name']),
160 state=dict(type=
'str', default=
'present', choices=[
'absent',
'present',
'query']),
164 argument_spec=argument_spec,
165 supports_check_mode=
True,
167 [
'state',
'absent', [
'subnet']],
168 [
'state',
'present', [
'subnet',
'zone']],
172 schema = module.params[
'schema']
173 site = module.params[
'site']
174 template = module.params[
'template']
175 vrf = module.params[
'vrf']
176 region = module.params[
'region']
177 cidr = module.params[
'cidr']
178 subnet = module.params[
'subnet']
179 zone = module.params[
'zone']
180 state = module.params[
'state']
185 schema_obj = mso.get_obj(
'schemas', displayName=schema)
187 mso.fail_json(msg=
"Provided schema '{0}' does not exist".
format(schema))
189 schema_path =
'schemas/{id}'.
format(**schema_obj)
190 schema_id = schema_obj[
'id']
193 site_id = mso.lookup_site(site)
196 sites = [(s[
'siteId'], s[
'templateName'])
for s
in schema_obj[
'sites']]
197 if (site_id, template)
not in sites:
198 mso.fail_json(msg=
"Provided site/template '{0}-{1}' does not exist. Existing sites/templates: {2}".
format(site, template,
', '.join(sites)))
201 site_idx = sites.index((site_id, template))
203 site_template =
'{0}-{1}'.
format(site_id, template)
206 vrf_ref = mso.vrf_ref(schema_id=schema_id, template=template, vrf=vrf)
207 vrfs = [v[
'vrfRef']
for v
in schema_obj[
'sites'][site_idx][
'vrfs']]
208 if vrf_ref
not in vrfs:
209 mso.fail_json(msg=
"Provided vrf '{0}' does not exist. Existing vrfs: {1}".
format(vrf,
', '.join(vrfs)))
210 vrf_idx = vrfs.index(vrf_ref)
213 regions = [r[
'name']
for r
in schema_obj[
'sites'][site_idx][
'vrfs'][vrf_idx][
'regions']]
214 if region
not in regions:
215 mso.fail_json(msg=
"Provided region '{0}' does not exist. Existing regions: {1}".
format(region,
', '.join(regions)))
216 region_idx = regions.index(region)
219 cidrs = [c[
'ip']
for c
in schema_obj[
'sites'][site_idx][
'vrfs'][vrf_idx][
'regions'][region_idx][
'cidrs']]
220 if cidr
not in cidrs:
221 mso.fail_json(msg=
"Provided CIDR IP '{0}' does not exist. Existing CIDR IPs: {1}".
format(cidr,
', '.join(cidrs)))
222 cidr_idx = cidrs.index(cidr)
225 subnets = [s[
'ip']
for s
in schema_obj[
'sites'][site_idx][
'vrfs'][vrf_idx][
'regions'][region_idx][
'cidrs'][cidr_idx][
'subnets']]
226 if subnet
is not None and subnet
in subnets:
227 subnet_idx = subnets.index(subnet)
229 subnet_path =
'/sites/{0}/vrfs/{1}/regions/{2}/cidrs/{3}/subnets/{4}'.
format(site_template, vrf, region, cidr_idx, subnet_idx)
230 mso.existing = schema_obj[
'sites'][site_idx][
'vrfs'][vrf_idx][
'regions'][region_idx][
'cidrs'][cidr_idx][
'subnets'][subnet_idx]
234 mso.existing = schema_obj[
'sites'][site_idx][
'vrfs'][vrf_idx][
'regions'][region_idx][
'cidrs'][cidr_idx][
'subnets']
235 elif not mso.existing:
236 mso.fail_json(msg=
"Subnet IP '{subnet}' not found".
format(subnet=subnet))
239 subnets_path =
'/sites/{0}/vrfs/{1}/regions/{2}/cidrs/{3}/subnets'.
format(site_template, vrf, region, cidr_idx)
242 mso.previous = mso.existing
243 if state ==
'absent':
245 mso.sent = mso.existing = {}
246 ops.append(dict(op=
'remove', path=subnet_path))
248 elif state ==
'present':
255 mso.sanitize(payload, collate=
True)
258 ops.append(dict(op=
'replace', path=subnet_path, value=mso.sent))
260 ops.append(dict(op=
'add', path=subnets_path +
'/-', value=mso.sent))
262 mso.existing = mso.proposed
264 if not module.check_mode:
265 mso.request(schema_path, method=
'PATCH', data=ops)
270if __name__ ==
"__main__":