Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_l3out_floating_svi_path.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2023, Shreyas Srish <[email protected]>
5 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8
9 __metaclass__ = type
10
11 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "community"}
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_l3out_floating_svi_path
16 short_description: Manage Layer 3 Outside (L3Out) Floating SVI Path Attributes (l3ext:RsDynPathAtt)
17 description:
18 - Manages L3Out Floating SVI path attributes on Cisco ACI fabrics.
19 options:
20 tenant:
21 description:
22 - Name of an existing tenant.
23 type: str
24 aliases: [ tenant_name ]
25 required: true
26 l3out:
27 description:
28 - Name of an existing L3Out.
29 type: str
30 aliases: [ l3out_name ]
31 required: true
32 node_profile:
33 description:
34 - Name of the node profile.
35 type: str
36 aliases: [ node_profile_name, logical_node ]
37 required: true
38 interface_profile:
39 description:
40 - Name of the interface profile.
41 type: str
42 aliases: [ interface_profile_name, logical_interface ]
43 required: true
44 pod_id:
45 description:
46 - Pod to build the interface on.
47 type: str
48 required: true
49 node_id:
50 description:
51 - Node to build the interface on for Port-channels and single ports.
52 type: str
53 required: true
54 encap:
55 description:
56 - Encapsulation on the interface (e.g. "vlan-500")
57 type: str
58 required: true
59 domain:
60 description:
61 - This option allows virtual machines to send frames with a mac address.
62 type: str
63 domain_type:
64 description:
65 - The domain type of the path.
66 - The physical domain type is only supported in APIC v5.0 and above.
67 type: str
68 choices: [ physical, vmware ]
69 access_encap:
70 description:
71 - The port encapsulation option.
72 type: str
73 floating_ip:
74 description:
75 - The floating IP address.
76 type: str
77 aliases: [ floating_address ]
78 forged_transmit:
79 description:
80 - This option allows virtual machines to send frames with a mac address.
81 - This is only supported in APIC v5.0 and above.
82 type: str
83 choices: [ enabled, disabled ]
84 mac_change:
85 description:
86 - The status of the mac address change support for port groups in an external VMM controller.
87 - This is only supported in APIC v5.0 and above.
88 type: str
89 choices: [ enabled, disabled ]
90 promiscuous_mode:
91 description:
92 - The status of promiscuous mode for port groups in an external VMM controller.
93 - This is only supported in APIC v5.0 and above.
94 type: str
95 choices: [ enabled, disabled ]
96 enhanced_lag_policy:
97 description:
98 - The enhanced lag policy of the path.
99 - Pass "" as the value to remove an existing enhanced lag policy (See Examples).
100 type: str
101 state:
102 description:
103 - Use C(present) or C(absent) for adding or removing.
104 - Use C(query) for listing an object or multiple objects.
105 type: str
106 choices: [ absent, present, query ]
107 default: present
108 extends_documentation_fragment:
109 - cisco.aci.aci
110 - cisco.aci.annotation
111
112 notes:
113 - The C(tenant), C(l3out), C(logical_node_profile), C(logical_interface_profile) and C(floating_svi) must exist before using this module in your playbook.
114 The M(cisco.aci.aci_tenant), M(cisco.aci.aci_l3out), M(cisco.aci.aci_l3out_logical_node_profile), M(cisco.aci.aci_l3out_logical_interface_profile) and
115 M(cisco.aci.aci_l3out_floating_svi) can be used for this.
116 seealso:
117 - module: cisco.aci.aci_tenant
118 - module: cisco.aci.aci_l3out
119 - module: cisco.aci.aci_l3out_logical_node_profile
120 - module: cisco.aci.aci_l3out_logical_interface_profile
121 - module: cisco.aci.aci_l3out_floating_svi
122 - name: APIC Management Information Model reference
123 description: More information about the internal APIC class B(l3ext:RsDynPathAtt))
124 link: https://developer.cisco.com/docs/apic-mim-ref/
125 author:
126 - Shreyas Srish (@shrsr)
127 """
128
129 EXAMPLES = r"""
130 - name: Create a Floating SVI path attribute
131 cisco.aci.aci_l3out_floating_svi_path:
132 host: apic
133 username: admin
134 password: SomeSecretPassword
135 tenant: my_tenant
136 l3out: my_l3out
137 node_profile: my_node_profile
138 interface_profile: my_interface_profile
139 pod_id: 1
140 node_id: 201
141 encap: vlan-1
142 floating_ip: 23.45.67.90/24
143 domain_type: virtual
144 domain: anstest
145 enhanced_lag_policy: enhanced
146 state: present
147 delegate_to: localhost
148
149 - name: Remove enhanced lag policy from the path
150 cisco.aci.aci_l3out_floating_svi_path:
151 host: apic
152 username: admin
153 password: SomeSecretPassword
154 tenant: my_tenant
155 l3out: my_l3out
156 node_profile: my_node_profile
157 interface_profile: my_interface_profile
158 pod_id: 1
159 node_id: 201
160 encap: vlan-1
161 floating_ip: 23.45.67.90/24
162 domain_type: virtual
163 domain: anstest
164 enhanced_lag_policy: ""
165 state: present
166 delegate_to: localhost
167
168 - name: Remove a Floating SVI path attribute
169 cisco.aci.aci_l3out_floating_svi_path:
170 host: apic
171 username: admin
172 password: SomeSecretPassword
173 tenant: my_tenant
174 l3out: my_l3out
175 node_profile: my_node_profile
176 interface_profile: my_interface_profile
177 pod_id: 1
178 node_id: 201
179 encap: vlan-1
180 domain_type: virtual
181 domain: anstest
182 state: absent
183 delegate_to: localhost
184
185 - name: Query a Floating SVI path attribute
186 cisco.aci.aci_l3out_floating_svi_path:
187 host: apic
188 username: admin
189 password: SomeSecretPassword
190 tenant: my_tenant
191 l3out: my_l3out
192 node_profile: my_node_profile
193 interface_profile: my_interface_profile
194 pod_id: 1
195 node_id: 201
196 encap: vlan-1
197 domain_type: virtual
198 domain: anstest
199 state: query
200 delegate_to: localhost
201 register: query_result
202
203 - name: Query all the Floating SVI path attributes
204 cisco.aci.aci_l3out_floating_svi_path:
205 host: apic
206 username: admin
207 password: SomeSecretPassword
208 tenant: my_tenant
209 l3out: my_l3out
210 node_profile: my_node_profile
211 interface_profile: my_interface_profile
212 pod_id: 1
213 node_id: 201
214 encap: vlan-1
215 state: query
216 delegate_to: localhost
217 register: query_results
218 """
219
220 RETURN = r"""
221 current:
222 description: The existing configuration from the APIC after the module has finished
223 returned: success
224 type: list
225 sample:
226 [
227 {
228 "fvTenant": {
229 "attributes": {
230 "descr": "Production environment",
231 "dn": "uni/tn-production",
232 "name": "production",
233 "nameAlias": "",
234 "ownerKey": "",
235 "ownerTag": ""
236 }
237 }
238 }
239 ]
240 error:
241 description: The error information as returned from the APIC
242 returned: failure
243 type: dict
244 sample:
245 {
246 "code": "122",
247 "text": "unknown managed object class foo"
248 }
249 raw:
250 description: The raw output returned by the APIC REST API (xml or json)
251 returned: parse error
252 type: str
253 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
254 sent:
255 description: The actual/minimal configuration pushed to the APIC
256 returned: info
257 type: list
258 sample:
259 {
260 "fvTenant": {
261 "attributes": {
262 "descr": "Production environment"
263 }
264 }
265 }
266 previous:
267 description: The original configuration from the APIC before the module has started
268 returned: info
269 type: list
270 sample:
271 [
272 {
273 "fvTenant": {
274 "attributes": {
275 "descr": "Production",
276 "dn": "uni/tn-production",
277 "name": "production",
278 "nameAlias": "",
279 "ownerKey": "",
280 "ownerTag": ""
281 }
282 }
283 }
284 ]
285 proposed:
286 description: The assembled configuration from the user-provided parameters
287 returned: info
288 type: dict
289 sample:
290 {
291 "fvTenant": {
292 "attributes": {
293 "descr": "Production environment",
294 "name": "production"
295 }
296 }
297 }
298 filter_string:
299 description: The filter string used for the request
300 returned: failure or debug
301 type: str
302 sample: ?rsp-prop-include=config-only
303 method:
304 description: The HTTP method used for the request to the APIC
305 returned: failure or debug
306 type: str
307 sample: POST
308 response:
309 description: The HTTP response from the APIC
310 returned: failure or debug
311 type: str
312 sample: OK (30 bytes)
313 status:
314 description: The HTTP status from the APIC
315 returned: failure or debug
316 type: int
317 sample: 200
318 url:
319 description: The HTTP url used for the request to the APIC
320 returned: failure or debug
321 type: str
322 sample: https://10.11.12.13/api/mo/uni/tn-production.json
323 """
324
325
326 from ansible.module_utils.basic import AnsibleModule
327 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
328
329
330 def main():
331 argument_spec = aci_argument_spec()
332 argument_spec.update(aci_annotation_spec())
333 argument_spec.update(
334 tenant=dict(type="str", aliases=["tenant_name"], required=True),
335 l3out=dict(type="str", aliases=["l3out_name"], required=True),
336 node_profile=dict(type="str", aliases=["node_profile_name", "logical_node"], required=True),
337 interface_profile=dict(type="str", aliases=["interface_profile_name", "logical_interface"], required=True),
338 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
339 pod_id=dict(type="str", required=True),
340 node_id=dict(type="str", required=True),
341 encap=dict(type="str", required=True),
342 floating_ip=dict(type="str", aliases=["floating_address"]),
343 forged_transmit=dict(type="str", choices=["enabled", "disabled"]),
344 mac_change=dict(type="str", choices=["enabled", "disabled"]),
345 promiscuous_mode=dict(type="str", choices=["enabled", "disabled"]),
346 domain_type=dict(type="str", choices=["physical", "vmware"]),
347 domain=dict(type="str"),
348 enhanced_lag_policy=dict(type="str"),
349 access_encap=dict(type="str"),
350 )
351
352 module = AnsibleModule(
353 argument_spec=argument_spec,
354 supports_check_mode=True,
355 required_if=[
356 ["state", "present", ["domain_type", "domain", "floating_ip"]],
357 ["state", "absent", ["domain_type", "domain"]],
358 ],
359 )
360
361 tenant = module.params.get("tenant")
362 l3out = module.params.get("l3out")
363 node_profile = module.params.get("node_profile")
364 interface_profile = module.params.get("interface_profile")
365 state = module.params.get("state")
366 pod_id = module.params.get("pod_id")
367 node_id = module.params.get("node_id")
368 floating_ip = module.params.get("floating_ip")
369 encap = module.params.get("encap")
370 forged_transmit = module.params.get("forged_transmit").capitalize() if module.params.get("forged_transmit") else None
371 mac_change = module.params.get("mac_change").capitalize() if module.params.get("mac_change") else None
372 promiscuous_mode = module.params.get("promiscuous_mode").capitalize() if module.params.get("promiscuous_mode") else None
373 domain_type = module.params.get("domain_type")
374 domain = module.params.get("domain")
375 enhanced_lag_policy = module.params.get("enhanced_lag_policy")
376 access_encap = module.params.get("access_encap")
377
378 aci = ACIModule(module)
379
380 node_dn = "topology/pod-{0}/node-{1}".format(pod_id, node_id)
381
382 tDn = None
383 if domain_type == "physical":
384 tDn = "uni/phys-{0}".format(domain)
385 elif domain_type == "vmware":
386 tDn = "uni/vmmp-VMware/dom-{0}".format(domain)
387
388 aci.construct_url(
389 root_class=dict(
390 aci_class="fvTenant",
391 aci_rn="tn-{0}".format(tenant),
392 module_object=tenant,
393 target_filter={"name": tenant},
394 ),
395 subclass_1=dict(
396 aci_class="l3extOut",
397 aci_rn="out-{0}".format(l3out),
398 module_object=l3out,
399 target_filter={"name": l3out},
400 ),
401 subclass_2=dict(
402 aci_class="l3extLNodeP",
403 aci_rn="lnodep-{0}".format(node_profile),
404 module_object=node_profile,
405 target_filter={"name": node_profile},
406 ),
407 subclass_3=dict(
408 aci_class="l3extLIfP",
409 aci_rn="lifp-{0}".format(interface_profile),
410 module_object=interface_profile,
411 target_filter={"name": interface_profile},
412 ),
413 subclass_4=dict(
414 aci_class="l3extVirtualLIfP", aci_rn="vlifp-[{0}]-[{1}]".format(node_dn, encap), module_object=node_dn, target_filter={"nodeDn": node_dn}
415 ),
416 subclass_5=dict(
417 aci_class="l3extRsDynPathAtt",
418 aci_rn="rsdynPathAtt-[{0}]".format(tDn),
419 module_object=tDn,
420 target_filter={"tDn": tDn},
421 ),
422 child_classes=["l3extVirtualLIfPLagPolAtt"],
423 )
424
425 aci.get_existing()
426
427 if state == "present":
428 child_configs = []
429 if enhanced_lag_policy is not None and domain_type == "vmware":
430 existing_enhanced_lag_policy = ""
431 if isinstance(aci.existing, list) and len(aci.existing) > 0:
432 for child in aci.existing[0].get("l3extRsDynPathAtt", {}).get("children", {}):
433 if child.get("l3extVirtualLIfPLagPolAtt"):
434 try:
435 existing_enhanced_lag_policy = child["l3extVirtualLIfPLagPolAtt"]["children"][0]["l3extRsVSwitchEnhancedLagPol"]["attributes"][
436 "tDn"
437 ].split("enlacplagp-")[1]
438 except (AttributeError, IndexError, KeyError):
439 existing_enhanced_lag_policy = ""
440
441 if enhanced_lag_policy == "":
442 child_configs.append(
443 dict(
444 l3extVirtualLIfPLagPolAtt=dict(
445 attributes=dict(status="deleted"),
446 ),
447 )
448 )
449
450 if enhanced_lag_policy != "":
451 child = [
452 dict(
453 l3extRsVSwitchEnhancedLagPol=dict(
454 attributes=dict(tDn="{0}/vswitchpolcont/enlacplagp-{1}".format(tDn, enhanced_lag_policy)),
455 )
456 ),
457 ]
458 if enhanced_lag_policy != existing_enhanced_lag_policy and existing_enhanced_lag_policy != "":
459 child.append(
460 dict(
461 l3extRsVSwitchEnhancedLagPol=dict(
462 attributes=dict(status="deleted", tDn="{0}/vswitchpolcont/enlacplagp-{1}".format(tDn, existing_enhanced_lag_policy)),
463 )
464 )
465 )
466 child_configs.append(dict(l3extVirtualLIfPLagPolAtt=dict(attributes=dict(), children=child)))
467
468 aci.payload(
469 aci_class="l3extRsDynPathAtt",
470 class_config=dict(
471 floatingAddr=floating_ip,
472 forgedTransmit=forged_transmit,
473 macChange=mac_change,
474 promMode=promiscuous_mode,
475 encap=access_encap,
476 ),
477 child_configs=child_configs,
478 )
479
480 aci.get_diff(aci_class="l3extRsDynPathAtt")
481
482 aci.post_config()
483
484 elif state == "absent":
485 aci.delete_config()
486
487 aci.exit_json()
488
489
490 if __name__ == "__main__":
491 main()