ansible  2.9.27
About: Ansible is an IT Configuration Management, Deployment \
About: Ansible (2.x) is an IT Configuration Management, Deployment & Orchestration tool.
ansible download page.
  Fossies Dox: ansible-2.9.27.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

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