Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2022, Lukas Holub (@lukasholub)
5 # Copyright: (c) 2023, Gaspard Micol (@gmicol) <[email protected]>
6 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
7
8 from __future__ import absolute_import, division, print_function
9
10 __metaclass__ = type
11
12 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"}
13
14 DOCUMENTATION = r"""
15 ---
16 module: aci_interface_policy_eigrp
17 short_description: Manage EIGRP interface policies (eigrp:IfPol)
18 description:
19 - Manage EIGRP interface policies for Tenants on Cisco ACI fabrics.
20 options:
21 tenant:
22 description:
23 - The name of an existing Tenant.
24 type: str
25 aliases: [ tenant_name ]
26 eigrp:
27 description:
28 - The EIGRP interface policy name.
29 - Note that you cannot change this name after the object has been created.
30 type: str
31 aliases: [ eigrp_interface, name ]
32 bandwidth:
33 description:
34 - The EIGRP bandwidth in kbps, overrides the bandwidth configured on an interface.
35 - This is used to influence path selection.
36 - Accepted values range between C(0) and C(2560000000).
37 - The APIC defaults to C(0) when unset during creation.
38 type: int
39 control_state:
40 description:
41 - The interface policy control state.
42 - 'This is a list of one or more of the following controls:'
43 - C(bfd) -- Enable Bidirectional Forwarding Detection.
44 - C(nexthop_self) -- Nexthop Self.
45 - C(split_horizon) -- Split Horizon.
46 - C(passive) -- The interface does not participate in the EIGRP protocol and
47 will not establish adjacencies or send routing updates.
48 - The APIC defaults to C([split_horizon, nexthop_self]) when unset during creation.
49 type: list
50 elements: str
51 choices: [ bfd, nexthop_self, passive, split_horizon ]
52 delay:
53 description:
54 - The EIGRP throughput delay, overrides the delay configured on an interface.
55 - This is used to influence path selection.
56 - The APIC defaults to C(0) when unset during creation.
57 type: int
58 delay_unit:
59 description:
60 - The EIGRP delay units, Wide metrics can use picoseconds accuracy for delay.
61 - The APIC defaults to C(tens_of_microseconds) when unset during creation.
62 type: str
63 choices: [ picoseconds, tens_of_microseconds ]
64 hello_interval:
65 description:
66 - The time interval in seconds between hello packets that EIGRP sends on the interface.
67 - The smaller the hello interval, the faster topological changes will be detected, but more routing traffic will ensue.
68 - Accepted values range between C(1) and C(65535).
69 - The APIC defaults to C(5) when unset during creation.
70 type: int
71 hold_interval:
72 description:
73 - The time period of time in seconds before declaring that the neighbor is down.
74 - Accepted values range between C(1) and C(65535).
75 - The APIC defaults to C(15) when unset during creation.
76 type: int
77 description:
78 description:
79 - The description of the EIGRP interface policy.
80 type: str
81 aliases: [ descr ]
82 state:
83 description:
84 - Use C(present) or C(absent) for adding or removing.
85 - Use C(query) for listing an object or multiple objects.
86 type: str
87 choices: [ absent, present, query ]
88 default: present
89 name_alias:
90 description:
91 - The alias for the current object. This relates to the nameAlias field in ACI.
92 type: str
93 extends_documentation_fragment:
94 - cisco.aci.aci
95 - cisco.aci.annotation
96 - cisco.aci.owner
97
98 notes:
99 - The C(tenant) used must exist before using this module in your playbook.
100 - The M(cisco.aci.aci_tenant) module can be used for this.
101 seealso:
102 - module: cisco.aci.aci_tenant
103 - name: APIC Management Information Model reference
104 description: More information about the internal APIC class B(eigrp:IfPol).
105 link: https://developer.cisco.com/docs/apic-mim-ref/
106 author:
107 - Gaspard Micol (@gmicol)
108 - Lukas Holub (@lukasholub)
109 """
110
111 EXAMPLES = r"""
112 - name: Create an EIGRP interface policy
113 cisco.aci.aci_interface_policy_eigrp:
114 host: apic
115 username: admin
116 password: SomeSecretPassword
117 tenant: production
118 eigrp: eigrp1
119 bandwidth: 10000
120 control_state: [split-horizon, nh-self]
121 delay: 10
122 delay_unit: tens_of_micro
123 hello_interval: 5
124 hold_interval: 15
125 state: present
126 delegate_to: localhost
127
128 - name: Delete EIGRRP interface policy
129 cisco.aci.aci_interface_policy_eigrp:
130 host: apic
131 username: admin
132 password: SomeSecretPassword
133 tenant: production
134 eigrp: eigrp1
135 state: present
136 delegate_to: localhost
137
138 - name: Query an EIGRRP interface policy
139 cisco.aci.aci_interface_policy_eigrp:
140 host: apic
141 username: admin
142 password: SomeSecretPassword
143 tenant: production
144 eigrp: eigrp1
145 state: query
146 delegate_to: localhost
147 register: query_result
148
149 - name: Query all EIGRP interface policies in tenant production
150 cisco.aci.aci_interface_policy_eigrp:
151 host: apic
152 username: admin
153 password: SomeSecretPassword
154 tenant: production
155 state: query
156 delegate_to: localhost
157 register: query_result
158 """
159
160 RETURN = r"""
161 current:
162 description: The existing configuration from the APIC after the module has finished
163 returned: success
164 type: list
165 sample:
166 [
167 {
168 "fvTenant": {
169 "attributes": {
170 "descr": "Production environment",
171 "dn": "uni/tn-production",
172 "name": "production",
173 "nameAlias": "",
174 "ownerKey": "",
175 "ownerTag": ""
176 }
177 }
178 }
179 ]
180 error:
181 description: The error information as returned from the APIC
182 returned: failure
183 type: dict
184 sample:
185 {
186 "code": "122",
187 "text": "unknown managed object class foo"
188 }
189 raw:
190 description: The raw output returned by the APIC REST API (xml or json)
191 returned: parse error
192 type: str
193 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
194 sent:
195 description: The actual/minimal configuration pushed to the APIC
196 returned: info
197 type: list
198 sample:
199 {
200 "fvTenant": {
201 "attributes": {
202 "descr": "Production environment"
203 }
204 }
205 }
206 previous:
207 description: The original configuration from the APIC before the module has started
208 returned: info
209 type: list
210 sample:
211 [
212 {
213 "fvTenant": {
214 "attributes": {
215 "descr": "Production",
216 "dn": "uni/tn-production",
217 "name": "production",
218 "nameAlias": "",
219 "ownerKey": "",
220 "ownerTag": ""
221 }
222 }
223 }
224 ]
225 proposed:
226 description: The assembled configuration from the user-provided parameters
227 returned: info
228 type: dict
229 sample:
230 {
231 "fvTenant": {
232 "attributes": {
233 "descr": "Production environment",
234 "name": "production"
235 }
236 }
237 }
238 filter_string:
239 description: The filter string used for the request
240 returned: failure or debug
241 type: str
242 sample: ?rsp-prop-include=config-only
243 method:
244 description: The HTTP method used for the request to the APIC
245 returned: failure or debug
246 type: str
247 sample: POST
248 response:
249 description: The HTTP response from the APIC
250 returned: failure or debug
251 type: str
252 sample: OK (30 bytes)
253 status:
254 description: The HTTP status from the APIC
255 returned: failure or debug
256 type: int
257 sample: 200
258 url:
259 description: The HTTP url used for the request to the APIC
260 returned: failure or debug
261 type: str
262 sample: https://10.11.12.13/api/mo/uni/tn-production.json
263 """
264
265 from ansible.module_utils.basic import AnsibleModule
266 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
267 from ansible_collections.cisco.aci.plugins.module_utils.constants import (
268 MATCH_EIGRP_INTERFACE_POLICY_DELAY_UNIT_MAPPING,
269 MATCH_EIGRP_INTERFACE_POLICY_CONTROL_STATE_MAPPING,
270 )
271
272
273 def main():
274 argument_spec = aci_argument_spec()
275 argument_spec.update(aci_annotation_spec())
276 argument_spec.update(aci_owner_spec())
277 argument_spec.update(
278 tenant=dict(type="str", aliases=["tenant_name"]), # Not required for querying all objects
279 eigrp=dict(type="str", aliases=["eigrp_interface", "name"]), # Not required for querying all objects
280 description=dict(type="str", aliases=["descr"]),
281 bandwidth=dict(type="int"),
282 control_state=dict(type="list", elements="str", choices=["bfd", "nexthop_self", "passive", "split_horizon"]),
283 delay=dict(type="int"),
284 delay_unit=dict(type="str", choices=["picoseconds", "tens_of_microseconds"]),
285 hello_interval=dict(type="int"),
286 hold_interval=dict(type="int"),
287 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
288 name_alias=dict(type="str"),
289 )
290
291 module = AnsibleModule(
292 argument_spec=argument_spec,
293 supports_check_mode=True,
294 required_if=[
295 ["state", "absent", ["eigrp", "tenant"]],
296 ["state", "present", ["eigrp", "tenant"]],
297 ],
298 )
299
300 aci = ACIModule(module)
301
302 tenant = module.params.get("tenant")
303 eigrp = module.params.get("eigrp")
304 delay = module.params.get("delay")
305 delay_unit = MATCH_EIGRP_INTERFACE_POLICY_DELAY_UNIT_MAPPING.get(module.params.get("delay_unit"))
306 description = module.params.get("description")
307 name_alias = module.params.get("name_alias")
308 state = module.params.get("state")
309
310 bandwidth = module.params.get("bandwidth")
311 if bandwidth is not None and bandwidth not in range(2560000001):
312 module.fail_json(msg="Parameter 'bandwidth' is only valid in range between 0 and 2560000000.")
313
314 hello_interval = module.params.get("hello_interval")
315 if hello_interval is not None and hello_interval not in range(1, 65536):
316 module.fail_json(msg="Parameter 'hello_interval' is only valid in range between 1 and 65535.")
317
318 hold_interval = module.params.get("hold_interval")
319 if hold_interval is not None and hold_interval not in range(1, 65536):
320 module.fail_json(msg="Parameter 'hold_interval' is only valid in range between 1 and 65535.")
321
322 if module.params.get("control_state"):
323 control_state = ",".join([MATCH_EIGRP_INTERFACE_POLICY_CONTROL_STATE_MAPPING.get(v) for v in module.params.get("control_state")])
324 else:
325 control_state = None
326
327 aci.construct_url(
328 root_class=dict(
329 aci_class="fvTenant",
330 aci_rn="tn-{0}".format(tenant),
331 module_object=tenant,
332 target_filter={"name": tenant},
333 ),
334 subclass_1=dict(
335 aci_class="eigrpIfPol",
336 aci_rn="eigrpIfPol-{0}".format(eigrp),
337 module_object=eigrp,
338 target_filter={"name": eigrp},
339 ),
340 )
341
342 aci.get_existing()
343
344 if state == "present":
345 aci.payload(
346 aci_class="eigrpIfPol",
347 class_config=dict(
348 name=eigrp,
349 descr=description,
350 bw=bandwidth,
351 ctrl=control_state,
352 delay=delay,
353 delayUnit=delay_unit,
354 helloIntvl=hello_interval,
355 holdIntvl=hold_interval,
356 nameAlias=name_alias,
357 ),
358 )
359
360 aci.get_diff(aci_class="eigrpIfPol")
361
362 aci.post_config()
363
364 elif state == "absent":
365 aci.delete_config()
366
367 aci.exit_json()
368
369
370 if __name__ == "__main__":
371 main()