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_anp_epg_staticleaf
17short_description: Manage site-local EPG static leafs in schema template
19- Manage site-local EPG static leafs 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 ANP.
45 - The name of the EPG.
49 - The pod of the static leaf.
53 - The path of the static leaf.
58 - The VLAN id of the static leaf.
62 - Use C(present) or C(absent)
for adding
or removing.
63 - Use C(query)
for listing an object
or multiple objects.
65 choices: [ absent, present, query ]
68- The ACI MultiSite PATCH API has a deficiency requiring some objects to be referenced by index.
69 This can cause silent corruption on concurrent access when changing/removing on object
as
70 the wrong object may be referenced. This module
is affected by this deficiency.
72- module: mso_schema_site_anp_epg
73- module: mso_schema_template_anp_epg
74extends_documentation_fragment: mso
78- name: Add a new static leaf to a site EPG
79 mso_schema_site_anp_epg_staticleaf:
82 password: SomeSecretPassword
91 delegate_to: localhost
93- name: Remove a static leaf from a site EPG
94 mso_schema_site_anp_epg_staticleaf:
97 password: SomeSecretPassword
105 delegate_to: localhost
107- name: Query a specific site EPG static leaf
108 mso_schema_site_anp_epg_staticleaf:
111 password: SomeSecretPassword
119 delegate_to: localhost
120 register: query_result
122- name: Query all site EPG static leafs
123 mso_schema_site_anp_epg_staticleaf:
126 password: SomeSecretPassword
132 delegate_to: localhost
133 register: query_result
139from ansible.module_utils.basic import AnsibleModule
140from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec
145 argument_spec.update(
146 schema=dict(type=
'str', required=
True),
147 site=dict(type=
'str', required=
True),
148 template=dict(type=
'str', required=
True),
149 anp=dict(type=
'str', required=
True),
150 epg=dict(type=
'str', required=
True),
151 pod=dict(type=
'str'),
152 leaf=dict(type=
'str', aliases=[
'name']),
153 vlan=dict(type=
'int'),
154 state=dict(type=
'str', default=
'present', choices=[
'absent',
'present',
'query']),
158 argument_spec=argument_spec,
159 supports_check_mode=
True,
161 [
'state',
'absent', [
'pod',
'leaf',
'vlan']],
162 [
'state',
'present', [
'pod',
'leaf',
'vlan']],
166 schema = module.params[
'schema']
167 site = module.params[
'site']
168 template = module.params[
'template']
169 anp = module.params[
'anp']
170 epg = module.params[
'epg']
171 pod = module.params[
'pod']
172 leaf = module.params[
'leaf']
173 vlan = module.params[
'vlan']
174 state = module.params[
'state']
176 leafpath =
'topology/{0}/node-{1}'.
format(pod, leaf)
181 schema_obj = mso.get_obj(
'schemas', displayName=schema)
183 mso.fail_json(msg=
"Provided schema '{0}' does not exist".
format(schema))
185 schema_path =
'schemas/{id}'.
format(**schema_obj)
186 schema_id = schema_obj[
'id']
189 site_id = mso.lookup_site(site)
192 sites = [(s[
'siteId'], s[
'templateName'])
for s
in schema_obj[
'sites']]
193 if (site_id, template)
not in sites:
194 mso.fail_json(msg=
"Provided site/template '{0}-{1}' does not exist. Existing sites/templates: {2}".
format(site, template,
', '.join(sites)))
197 site_idx = sites.index((site_id, template))
199 site_template =
'{0}-{1}'.
format(site_id, template)
202 anp_ref = mso.anp_ref(schema_id=schema_id, template=template, anp=anp)
203 anps = [a[
'anpRef']
for a
in schema_obj[
'sites'][site_idx][
'anps']]
204 if anp_ref
not in anps:
205 mso.fail_json(msg=
"Provided anp '{0}' does not exist. Existing anps: {1}".
format(anp,
', '.join(anps)))
206 anp_idx = anps.index(anp_ref)
209 epg_ref = mso.epg_ref(schema_id=schema_id, template=template, anp=anp, epg=epg)
210 epgs = [e[
'epgRef']
for e
in schema_obj[
'sites'][site_idx][
'anps'][anp_idx][
'epgs']]
211 if epg_ref
not in epgs:
212 mso.fail_json(msg=
"Provided epg '{0}' does not exist. Existing epgs: {1}".
format(epg,
', '.join(epgs)))
213 epg_idx = epgs.index(epg_ref)
216 leafs = [(l[
'path'], l[
'portEncapVlan'])
for l
in schema_obj[
'sites'][site_idx][
'anps'][anp_idx][
'epgs'][epg_idx][
'staticLeafs']]
217 if (leafpath, vlan)
in leafs:
218 leaf_idx = leafs.index((leafpath, vlan))
220 leaf_path =
'/sites/{0}/anps/{1}/epgs/{2}/staticLeafs/{3}'.
format(site_template, anp, epg, leaf_idx)
221 mso.existing = schema_obj[
'sites'][site_idx][
'anps'][anp_idx][
'epgs'][epg_idx][
'staticLeafs'][leaf_idx]
224 if leaf
is None or vlan
is None:
225 mso.existing = schema_obj[
'sites'][site_idx][
'anps'][anp_idx][
'epgs'][epg_idx][
'staticLeafs']
226 elif not mso.existing:
227 mso.fail_json(msg=
"Static leaf '{leaf}/{vlan}' not found".
format(leaf=leaf, vlan=vlan))
230 leafs_path =
'/sites/{0}/anps/{1}/epgs/{2}/staticLeafs'.
format(site_template, anp, epg)
233 mso.previous = mso.existing
234 if state ==
'absent':
236 mso.sent = mso.existing = {}
237 ops.append(dict(op=
'remove', path=leaf_path))
239 elif state ==
'present':
245 mso.sanitize(payload, collate=
True)
248 ops.append(dict(op=
'replace', path=leaf_path, value=mso.sent))
250 ops.append(dict(op=
'add', path=leafs_path +
'/-', value=mso.sent))
252 mso.existing = mso.proposed
254 if not module.check_mode:
255 mso.request(schema_path, method=
'PATCH', data=ops)
260if __name__ ==
"__main__":