Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2018, Dag Wieers (dagwieers) <[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": "certified"}
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_interface_policy_ospf
16 short_description: Manage OSPF interface policies (ospf:IfPol)
17 description:
18 - Manage OSPF interface policies on Cisco ACI fabrics.
19 options:
20 tenant:
21 description:
22 - The name of the Tenant the OSPF interface policy should belong to.
23 type: str
24 aliases: [ tenant_name ]
25 ospf:
26 description:
27 - The OSPF interface policy name.
28 - This name can be between 1 and 64 alphanumeric characters.
29 - Note that you cannot change this name after the object has been saved.
30 type: str
31 aliases: [ ospf_interface, name ]
32 description:
33 description:
34 - The description of the OSPF interface.
35 type: str
36 aliases: [ descr ]
37 network_type:
38 description:
39 - The OSPF interface policy network type.
40 - OSPF supports broadcast and point-to-point.
41 - The APIC defaults to C(unspecified) when unset during creation.
42 type: str
43 choices: [ bcast, p2p, unspecified ]
44 cost:
45 description:
46 - The OSPF cost of the interface.
47 - The cost (also called metric) of an interface in OSPF is an indication of
48 the overhead required to send packets across a certain interface. The
49 cost of an interface is inversely proportional to the bandwidth of that
50 interface. A higher bandwidth indicates a lower cost. There is more
51 overhead (higher cost) and time delays involved in crossing a 56k serial
52 line than crossing a 10M ethernet line. The formula used to calculate the
53 cost is C(cost= 10000 0000/bandwith in bps) For example, it will cost
54 10 EXP8/10 EXP7 = 10 to cross a 10M Ethernet line and will cost
55 10 EXP8/1544000 = 64 to cross a T1 line.
56 - By default, the cost of an interface is calculated based on the bandwidth;
57 you can force the cost of an interface with the ip ospf cost value
58 interface subconfiguration mode command.
59 - Accepted values range between C(1) and C(450).
60 - The APIC defaults to C(0) when unset during creation.
61 type: int
62 controls:
63 description:
64 - The interface policy controls.
65 - 'This is a list of one or more of the following controls:'
66 - C(advert-subnet) -- Advertise IP subnet instead of a host mask in the router LSA.
67 - C(bfd) -- Bidirectional Forwarding Detection
68 - C(mtu-ignore) -- Disables MTU mismatch detection on an interface.
69 - C(passive) -- The interface does not participate in the OSPF protocol and
70 will not establish adjacencies or send routing updates. However the
71 interface is announced as part of the routing network.
72 type: list
73 elements: str
74 choices: [ advert-subnet, bfd, mtu-ignore, passive, unspecified ]
75 dead_interval:
76 description:
77 - The interval between hello packets from a neighbor before the router
78 declares the neighbor as down.
79 - This value must be the same for all networking devices on a specific network.
80 - Specifying a smaller dead interval (seconds) will give faster detection
81 of a neighbor being down and improve convergence, but might cause more
82 routing instability.
83 - Accepted values range between C(1) and C(65535).
84 - The APIC defaults to C(40) when unset during creation.
85 type: int
86 hello_interval:
87 description:
88 - The interval between hello packets that OSPF sends on the interface.
89 - Note that the smaller the hello interval, the faster topological changes will be detected, but more routing traffic will ensue.
90 - This value must be the same for all routers and access servers on a specific network.
91 - Accepted values range between C(1) and C(65535).
92 - The APIC defaults to C(10) when unset during creation.
93 type: int
94 prefix_suppression:
95 description:
96 - Whether prefix suppressions is enabled or disabled.
97 - The APIC defaults to C(inherit) when unset during creation.
98 type: str
99 choices: [ inherit, enable, disable ]
100 priority:
101 description:
102 - The priority for the OSPF interface profile.
103 - Accepted values ranges between C(0) and C(255).
104 - The APIC defaults to C(1) when unset during creation.
105 type: int
106 retransmit_interval:
107 description:
108 - The interval between LSA retransmissions.
109 - The retransmit interval occurs while the router is waiting for an acknowledgement from the neighbor router that it received the LSA.
110 - If no acknowledgment is received at the end of the interval, then the LSA is resent.
111 - Accepted values range between C(1) and C(65535).
112 - The APIC defaults to C(5) when unset during creation.
113 type: int
114 transmit_delay:
115 description:
116 - The delay time needed to send an LSA update packet.
117 - OSPF increments the LSA age time by the transmit delay amount before transmitting the LSA update.
118 - You should take into account the transmission and propagation delays for the interface when you set this value.
119 - Accepted values range between C(1) and C(450).
120 - The APIC defaults to C(1) when unset during creation.
121 type: int
122 state:
123 description:
124 - Use C(present) or C(absent) for adding or removing.
125 - Use C(query) for listing an object or multiple objects.
126 type: str
127 choices: [ absent, present, query ]
128 default: present
129 name_alias:
130 description:
131 - The alias for the current object. This relates to the nameAlias field in ACI.
132 type: str
133 extends_documentation_fragment:
134 - cisco.aci.aci
135 - cisco.aci.annotation
136 - cisco.aci.owner
137
138 seealso:
139 - name: APIC Management Information Model reference
140 description: More information about the internal APIC class B(ospf:IfPol).
141 link: https://developer.cisco.com/docs/apic-mim-ref/
142 author:
143 - Dag Wieers (@dagwieers)
144 """
145
146 EXAMPLES = r"""
147 - name: Ensure ospf interface policy exists
148 cisco.aci.aci_interface_policy_ospf:
149 host: apic
150 username: admin
151 password: SomeSecretPassword
152 tenant: production
153 ospf: ospf1
154 state: present
155 delegate_to: localhost
156
157 - name: Ensure ospf interface policy does not exist
158 cisco.aci.aci_interface_policy_ospf:
159 host: apic
160 username: admin
161 password: SomeSecretPassword
162 tenant: production
163 ospf: ospf1
164 state: present
165 delegate_to: localhost
166
167 - name: Query an ospf interface policy
168 cisco.aci.aci_interface_policy_ospf:
169 host: apic
170 username: admin
171 password: SomeSecretPassword
172 tenant: production
173 ospf: ospf1
174 state: query
175 delegate_to: localhost
176 register: query_result
177
178 - name: Query all ospf interface policies in tenant production
179 cisco.aci.aci_interface_policy_ospf:
180 host: apic
181 username: admin
182 password: SomeSecretPassword
183 tenant: production
184 state: query
185 delegate_to: localhost
186 register: query_result
187 """
188
189 RETURN = r"""
190 current:
191 description: The existing configuration from the APIC after the module has finished
192 returned: success
193 type: list
194 sample:
195 [
196 {
197 "fvTenant": {
198 "attributes": {
199 "descr": "Production environment",
200 "dn": "uni/tn-production",
201 "name": "production",
202 "nameAlias": "",
203 "ownerKey": "",
204 "ownerTag": ""
205 }
206 }
207 }
208 ]
209 error:
210 description: The error information as returned from the APIC
211 returned: failure
212 type: dict
213 sample:
214 {
215 "code": "122",
216 "text": "unknown managed object class foo"
217 }
218 raw:
219 description: The raw output returned by the APIC REST API (xml or json)
220 returned: parse error
221 type: str
222 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
223 sent:
224 description: The actual/minimal configuration pushed to the APIC
225 returned: info
226 type: list
227 sample:
228 {
229 "fvTenant": {
230 "attributes": {
231 "descr": "Production environment"
232 }
233 }
234 }
235 previous:
236 description: The original configuration from the APIC before the module has started
237 returned: info
238 type: list
239 sample:
240 [
241 {
242 "fvTenant": {
243 "attributes": {
244 "descr": "Production",
245 "dn": "uni/tn-production",
246 "name": "production",
247 "nameAlias": "",
248 "ownerKey": "",
249 "ownerTag": ""
250 }
251 }
252 }
253 ]
254 proposed:
255 description: The assembled configuration from the user-provided parameters
256 returned: info
257 type: dict
258 sample:
259 {
260 "fvTenant": {
261 "attributes": {
262 "descr": "Production environment",
263 "name": "production"
264 }
265 }
266 }
267 filter_string:
268 description: The filter string used for the request
269 returned: failure or debug
270 type: str
271 sample: ?rsp-prop-include=config-only
272 method:
273 description: The HTTP method used for the request to the APIC
274 returned: failure or debug
275 type: str
276 sample: POST
277 response:
278 description: The HTTP response from the APIC
279 returned: failure or debug
280 type: str
281 sample: OK (30 bytes)
282 status:
283 description: The HTTP status from the APIC
284 returned: failure or debug
285 type: int
286 sample: 200
287 url:
288 description: The HTTP url used for the request to the APIC
289 returned: failure or debug
290 type: str
291 sample: https://10.11.12.13/api/mo/uni/tn-production.json
292 """
293
294 from ansible.module_utils.basic import AnsibleModule
295 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
296
297
298 def main():
299 argument_spec = aci_argument_spec()
300 argument_spec.update(aci_annotation_spec())
301 argument_spec.update(aci_owner_spec())
302 argument_spec.update(
303 tenant=dict(type="str", aliases=["tenant_name"]), # Not required for querying all objects
304 ospf=dict(type="str", aliases=["ospf_interface", "name"]), # Not required for querying all objects
305 description=dict(type="str", aliases=["descr"]),
306 network_type=dict(type="str", choices=["bcast", "p2p", "unspecified"]),
307 cost=dict(type="int"),
308 controls=dict(type="list", elements="str", choices=["advert-subnet", "bfd", "mtu-ignore", "passive", "unspecified"]),
309 dead_interval=dict(type="int"),
310 hello_interval=dict(type="int"),
311 prefix_suppression=dict(type="str", choices=["inherit", "enable", "disable"]),
312 priority=dict(type="int"),
313 retransmit_interval=dict(type="int"),
314 transmit_delay=dict(type="int"),
315 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
316 name_alias=dict(type="str"),
317 )
318
319 module = AnsibleModule(
320 argument_spec=argument_spec,
321 supports_check_mode=True,
322 required_if=[
323 ["state", "absent", ["ospf", "tenant"]],
324 ["state", "present", ["ospf", "tenant"]],
325 ],
326 )
327
328 aci = ACIModule(module)
329
330 tenant = module.params.get("tenant")
331 ospf = module.params.get("ospf")
332 description = module.params.get("description")
333 name_alias = module.params.get("name_alias")
334 network_type = module.params.get("network_type")
335 prefix_suppression = module.params.get("prefix_suppression")
336 controls = ",".join(module.params.get("controls")) if module.params.get("controls") else None
337
338 cost = module.params.get("cost")
339 if cost is not None and cost not in range(1, 451):
340 module.fail_json(msg="Parameter 'cost' is only valid in range between 1 and 450.")
341
342 dead_interval = module.params.get("dead_interval")
343 if dead_interval is not None and dead_interval not in range(1, 65536):
344 module.fail_json(msg="Parameter 'dead_interval' is only valid in range between 1 and 65536.")
345
346 hello_interval = module.params.get("hello_interval")
347 if hello_interval is not None and hello_interval not in range(1, 65536):
348 module.fail_json(msg="Parameter 'hello_interval' is only valid in range between 1 and 65536.")
349
350 priority = module.params.get("priority")
351 if priority is not None and priority not in range(0, 256):
352 module.fail_json(msg="Parameter 'priority' is only valid in range between 1 and 255.")
353
354 retransmit_interval = module.params.get("retransmit_interval")
355 if retransmit_interval is not None and retransmit_interval not in range(1, 65536):
356 module.fail_json(msg="Parameter 'retransmit_interval' is only valid in range between 1 and 65536.")
357
358 transmit_delay = module.params.get("transmit_delay")
359 if transmit_delay is not None and transmit_delay not in range(1, 451):
360 module.fail_json(msg="Parameter 'transmit_delay' is only valid in range between 1 and 450.")
361
362 state = module.params.get("state")
363
364 aci.construct_url(
365 root_class=dict(
366 aci_class="ospfIfPol",
367 aci_rn="tn-{0}/ospfIfPol-{1}".format(tenant, ospf),
368 module_object=ospf,
369 target_filter={"name": ospf},
370 ),
371 )
372
373 aci.get_existing()
374
375 if state == "present":
376 aci.payload(
377 aci_class="ospfIfPol",
378 class_config=dict(
379 name=ospf,
380 descr=description,
381 cost=cost,
382 ctrl=controls,
383 deadIntvl=dead_interval,
384 helloIntvl=hello_interval,
385 nwT=network_type,
386 pfxSuppress=prefix_suppression,
387 prio=priority,
388 rexmitIntvl=retransmit_interval,
389 xmitDelay=transmit_delay,
390 nameAlias=name_alias,
391 ),
392 )
393
394 aci.get_diff(aci_class="ospfIfPol")
395
396 aci.post_config()
397
398 elif state == "absent":
399 aci.delete_config()
400
401 aci.exit_json()
402
403
404 if __name__ == "__main__":
405 main()