Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2023, Anvitha Jain (@anvjain) <[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_interface_policy_bfd
16 short_description: Manage BFD Interface policies (bfd:IfPol)
17 description:
18 - Manage BFD Interface policy configuration on Cisco ACI fabrics
19 - Only available in APIC version 5.2 or later
20 options:
21 tenant:
22 description:
23 - Name of an existing tenant
24 type: str
25 name:
26 description:
27 - Name of the BFD Interface policy
28 type: str
29 aliases: [ bfd_interface_policy ]
30 description:
31 description:
32 - Description of the BFD Interface policy
33 type: str
34 admin_state:
35 description:
36 - Admin state of the BFD Interface policy
37 - APIC sets the default value to enabled
38 type: str
39 choices: [ enabled, disabled ]
40 detection_multiplier:
41 description:
42 - Detection multiplier of the BFD Interface policy
43 - APIC sets the default value to 3
44 - Allowed range is 1-50
45 type: int
46 min_transmit_interval:
47 description:
48 - Minimum transmit (Tx) interval of the BFD Interface policy
49 - APIC sets the default value to 50
50 - Allowed range is 250-999
51 type: int
52 min_receive_interval:
53 description:
54 - Minimum receive (Rx) interval of the BFD Interface policy
55 - APIC sets the default value to 50
56 - Allowed range is 250-999
57 type: int
58 state:
59 description:
60 - Use C(present) or C(absent) for adding or removing
61 - Use C(query) for listing an object or multiple objects
62 type: str
63 choices: [ absent, present, query ]
64 default: present
65 extends_documentation_fragment:
66 - cisco.aci.aci
67 - cisco.aci.annotation
68
69 notes:
70 - The C(tenant) must exist before using this module in your playbook
71 The M(cisco.aci.aci_tenant) modules can be used for this
72 seealso:
73 - name: APIC Management Information Model reference
74 description: More information about the internal APIC class B(bfd:IfPol)
75 link: https://developer.cisco.com/docs/apic-mim-ref/
76 - module: cisco.aci.aci_tenant
77 author:
78 - Anvitha Jain (@anvjain)
79 """
80
81 EXAMPLES = r"""
82 - name: Add a new BFD Interface policy
83 cisco.aci.aci_interface_policy_bfd:
84 host: apic
85 username: admin
86 password: SomeSecretPassword
87 tenant: ansible_tenant
88 name: ansible_bfd_interface_policy
89 description: Ansible BFD Interface Policy
90 state: present
91 delegate_to: localhost
92
93 - name: Remove a BFD Interface policy
94 cisco.aci.aci_interface_policy_bfd:
95 host: apic
96 username: admin
97 password: SomeSecretPassword
98 tenant: ansible_tenant
99 name: ansible_bfd_interface_policy
100 state: absent
101 delegate_to: localhost
102
103 - name: Query a BFD Interface policy
104 cisco.aci.aci_interface_policy_bfd:
105 host: apic
106 username: admin
107 password: SomeSecretPassword
108 tenant: ansible_tenant
109 name: ansible_bfd_interface_policy
110 state: query
111 delegate_to: localhost
112
113 - name: Query all BFD Interface policies in a specific tenant
114 cisco.aci.aci_interface_policy_bfd:
115 host: apic
116 username: admin
117 password: SomeSecretPassword
118 tenant: ansible_tenant
119 state: query
120 delegate_to: localhost
121 """
122
123 RETURN = r"""
124 current:
125 description: The existing configuration from the APIC after the module has finished
126 returned: success
127 type: list
128 sample:
129 [
130 {
131 "fvTenant": {
132 "attributes": {
133 "descr": "Production environment",
134 "dn": "uni/tn-production",
135 "name": "production",
136 "nameAlias": "",
137 "ownerKey": "",
138 "ownerTag": ""
139 }
140 }
141 }
142 ]
143 error:
144 description: The error information as returned from the APIC
145 returned: failure
146 type: dict
147 sample:
148 {
149 "code": "122",
150 "text": "unknown managed object class foo"
151 }
152 raw:
153 description: The raw output returned by the APIC REST API (xml or json)
154 returned: parse error
155 type: str
156 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class "/></imdata>'
157 sent:
158 description: The actual/minimal configuration pushed to the APIC
159 returned: info
160 type: list
161 sample:
162 {
163 "fvTenant": {
164 "attributes": {
165 "descr": "Production environment"
166 }
167 }
168 }
169 previous:
170 description: The original configuration from the APIC before the module has started
171 returned: info
172 type: list
173 sample:
174 [
175 {
176 "fvTenant": {
177 "attributes": {
178 "descr": "Production",
179 "dn": "uni/tn-production",
180 "name": "production",
181 "nameAlias": "",
182 "ownerKey": "",
183 "ownerTag": ""
184 }
185 }
186 }
187 ]
188 proposed:
189 description: The assembled configuration from the user-provided parameters
190 returned: info
191 type: dict
192 sample:
193 {
194 "fvTenant": {
195 "attributes": {
196 "descr": "Production environment",
197 "name": "production"
198 }
199 }
200 }
201 filter_string:
202 description: The filter string used for the request
203 returned: failure or debug
204 type: str
205 sample: ?rsp-prop-include=config-only
206 method:
207 description: The HTTP method used for the request to the APIC
208 returned: failure or debug
209 type: str
210 sample: POST
211 response:
212 description: The HTTP response from the APIC
213 returned: failure or debug
214 type: str
215 sample: OK (30 bytes)
216 status:
217 description: The HTTP status from the APIC
218 returned: failure or debug
219 type: int
220 sample: 200
221 url:
222 description: The HTTP url used for the request to the APIC
223 returned: failure or debug
224 type: str
225 sample: https://10.11.12.13/api/mo/uni/tn-production.json
226 """
227
228 from ansible.module_utils.basic import AnsibleModule
229 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
230
231
232 def main():
233 argument_spec = aci_argument_spec()
234 argument_spec.update(aci_annotation_spec())
235 argument_spec.update(
236 name=dict(type="str", aliases=["bfd_interface_policy"]),
237 description=dict(type="str"),
238 admin_state=dict(type="str", choices=["enabled", "disabled"]),
239 detection_multiplier=dict(type="int"),
240 min_transmit_interval=dict(type="int"),
241 min_receive_interval=dict(type="int"),
242 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
243 tenant=dict(type="str"),
244 )
245
246 module = AnsibleModule(
247 argument_spec=argument_spec,
248 supports_check_mode=True,
249 required_if=[
250 ["state", "absent", ["name", "tenant"]],
251 ["state", "present", ["name", "tenant"]],
252 ],
253 )
254
255 name = module.params.get("name")
256 description = module.params.get("description")
257 state = module.params.get("state")
258 tenant = module.params.get("tenant")
259 admin_state = module.params.get("admin_state")
260 detection_multiplier = module.params.get("detection_multiplier")
261 min_transmit_interval = module.params.get("min_transmit_interval")
262 min_receive_interval = module.params.get("min_receive_interval")
263
264 aci = ACIModule(module)
265 aci.construct_url(
266 root_class=dict(
267 aci_class="fvTenant",
268 aci_rn="tn-{0}".format(tenant),
269 module_object=tenant,
270 target_filter={"name": tenant},
271 ),
272 subclass_1=dict(
273 aci_class="bfdIfPol",
274 aci_rn="bfdIfPol-{0}".format(name),
275 module_object=name,
276 target_filter={"name": name},
277 ),
278 )
279
280 aci.get_existing()
281
282 if state == "present":
283 class_config = dict(
284 name=name,
285 descr=description,
286 adminSt=admin_state,
287 )
288
289 if detection_multiplier and detection_multiplier not in range(1, 50):
290 module.fail_json(msg='The "detection_multiplier" must be a value between 1 and 50')
291 else:
292 class_config["detectMult"] = detection_multiplier
293 if min_transmit_interval and min_transmit_interval not in range(50, 999):
294 module.fail_json(msg='The "min_transmit_interval" must be a value between 50 and 999')
295 else:
296 class_config["minTxIntvl"] = min_transmit_interval
297 if min_receive_interval and min_receive_interval not in range(50, 999):
298 module.fail_json(msg='The "min_receive_interval" must be a value between 50 and 999')
299 else:
300 class_config["minRxIntvl"] = min_receive_interval
301
302 aci.payload(
303 aci_class="bfdIfPol",
304 class_config=class_config,
305 )
306
307 aci.get_diff(aci_class="bfdIfPol")
308
309 aci.post_config()
310
311 elif state == "absent":
312 aci.delete_config()
313
314 aci.exit_json()
315
316
317 if __name__ == "__main__":
318 main()