Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_bgp_timers_policy.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": "certified"}
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_bgp_timers_policy
16 short_description: Manage BGP timers policy (bgp:CtxPol)
17 description:
18 - Manage BGP timers policies for the Tenants 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 bgp_timers_policy:
26 description:
27 - The name of the BGP timers policy.
28 type: str
29 aliases: [ bgp_timers_policy_name, name ]
30 graceful_restart_controls:
31 description:
32 - The property to determine whether the entity functions only as a graceful restart helper or whether graceful restart is enabled completely.
33 - The graceful restart helper option configures the local BGP router to support the graceful restart of a remote BGP peer.
34 - The complete graceful restart option allows BGP graceful restart to be enabled or disable for an individual neighbor.
35 - The APIC defaults to C(helper) when unset during creation.
36 type: str
37 choices: [ helper, complete ]
38 hold_interval:
39 description:
40 - The time period to wait before declaring the neighbor device down.
41 - The APIC defaults to C(180) when unset during creation.
42 type: int
43 keepalive_interval:
44 description:
45 - The interval time between sending keepalive messages.
46 - The APIC defaults to C(60) when unset during creation.
47 type: int
48 max_as_limit:
49 description:
50 - The maximum AS limit, to discard routes that have excessive AS numbers.
51 - The APIC defaults to C(0) when unset during creation.
52 type: int
53 stale_interval:
54 description:
55 - The maximum time that BGP keeps stale routes from the restarting BGP peer.
56 - The APIC defaults to C(default) which is equal to 300 sec when unset during creation.
57 type: int
58 description:
59 description:
60 - Description for the BGP timers policy.
61 type: str
62 aliases: [ descr ]
63 state:
64 description:
65 - Use C(present) or C(absent) for adding or removing.
66 - Use C(query) for listing an object or multiple objects.
67 type: str
68 choices: [ absent, present, query ]
69 default: present
70 name_alias:
71 description:
72 - The alias for the current object. This relates to the nameAlias field in ACI.
73 type: str
74 extends_documentation_fragment:
75 - cisco.aci.aci
76 - cisco.aci.annotation
77 - cisco.aci.owner
78
79 notes:
80 - The C(tenant) used must exist before using this module in your playbook.
81 The M(cisco.aci.aci_tenant) module can be used for this.
82 seealso:
83 - module: cisco.aci.aci_tenant
84 - name: APIC Management Information Model reference
85 description: More information about the internal APIC class B(bgp:CtxPol).
86 link: https://developer.cisco.com/docs/apic-mim-ref/
87 author:
88 - Gaspard Micol (@gmicol)
89 """
90
91 EXAMPLES = r"""
92 - name: Create a BGP timers policy
93 cisco.aci.aci_bgp_timers_policy:
94 host: apic
95 username: admin
96 password: SomeSecretPassword
97 bgp_timers_policy: my_bgp_timers_policy
98 graceful_restart_controls: complete
99 hold_interval: 360
100 keepalive_interval: 120
101 max_as_limit: 1
102 stale_interval: 600
103 tenant: production
104 state: present
105 delegate_to: localhost
106
107 - name: Delete a BGP timers policy
108 cisco.aci.aci_bgp_timers_policy:
109 host: apic
110 username: admin
111 password: SomeSecretPassword
112 bgp_timers_policy: my_bgp_timers_policy
113 tenant: production
114 state: absent
115 delegate_to: localhost
116
117 - name: Query all BGP timers policies
118 cisco.aci.aci_bgp_timers_policy:
119 host: apic
120 username: admin
121 password: SomeSecretPassword
122 state: query
123 delegate_to: localhost
124 register: query_result
125
126 - name: Query a specific BGP timers policy
127 cisco.aci.aci_bgp_timers_policy:
128 host: apic
129 username: admin
130 password: SomeSecretPassword
131 bgp_timers_policy: my_bgp_timers_policy
132 tenant: production
133 state: query
134 delegate_to: localhost
135 register: query_result
136 """
137
138 RETURN = r"""
139 current:
140 description: The existing configuration from the APIC after the module has finished
141 returned: success
142 type: list
143 sample:
144 [
145 {
146 "fvTenant": {
147 "attributes": {
148 "descr": "Production environment",
149 "dn": "uni/tn-production",
150 "name": "production",
151 "nameAlias": "",
152 "ownerKey": "",
153 "ownerTag": ""
154 }
155 }
156 }
157 ]
158 error:
159 description: The error information as returned from the APIC
160 returned: failure
161 type: dict
162 sample:
163 {
164 "code": "122",
165 "text": "unknown managed object class foo"
166 }
167 raw:
168 description: The raw output returned by the APIC REST API (xml or json)
169 returned: parse error
170 type: str
171 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
172 sent:
173 description: The actual/minimal configuration pushed to the APIC
174 returned: info
175 type: list
176 sample:
177 {
178 "fvTenant": {
179 "attributes": {
180 "descr": "Production environment"
181 }
182 }
183 }
184 previous:
185 description: The original configuration from the APIC before the module has started
186 returned: info
187 type: list
188 sample:
189 [
190 {
191 "fvTenant": {
192 "attributes": {
193 "descr": "Production",
194 "dn": "uni/tn-production",
195 "name": "production",
196 "nameAlias": "",
197 "ownerKey": "",
198 "ownerTag": ""
199 }
200 }
201 }
202 ]
203 proposed:
204 description: The assembled configuration from the user-provided parameters
205 returned: info
206 type: dict
207 sample:
208 {
209 "fvTenant": {
210 "attributes": {
211 "descr": "Production environment",
212 "name": "production"
213 }
214 }
215 }
216 filter_string:
217 description: The filter string used for the request
218 returned: failure or debug
219 type: str
220 sample: ?rsp-prop-include=config-only
221 method:
222 description: The HTTP method used for the request to the APIC
223 returned: failure or debug
224 type: str
225 sample: POST
226 response:
227 description: The HTTP response from the APIC
228 returned: failure or debug
229 type: str
230 sample: OK (30 bytes)
231 status:
232 description: The HTTP status from the APIC
233 returned: failure or debug
234 type: int
235 sample: 200
236 url:
237 description: The HTTP url used for the request to the APIC
238 returned: failure or debug
239 type: str
240 sample: https://10.11.12.13/api/mo/uni/tn-production.json
241 """
242
243 from ansible.module_utils.basic import AnsibleModule
244 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
245 from ansible_collections.cisco.aci.plugins.module_utils.constants import MATCH_GRACEFUL_RESTART_CONTROLS_MAPPING
246
247
248 def main():
249 argument_spec = aci_argument_spec()
250 argument_spec.update(aci_annotation_spec())
251 argument_spec.update(aci_owner_spec())
252 argument_spec.update(
253 tenant=dict(type="str", aliases=["tenant_name"]), # Not required for querying all objects
254 bgp_timers_policy=dict(type="str", aliases=["bgp_timers_policy_name", "name"]), # Not required for querying all objects
255 graceful_restart_controls=dict(type="str", choices=["helper", "complete"]),
256 hold_interval=dict(type="int"),
257 keepalive_interval=dict(type="int"),
258 max_as_limit=dict(type="int"),
259 stale_interval=dict(type="int"),
260 description=dict(type="str", aliases=["descr"]),
261 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
262 name_alias=dict(type="str"),
263 )
264
265 module = AnsibleModule(
266 argument_spec=argument_spec,
267 supports_check_mode=True,
268 required_if=[
269 ["state", "absent", ["bgp_timers_policy", "tenant"]],
270 ["state", "present", ["bgp_timers_policy", "tenant"]],
271 ],
272 )
273
274 bgp_timers_policy = module.params.get("bgp_timers_policy")
275 graceful_restart_controls = MATCH_GRACEFUL_RESTART_CONTROLS_MAPPING.get(module.params.get("graceful_restart_controls"))
276 hold_interval = module.params.get("hold_interval")
277 keepalive_interval = module.params.get("keepalive_interval")
278 max_as_limit = module.params.get("max_as_limit")
279 stale_interval = module.params.get("stale_interval")
280 description = module.params.get("description")
281 state = module.params.get("state")
282 tenant = module.params.get("tenant")
283 name_alias = module.params.get("name_alias")
284
285 aci = ACIModule(module)
286
287 aci.construct_url(
288 root_class=dict(
289 aci_class="fvTenant",
290 aci_rn="tn-{0}".format(tenant),
291 module_object=tenant,
292 target_filter={"name": tenant},
293 ),
294 subclass_1=dict(
295 aci_class="bgpCtxPol",
296 aci_rn="bgpCtxP-{0}".format(bgp_timers_policy),
297 module_object=bgp_timers_policy,
298 target_filter={"name": bgp_timers_policy},
299 ),
300 )
301
302 aci.get_existing()
303
304 if state == "present":
305 aci.payload(
306 aci_class="bgpCtxPol",
307 class_config=dict(
308 name=bgp_timers_policy,
309 grCtrl=graceful_restart_controls,
310 holdIntvl=hold_interval,
311 kaIntvl=keepalive_interval,
312 maxAsLimit=max_as_limit,
313 staleIntvl=stale_interval,
314 descr=description,
315 nameAlias=name_alias,
316 ),
317 )
318
319 aci.get_diff(aci_class="bgpCtxPol")
320
321 aci.post_config()
322
323 elif state == "absent":
324 aci.delete_config()
325
326 aci.exit_json()
327
328
329 if __name__ == "__main__":
330 main()