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_staticport
17short_description: Manage site-local EPG static ports in schema template
19- Manage site-local EPG static ports 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 path type of the static port
55 - The pod of the static port.
59 - The leaf of the static port.
63 - The path of the static port.
67 - The port encap VLAN id of the static port.
71 - The deployment immediacy of the static port.
72 - C(immediate) means B(Deploy immediate).
73 - C(lazy) means B(deploy on demand).
75 choices: [ immediate, lazy ]
78 - The mode of the static port.
79 - C(native) means B(Access (802.1p)).
80 - C(regular) means B(Trunk).
81 - C(untagged) means B(Access (untagged)).
83 choices: [ native, regular, untagged ]
86 - Use C(present) or C(absent)
for adding
or removing.
87 - Use C(query)
for listing an object
or multiple objects.
89 choices: [ absent, present, query ]
92- The ACI MultiSite PATCH API has a deficiency requiring some objects to be referenced by index.
93 This can cause silent corruption on concurrent access when changing/removing on object
as
94 the wrong object may be referenced. This module
is affected by this deficiency.
96- module: mso_schema_site_anp_epg
97- module: mso_schema_template_anp_epg
98extends_documentation_fragment: mso
102- name: Add a new static port to a site EPG
103 mso_schema_site_anp_epg_staticport:
106 password: SomeSecretPassword
117 deployment_immediacy: immediate
119 delegate_to: localhost
121- name: Remove a static port from a site EPG
122 mso_schema_site_anp_epg_staticport:
125 password: SomeSecretPassword
136 delegate_to: localhost
138- name: Query a specific site EPG static port
139 mso_schema_site_anp_epg_staticport:
142 password: SomeSecretPassword
153 delegate_to: localhost
154 register: query_result
156- name: Query all site EPG static ports
157 mso_schema_site_anp_epg_staticport:
160 password: SomeSecretPassword
166 delegate_to: localhost
167 register: query_result
173from ansible.module_utils.basic import AnsibleModule
174from ansible.module_utils.network.aci.mso import MSOModule, mso_argument_spec
179 argument_spec.update(
180 schema=dict(type=
'str', required=
True),
181 site=dict(type=
'str', required=
True),
182 template=dict(type=
'str', required=
True),
183 anp=dict(type=
'str', required=
True),
184 epg=dict(type=
'str', required=
True),
185 type=dict(type=
'str', default=
'port', choices=[
'port']),
186 pod=dict(type=
'str'),
187 leaf=dict(type=
'str'),
188 path=dict(type=
'str'),
189 vlan=dict(type=
'int'),
190 deployment_immediacy=dict(type=
'str', choices=[
'immediate',
'lazy']),
191 mode=dict(type=
'str', choices=[
'native',
'regular',
'untagged']),
192 state=dict(type=
'str', default=
'present', choices=[
'absent',
'present',
'query']),
196 argument_spec=argument_spec,
197 supports_check_mode=
True,
199 [
'state',
'absent', [
'type',
'pod',
'leaf',
'path',
'vlan']],
200 [
'state',
'present', [
'type',
'pod',
'leaf',
'path',
'vlan']],
204 schema = module.params[
'schema']
205 site = module.params[
'site']
206 template = module.params[
'template']
207 anp = module.params[
'anp']
208 epg = module.params[
'epg']
209 path_type = module.params[
'type']
210 pod = module.params[
'pod']
211 leaf = module.params[
'leaf']
212 path = module.params[
'path']
213 vlan = module.params[
'vlan']
214 deployment_immediacy = module.params[
'deployment_immediacy']
215 mode = module.params[
'mode']
216 state = module.params[
'state']
218 if path_type ==
'port':
219 portpath =
'topology/{0}/paths-{1}/pathep-[{2}]'.
format(pod, leaf, path)
224 schema_obj = mso.get_obj(
'schemas', displayName=schema)
226 mso.fail_json(msg=
"Provided schema '{0}' does not exist".
format(schema))
228 schema_path =
'schemas/{id}'.
format(**schema_obj)
229 schema_id = schema_obj[
'id']
232 site_id = mso.lookup_site(site)
235 sites = [(s[
'siteId'], s[
'templateName'])
for s
in schema_obj[
'sites']]
236 if (site_id, template)
not in sites:
237 mso.fail_json(msg=
"Provided site/template '{0}-{1}' does not exist. Existing sites/templates: {2}".
format(site, template,
', '.join(sites)))
240 site_idx = sites.index((site_id, template))
242 site_template =
'{0}-{1}'.
format(site_id, template)
245 anp_ref = mso.anp_ref(schema_id=schema_id, template=template, anp=anp)
246 anps = [a[
'anpRef']
for a
in schema_obj[
'sites'][site_idx][
'anps']]
247 if anp_ref
not in anps:
248 mso.fail_json(msg=
"Provided anp '{0}' does not exist. Existing anps: {1}".
format(anp,
', '.join(anps)))
249 anp_idx = anps.index(anp_ref)
252 epg_ref = mso.epg_ref(schema_id=schema_id, template=template, anp=anp, epg=epg)
253 epgs = [e[
'epgRef']
for e
in schema_obj[
'sites'][site_idx][
'anps'][anp_idx][
'epgs']]
254 if epg_ref
not in epgs:
255 mso.fail_json(msg=
"Provided epg '{0}' does not exist. Existing epgs: {1}".
format(epg,
', '.join(epgs)))
256 epg_idx = epgs.index(epg_ref)
259 portpaths = [p[
'path']
for p
in schema_obj[
'sites'][site_idx][
'anps'][anp_idx][
'epgs'][epg_idx][
'staticPorts']]
260 if portpath
in portpaths:
261 portpath_idx = portpaths.index(portpath)
263 port_path =
'/sites/{0}/anps/{1}/epgs/{2}/staticPorts/{3}'.
format(site_template, anp, epg, portpath_idx)
264 mso.existing = schema_obj[
'sites'][site_idx][
'anps'][anp_idx][
'epgs'][epg_idx][
'staticPorts'][portpath_idx]
267 if leaf
is None or vlan
is None:
268 mso.existing = schema_obj[
'sites'][site_idx][
'anps'][anp_idx][
'epgs'][epg_idx][
'staticPorts']
269 elif not mso.existing:
270 mso.fail_json(msg=
"Static port '{portpath}' not found".
format(portpath=portpath))
273 ports_path =
'/sites/{0}/anps/{1}/epgs/{2}/staticPorts'.
format(site_template, anp, epg)
276 mso.previous = mso.existing
277 if state ==
'absent':
279 mso.sent = mso.existing = {}
280 ops.append(dict(op=
'remove', path=port_path))
282 elif state ==
'present':
284 if deployment_immediacy
is None:
285 deployment_immediacy =
'lazy'
290 deploymentImmediacy=deployment_immediacy,
297 mso.sanitize(payload, collate=
True)
300 ops.append(dict(op=
'replace', path=port_path, value=mso.sent))
302 ops.append(dict(op=
'add', path=ports_path +
'/-', value=mso.sent))
304 mso.existing = mso.proposed
306 if not module.check_mode:
307 mso.request(schema_path, method=
'PATCH', data=ops)
312if __name__ ==
"__main__":