Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2024, Gaspard Micol (@gmicol) <[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_logical_interface_profile
16 short_description: Manage Layer 3 Outside (L3Out) logical interface profiles (l3ext:LIfP)
17 description:
18 - Manage L3Out interface profiles on Cisco ACI fabrics.
19 options:
20 tenant:
21 description:
22 - The name of an existing tenant.
23 type: str
24 aliases: [ tenant_name ]
25 l3out:
26 description:
27 - The name of an existing L3Out.
28 type: str
29 aliases: [ l3out_name ]
30 node_profile:
31 description:
32 - The name of the node profile.
33 type: str
34 aliases: [ node_profile_name, logical_node ]
35 interface_profile:
36 description:
37 - The name of the logical interface profile.
38 type: str
39 aliases: [ name, interface_profile_name, logical_interface ]
40 nd_policy:
41 description:
42 - The name of the neighbor discovery interface policy.
43 type: str
44 egress_dpp_policy:
45 description:
46 - The name of the egress data plane policing policy.
47 type: str
48 ingress_dpp_policy:
49 description:
50 - The name of the ingress data plane policing policy.
51 type: str
52 qos_priority:
53 description:
54 - The QoS priority class ID.
55 - The APIC defaults to C(unspecified) when unset during creation.
56 type: str
57 choices: [ level1, level2, level3, level4, level5, level6, unspecified ]
58 aliases: [ priority, prio ]
59 qos_custom_policy:
60 description:
61 - The name of the QoS custom policy.
62 type: str
63 aliases: [ qos_custom_policy_name ]
64 pim_v4_interface_profile:
65 description:
66 - The PIM IPv4 interface profile.
67 type: dict
68 suboptions:
69 tenant:
70 description:
71 - The name of the tenant to which the PIM IPv4 interface policy belongs.
72 type: str
73 aliases: [ tenant_name ]
74 pim:
75 description:
76 - The name of the PIM IPv4 interface policy.
77 type: str
78 aliases: [ pim_interface_policy, name ]
79 aliases: [ pim_v4 ]
80 pim_v6_interface_profile:
81 description:
82 - The PIM IPv6 interface profile.
83 type: dict
84 suboptions:
85 tenant:
86 description:
87 - The name of the tenant to which the PIM IPv6 interface policy belongs.
88 type: str
89 aliases: [ tenant_name ]
90 pim:
91 description:
92 - The name of the PIM IPv6 interface policy.
93 type: str
94 aliases: [ pim_interface_policy, name ]
95 aliases: [ pim_v6 ]
96 igmp_interface_profile:
97 description:
98 - The IGMP interface profile.
99 type: dict
100 suboptions:
101 tenant:
102 description:
103 - The name of the tenant to which the IGMP interface policy belongs.
104 type: str
105 aliases: [ tenant_name ]
106 igmp:
107 description:
108 - The name of the IGMP interface policy.
109 type: str
110 aliases: [ igmp_interface_policy, name ]
111 aliases: [ igmp ]
112 description:
113 description:
114 - The description for the logical interface profile.
115 type: str
116 aliases: [ descr ]
117 state:
118 description:
119 - Use C(present) or C(absent) for adding or removing.
120 - Use C(query) for listing an object or multiple objects.
121 type: str
122 choices: [ absent, present, query ]
123 default: present
124 extends_documentation_fragment:
125 - cisco.aci.aci
126 - cisco.aci.annotation
127 - cisco.aci.owner
128
129 notes:
130 - The I(tenant), I(l3out) and I(node_profile) must exist before using this module in your playbook.
131 The M(cisco.aci.aci_tenant), M(cisco.aci.aci_l3out) and M(cisco.aci.aci_l3out_logical_node_profile) can be used for this.
132 seealso:
133 - module: cisco.aci.aci_tenant
134 - module: cisco.aci.aci_l3out
135 - module: cisco.aci.aci_l3out_logical_node_profile
136 - name: APIC Management Information Model reference
137 description: More information about the internal APIC class B(l3ext:LIfP).
138 link: https://developer.cisco.com/docs/apic-mim-ref/
139 author:
140 - Marcel Zehnder (@maercu)
141 - Gaspard Micol (@gmicol)
142 """
143
144 EXAMPLES = r"""
145 - name: Add a new interface profile
146 cisco.aci.aci_l3out_logical_interface_profile:
147 host: apic
148 username: admin
149 password: SomeSecretPassword
150 tenant: my_tenant
151 l3out: my_l3out
152 node_profile: my_node_profile
153 interface_profile: my_interface_profile
154 state: present
155 delegate_to: localhost
156
157 - name: Query an interface profile
158 cisco.aci.aci_l3out_logical_interface_profile:
159 host: apic
160 username: admin
161 password: SomeSecretPassword
162 tenant: my_tenant
163 l3out: my_l3out
164 node_profile: my_node_profile
165 interface_profile: my_interface_profile
166 state: query
167 delegate_to: localhost
168 register: query_result
169
170 - name: Query all interface profiles
171 cisco.aci.aci_l3out_logical_interface_profile:
172 host: apic
173 username: admin
174 password: SomeSecretPassword
175 state: query
176 delegate_to: localhost
177 register: query_result
178
179 - name: Delete an interface profile
180 cisco.aci.aci_l3out_logical_interface_profile:
181 host: apic
182 username: admin
183 password: SomeSecretPassword
184 tenant: my_tenant
185 l3out: my_l3out
186 node_profile: my_node_profile
187 interface_profile: my_interface_profile
188 state: absent
189 delegate_to: localhost
190 """
191
192 RETURN = r"""
193 current:
194 description: The existing configuration from the APIC after the module has finished
195 returned: success
196 type: list
197 sample:
198 [
199 {
200 "fvTenant": {
201 "attributes": {
202 "descr": "Production environment",
203 "dn": "uni/tn-production",
204 "name": "production",
205 "nameAlias": "",
206 "ownerKey": "",
207 "ownerTag": ""
208 }
209 }
210 }
211 ]
212 error:
213 description: The error information as returned from the APIC
214 returned: failure
215 type: dict
216 sample:
217 {
218 "code": "122",
219 "text": "unknown managed object class foo"
220 }
221 raw:
222 description: The raw output returned by the APIC REST API (xml or json)
223 returned: parse error
224 type: str
225 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
226 sent:
227 description: The actual/minimal configuration pushed to the APIC
228 returned: info
229 type: list
230 sample:
231 {
232 "fvTenant": {
233 "attributes": {
234 "descr": "Production environment"
235 }
236 }
237 }
238 previous:
239 description: The original configuration from the APIC before the module has started
240 returned: info
241 type: list
242 sample:
243 [
244 {
245 "fvTenant": {
246 "attributes": {
247 "descr": "Production",
248 "dn": "uni/tn-production",
249 "name": "production",
250 "nameAlias": "",
251 "ownerKey": "",
252 "ownerTag": ""
253 }
254 }
255 }
256 ]
257 proposed:
258 description: The assembled configuration from the user-provided parameters
259 returned: info
260 type: dict
261 sample:
262 {
263 "fvTenant": {
264 "attributes": {
265 "descr": "Production environment",
266 "name": "production"
267 }
268 }
269 }
270 filter_string:
271 description: The filter string used for the request
272 returned: failure or debug
273 type: str
274 sample: ?rsp-prop-include=config-only
275 method:
276 description: The HTTP method used for the request to the APIC
277 returned: failure or debug
278 type: str
279 sample: POST
280 response:
281 description: The HTTP response from the APIC
282 returned: failure or debug
283 type: str
284 sample: OK (30 bytes)
285 status:
286 description: The HTTP status from the APIC
287 returned: failure or debug
288 type: int
289 sample: 200
290 url:
291 description: The HTTP url used for the request to the APIC
292 returned: failure or debug
293 type: str
294 sample: https://10.11.12.13/api/mo/uni/tn-production.json
295 """
296
297
298 from ansible.module_utils.basic import AnsibleModule
299 from ansible_collections.cisco.aci.plugins.module_utils.aci import (
300 ACIModule,
301 aci_argument_spec,
302 aci_annotation_spec,
303 aci_owner_spec,
304 pim_interface_profile_spec,
305 igmp_interface_profile_spec,
306 )
307
308
309 def main():
310 argument_spec = aci_argument_spec()
311 argument_spec.update(aci_annotation_spec())
312 argument_spec.update(aci_owner_spec())
313 argument_spec.update(
314 tenant=dict(type="str", aliases=["tenant_name"]),
315 l3out=dict(type="str", aliases=["l3out_name"]),
316 node_profile=dict(type="str", aliases=["node_profile_name", "logical_node"]),
317 interface_profile=dict(type="str", aliases=["name", "interface_profile_name", "logical_interface"]),
318 nd_policy=dict(type="str"),
319 egress_dpp_policy=dict(type="str"),
320 ingress_dpp_policy=dict(type="str"),
321 qos_priority=dict(type="str", choices=["level1", "level2", "level3", "level4", "level5", "level6", "unspecified"], aliases=["priority", "prio"]),
322 qos_custom_policy=dict(type="str", aliases=["qos_custom_policy_name"]),
323 pim_v4_interface_profile=dict(type="dict", options=pim_interface_profile_spec(), aliases=["pim_v4"]),
324 pim_v6_interface_profile=dict(type="dict", options=pim_interface_profile_spec(), aliases=["pim_v6"]),
325 igmp_interface_profile=dict(type="dict", options=igmp_interface_profile_spec(), aliases=["igmp"]),
326 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
327 description=dict(type="str", aliases=["descr"]),
328 )
329
330 module = AnsibleModule(
331 argument_spec=argument_spec,
332 supports_check_mode=True,
333 required_if=[
334 ["state", "absent", ["tenant", "l3out", "node_profile", "interface_profile"]],
335 ["state", "present", ["tenant", "l3out", "node_profile", "interface_profile"]],
336 ],
337 )
338
339 tenant = module.params.get("tenant")
340 l3out = module.params.get("l3out")
341 node_profile = module.params.get("node_profile")
342 interface_profile = module.params.get("interface_profile")
343 nd_policy = module.params.get("nd_policy")
344 egress_dpp_policy = module.params.get("egress_dpp_policy")
345 ingress_dpp_policy = module.params.get("ingress_dpp_policy")
346 qos_priority = module.params.get("qos_priority")
347 qos_custom_policy = module.params.get("qos_custom_policy")
348 description = module.params.get("description")
349 state = module.params.get("state")
350
351 aci = ACIModule(module)
352
353 extra_child_classes = dict(
354 pimIPV6IfP=dict(rs_class="pimRsV6IfPol", attribute_input=module.params.get("pim_v6_interface_profile")),
355 pimIfP=dict(rs_class="pimRsIfPol", attribute_input=module.params.get("pim_v4_interface_profile")),
356 igmpIfP=dict(rs_class="igmpRsIfPol", attribute_input=module.params.get("igmp_interface_profile")),
357 )
358
359 aci.construct_url(
360 root_class=dict(
361 aci_class="fvTenant",
362 aci_rn="tn-{0}".format(tenant),
363 module_object=tenant,
364 target_filter={"name": tenant},
365 ),
366 subclass_1=dict(
367 aci_class="l3extOut",
368 aci_rn="out-{0}".format(l3out),
369 module_object=l3out,
370 target_filter={"name": l3out},
371 ),
372 subclass_2=dict(
373 aci_class="l3extLNodeP",
374 aci_rn="lnodep-{0}".format(node_profile),
375 module_object=node_profile,
376 target_filter={"name": node_profile},
377 ),
378 subclass_3=dict(
379 aci_class="l3extLIfP",
380 aci_rn="lifp-{0}".format(interface_profile),
381 module_object=interface_profile,
382 target_filter={"name": interface_profile},
383 ),
384 child_classes=list(extra_child_classes.keys()) + ["l3extRsEgressQosDppPol", "l3extRsIngressQosDppPol", "l3extRsLIfPCustQosPol", "l3extRsNdIfPol"],
385 )
386
387 aci.get_existing()
388
389 if state == "present":
390 child_configs = [
391 dict(l3extRsNdIfPol=dict(attributes=dict(tnNdIfPolName=nd_policy))),
392 dict(l3extRsIngressQosDppPol=dict(attributes=dict(tnQosDppPolName=ingress_dpp_policy))),
393 dict(l3extRsEgressQosDppPol=dict(attributes=dict(tnQosDppPolName=egress_dpp_policy))),
394 dict(l3extRsLIfPCustQosPol=dict(attributes=dict(tnQosCustomPolName=qos_custom_policy))),
395 ]
396 for class_name, attribute in extra_child_classes.items():
397 attribute_input = attribute.get("attribute_input")
398 if attribute_input is not None:
399 rs_class = attribute.get("rs_class")
400 if all(value is None for value in attribute_input.values()) and isinstance(aci.existing, list) and len(aci.existing) > 0:
401 for child in aci.existing[0].get("l3extLIfP", {}).get("children", {}):
402 if child.get(class_name):
403 child_configs.append(
404 {
405 class_name: dict(
406 attributes=dict(status="deleted"),
407 ),
408 }
409 )
410 elif all(value is not None for value in attribute_input.values()):
411 if rs_class in ["pimRsV6IfPol", "pimRsIfPol"]:
412 child_configs.append(
413 {
414 class_name: dict(
415 attributes={},
416 children=[
417 {
418 rs_class: dict(
419 attributes=dict(
420 tDn="uni/tn-{0}/pimifpol-{1}".format(attribute_input.get("tenant"), attribute_input.get("pim"))
421 )
422 )
423 },
424 ],
425 )
426 }
427 )
428 elif rs_class == "igmpRsIfPol":
429 child_configs.append(
430 {
431 class_name: dict(
432 attributes={},
433 children=[
434 {
435 rs_class: dict(
436 attributes=dict(
437 tDn="uni/tn-{0}/igmpIfPol-{1}".format(attribute_input.get("tenant"), attribute_input.get("igmp"))
438 )
439 )
440 },
441 ],
442 )
443 }
444 )
445
446 aci.payload(
447 aci_class="l3extLIfP",
448 class_config=dict(
449 name=interface_profile,
450 prio=qos_priority,
451 descr=description,
452 ),
453 child_configs=child_configs,
454 )
455
456 aci.get_diff(aci_class="l3extLIfP")
457
458 aci.post_config()
459
460 elif state == "absent":
461 aci.delete_config()
462
463 aci.exit_json()
464
465
466 if __name__ == "__main__":
467 main()