Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2023, 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_eigrp_interface_profile
16 short_description: Manage Layer 3 Outside (L3Out) EIGRP interface profile (eigrp:IfP)
17 description:
18 - Manage L3Out logical interface profile EIGRP policies 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 an existing interface profile.
38 type: str
39 aliases: [ interface_profile_name, logical_interface ]
40 eigrp_policy:
41 description:
42 - The name of an existing EIGRP interface policy.
43 type: str
44 aliases: [ name, eigrp_policy_name ]
45 eigrp_keychain_policy:
46 description:
47 - The name of an existing EIGRP keychain policy.
48 - Pass an empty string to disable Authentification.
49 type: str
50 aliases: [ keychain_policy, keychain_policy_name ]
51 description:
52 description:
53 - The description of the EIGRP interface profile.
54 type: str
55 aliases: [ descr ]
56 state:
57 description:
58 - Use C(present) or C(absent) for adding or removing.
59 - Use C(query) for listing an object or multiple objects.
60 type: str
61 choices: [ absent, present, query ]
62 default: present
63 extends_documentation_fragment:
64 - cisco.aci.aci
65 - cisco.aci.annotation
66 - cisco.aci.owner
67
68 notes:
69 - The C(tenant), C(l3out), C(node_profile), C(interface_profile) and C(eigrp_policy) must exist before using this module in your playbook.
70 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)
71 and M(cisco.aci.aci_interface_policy_eigrp) can be used for this.
72 - if C(eigrp_keychain_policy) is used, it must exist before using this module in your playbook.
73 The M(cisco.aci.aci_keychain_policy) can be used for this.
74 seealso:
75 - module: cisco.aci.aci_tenant
76 - module: cisco.aci.aci_l3out
77 - module: cisco.aci.aci_l3out_logical_node_profile
78 - module: cisco.aci.aci_l3out_logical_interface_profile
79 - module: cisco.aci.aci_interface_policy_eigrp
80 - module: cisco.aci.aci_keychain_policy
81 - name: APIC Management Information Model reference
82 description: More information about the internal APIC classes
83 link: https://developer.cisco.com/docs/apic-mim-ref/
84 author:
85 - Gaspard Micol (@gmicol)
86 """
87
88 EXAMPLES = r"""
89 - name: Add a new interface profile EIGRP policy
90 cisco.aci.aci_l3out_eigrp_interface_profile:
91 host: apic
92 username: admin
93 password: SomeSecretPassword
94 tenant: my_tenant
95 l3out: my_l3out
96 node_profile: my_node_profile
97 interface_profile: my_interface_profile
98 eigrp_policy: my_eigrp_interface_policy
99 state: present
100 delegate_to: localhost
101
102 - name: Add a new interface profile EIGRP policy with authentication
103 cisco.aci.aci_l3out_eigrp_interface_profile:
104 host: apic
105 username: admin
106 password: SomeSecretPassword
107 tenant: my_tenant
108 l3out: my_l3out
109 node_profile: my_node_profile
110 interface_profile: my_interface_profile
111 eigrp_policy: my_eigrp_interface_policy
112 eigrp_keychain_policy: my_keychain_policy
113 state: present
114 delegate_to: localhost
115
116 - name: Disable authentification from an interface profile EIGRP policy
117 cisco.aci.aci_l3out_eigrp_interface_profile:
118 host: apic
119 username: admin
120 password: SomeSecretPassword
121 tenant: my_tenant
122 l3out: my_l3out
123 node_profile: my_node_profile
124 interface_profile: my_interface_profile
125 eigrp_policy: my_eigrp_interface_policy
126 eigrp_keychain_policy: ""
127 state: present
128 delegate_to: localhost
129
130 - name: Delete an interface profile EIGRP policy
131 cisco.aci.aci_l3out_eigrp_interface_profile:
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 eigrp_policy: my_eigrp_interface_policy
140 state: absent
141 delegate_to: localhost
142
143 - name: Query an interface profile EIGRP policy
144 cisco.aci.aci_l3out_eigrp_interface_profile:
145 host: apic
146 username: admin
147 password: SomeSecretPassword
148 tenant: my_tenant
149 l3out: my_l3out
150 node_profile: my_node_profile
151 interface_profile: my_interface_profile
152 eigrp_policy: my_eigrp_interface_policy
153 state: query
154 delegate_to: localhost
155 register: query_result
156 """
157
158 RETURN = r"""
159 current:
160 description: The existing configuration from the APIC after the module has finished
161 returned: success
162 type: list
163 sample:
164 [
165 {
166 "fvTenant": {
167 "attributes": {
168 "descr": "Production environment",
169 "dn": "uni/tn-production",
170 "name": "production",
171 "nameAlias": "",
172 "ownerKey": "",
173 "ownerTag": ""
174 }
175 }
176 }
177 ]
178 error:
179 description: The error information as returned from the APIC
180 returned: failure
181 type: dict
182 sample:
183 {
184 "code": "122",
185 "text": "unknown managed object class foo"
186 }
187 raw:
188 description: The raw output returned by the APIC REST API (xml or json)
189 returned: parse error
190 type: str
191 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
192 sent:
193 description: The actual/minimal configuration pushed to the APIC
194 returned: info
195 type: list
196 sample:
197 {
198 "fvTenant": {
199 "attributes": {
200 "descr": "Production environment"
201 }
202 }
203 }
204 previous:
205 description: The original configuration from the APIC before the module has started
206 returned: info
207 type: list
208 sample:
209 [
210 {
211 "fvTenant": {
212 "attributes": {
213 "descr": "Production",
214 "dn": "uni/tn-production",
215 "name": "production",
216 "nameAlias": "",
217 "ownerKey": "",
218 "ownerTag": ""
219 }
220 }
221 }
222 ]
223 proposed:
224 description: The assembled configuration from the user-provided parameters
225 returned: info
226 type: dict
227 sample:
228 {
229 "fvTenant": {
230 "attributes": {
231 "descr": "Production environment",
232 "name": "production"
233 }
234 }
235 }
236 filter_string:
237 description: The filter string used for the request
238 returned: failure or debug
239 type: str
240 sample: ?rsp-prop-include=config-only
241 method:
242 description: The HTTP method used for the request to the APIC
243 returned: failure or debug
244 type: str
245 sample: POST
246 response:
247 description: The HTTP response from the APIC
248 returned: failure or debug
249 type: str
250 sample: OK (30 bytes)
251 status:
252 description: The HTTP status from the APIC
253 returned: failure or debug
254 type: int
255 sample: 200
256 url:
257 description: The HTTP url used for the request to the APIC
258 returned: failure or debug
259 type: str
260 sample: https://10.11.12.13/api/mo/uni/tn-production.json
261 """
262
263
264 from ansible.module_utils.basic import AnsibleModule
265 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
266
267
268 def main():
269 argument_spec = aci_argument_spec()
270 argument_spec.update(aci_annotation_spec())
271 argument_spec.update(aci_owner_spec())
272 argument_spec.update(
273 tenant=dict(type="str", aliases=["tenant_name"]),
274 l3out=dict(type="str", aliases=["l3out_name"]),
275 node_profile=dict(type="str", aliases=["node_profile_name", "logical_node"]),
276 interface_profile=dict(type="str", aliases=["interface_profile_name", "logical_interface"]),
277 eigrp_policy=dict(type="str", aliases=["name", "eigrp_policy_name"]),
278 eigrp_keychain_policy=dict(type="str", aliases=["keychain_policy", "keychain_policy_name"], no_log=False),
279 description=dict(type="str", aliases=["descr"]),
280 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
281 )
282
283 module = AnsibleModule(
284 argument_spec=argument_spec,
285 supports_check_mode=True,
286 required_if=[
287 ["state", "absent", ["tenant", "l3out", "node_profile", "interface_profile"]],
288 ["state", "present", ["tenant", "l3out", "node_profile", "interface_profile", "eigrp_policy"]],
289 ],
290 )
291
292 tenant = module.params.get("tenant")
293 l3out = module.params.get("l3out")
294 node_profile = module.params.get("node_profile")
295 interface_profile = module.params.get("interface_profile")
296 eigrp_policy = module.params.get("eigrp_policy")
297 eigrp_keychain_policy = module.params.get("eigrp_keychain_policy")
298 description = module.params.get("description")
299 state = module.params.get("state")
300
301 aci = ACIModule(module)
302
303 child_classes = ["eigrpRsIfPol", "eigrpAuthIfP"]
304
305 aci.construct_url(
306 root_class=dict(
307 aci_class="fvTenant",
308 aci_rn="tn-{0}".format(tenant),
309 module_object=tenant,
310 target_filter={"name": tenant},
311 ),
312 subclass_1=dict(
313 aci_class="l3extOut",
314 aci_rn="out-{0}".format(l3out),
315 module_object=l3out,
316 target_filter={"name": l3out},
317 ),
318 subclass_2=dict(
319 aci_class="l3extLNodeP",
320 aci_rn="lnodep-{0}".format(node_profile),
321 module_object=node_profile,
322 target_filter={"name": node_profile},
323 ),
324 subclass_3=dict(
325 aci_class="l3extLIfP",
326 aci_rn="lifp-[{0}]".format(interface_profile),
327 module_object=interface_profile,
328 target_filter={"name": interface_profile},
329 ),
330 subclass_4=dict(
331 aci_class="eigrpIfP",
332 aci_rn="eigrpIfP",
333 module_object=interface_profile,
334 target_filter={"name": interface_profile},
335 ),
336 child_classes=child_classes,
337 )
338
339 aci.get_existing()
340
341 if state == "present":
342 child_configs = [dict(eigrpRsIfPol=dict(attributes=dict(tnEigrpIfPolName=eigrp_policy)))]
343
344 if eigrp_keychain_policy is not None:
345 if eigrp_keychain_policy == "" and isinstance(aci.existing, list) and len(aci.existing) > 0:
346 for child in aci.existing[0].get("eigrpIfP", {}).get("children", {}):
347 if child.get("eigrpAuthIfP"):
348 child_configs.append(
349 dict(
350 eigrpAuthIfP=dict(
351 attributes=dict(status="deleted"),
352 ),
353 )
354 )
355 elif eigrp_keychain_policy != "":
356 child_configs.append(
357 dict(
358 eigrpAuthIfP=dict(
359 attributes=dict(),
360 children=[
361 dict(
362 eigrpRsKeyChainPol=dict(
363 attributes=dict(
364 tnFvKeyChainPolName=eigrp_keychain_policy,
365 ),
366 )
367 )
368 ],
369 )
370 )
371 )
372
373 aci.payload(
374 aci_class="eigrpIfP",
375 class_config=dict(
376 descr=description,
377 ),
378 child_configs=child_configs,
379 )
380
381 aci.get_diff(aci_class="eigrpIfP")
382
383 aci.post_config()
384
385 elif state == "absent":
386 aci.delete_config()
387
388 aci.exit_json()
389
390
391 if __name__ == "__main__":
392 main()