Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_bfd_multihop_node_policy.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_bfd_multihop_node_policy
16 short_description: Manage BFD Multihop Node policies (bfd:MhNodePol)
17 description:
18 - Manage BFD Multihop Node 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 Multihop Node policy
28 type: str
29 aliases: [ bfd_multihop_node_policy ]
30 description:
31 description:
32 - Description of the BFD Multihop Node policy
33 type: str
34 admin_state:
35 description:
36 - Admin state of the BFD Multihop Node 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 Multihop Node 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 Multihop Node policy
49 - APIC sets the default value to 250
50 - Allowed range is 250-999
51 type: int
52 min_receive_interval:
53 description:
54 - Minimum receive (Rx) interval of the BFD Multihop Node policy
55 - APIC sets the default value to 250
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:MhNodePol)
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 Multihop Node policy
83 cisco.aci.aci_bfd_multihop_node_policy:
84 host: apic
85 username: admin
86 password: SomeSecretPassword
87 tenant: ansible_tenant
88 name: ansible_bfd_multihop_node_policy
89 description: Ansible BFD Multihop Node Policy
90 state: present
91 delegate_to: localhost
92
93 - name: Remove a BFD Multihop Node policy
94 cisco.aci.aci_bfd_multihop_node_policy:
95 host: apic
96 username: admin
97 password: SomeSecretPassword
98 tenant: ansible_tenant
99 name: ansible_bfd_multihop_node_policy
100 state: absent
101 delegate_to: localhost
102
103 - name: Query a BFD Multihop Node policy
104 cisco.aci.aci_bfd_multihop_node_policy:
105 host: apic
106 username: admin
107 password: SomeSecretPassword
108 tenant: ansible_tenant
109 name: my_dhcp_relay
110 state: query
111 delegate_to: localhost
112 register: query_result
113
114 - name: Query all BFD Multihop Node policies in a specific tenant
115 cisco.aci.aci_bfd_multihop_node_policy:
116 host: apic
117 username: admin
118 password: SomeSecretPassword
119 tenant: ansible_tenant
120 state: query
121 delegate_to: localhost
122 register: query_result
123 """
124
125 RETURN = r"""
126 current:
127 description: The existing configuration from the APIC after the module has finished
128 returned: success
129 type: list
130 sample:
131 [
132 {
133 "fvTenant": {
134 "attributes": {
135 "descr": "Production environment",
136 "dn": "uni/tn-production",
137 "name": "production",
138 "nameAlias": "",
139 "ownerKey": "",
140 "ownerTag": ""
141 }
142 }
143 }
144 ]
145 error:
146 description: The error information as returned from the APIC
147 returned: failure
148 type: dict
149 sample:
150 {
151 "code": "122",
152 "text": "unknown managed object class foo"
153 }
154 raw:
155 description: The raw output returned by the APIC REST API (xml or json)
156 returned: parse error
157 type: str
158 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class "/></imdata>'
159 sent:
160 description: The actual/minimal configuration pushed to the APIC
161 returned: info
162 type: list
163 sample:
164 {
165 "fvTenant": {
166 "attributes": {
167 "descr": "Production environment"
168 }
169 }
170 }
171 previous:
172 description: The original configuration from the APIC before the module has started
173 returned: info
174 type: list
175 sample:
176 [
177 {
178 "fvTenant": {
179 "attributes": {
180 "descr": "Production",
181 "dn": "uni/tn-production",
182 "name": "production",
183 "nameAlias": "",
184 "ownerKey": "",
185 "ownerTag": ""
186 }
187 }
188 }
189 ]
190 proposed:
191 description: The assembled configuration from the user-provided parameters
192 returned: info
193 type: dict
194 sample:
195 {
196 "fvTenant": {
197 "attributes": {
198 "descr": "Production environment",
199 "name": "production"
200 }
201 }
202 }
203 filter_string:
204 description: The filter string used for the request
205 returned: failure or debug
206 type: str
207 sample: ?rsp-prop-include=config-only
208 method:
209 description: The HTTP method used for the request to the APIC
210 returned: failure or debug
211 type: str
212 sample: POST
213 response:
214 description: The HTTP response from the APIC
215 returned: failure or debug
216 type: str
217 sample: OK (30 bytes)
218 status:
219 description: The HTTP status from the APIC
220 returned: failure or debug
221 type: int
222 sample: 200
223 url:
224 description: The HTTP url used for the request to the APIC
225 returned: failure or debug
226 type: str
227 sample: https://10.11.12.13/api/mo/uni/tn-production.json
228 """
229
230 from ansible.module_utils.basic import AnsibleModule
231 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
232
233
234 def main():
235 argument_spec = aci_argument_spec()
236 argument_spec.update(aci_annotation_spec())
237 argument_spec.update(
238 name=dict(type="str", aliases=["bfd_multihop_node_policy"]),
239 description=dict(type="str"),
240 admin_state=dict(type="str", choices=["enabled", "disabled"]),
241 detection_multiplier=dict(type="int"),
242 min_transmit_interval=dict(type="int"),
243 min_receive_interval=dict(type="int"),
244 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
245 tenant=dict(type="str"),
246 )
247
248 module = AnsibleModule(
249 argument_spec=argument_spec,
250 supports_check_mode=True,
251 required_if=[
252 ["state", "absent", ["name", "tenant"]],
253 ["state", "present", ["name", "tenant"]],
254 ],
255 )
256
257 name = module.params.get("name")
258 description = module.params.get("description")
259 state = module.params.get("state")
260 tenant = module.params.get("tenant")
261 admin_state = module.params.get("admin_state")
262 detection_multiplier = module.params.get("detection_multiplier")
263 min_transmit_interval = module.params.get("min_transmit_interval")
264 min_receive_interval = module.params.get("min_receive_interval")
265
266 aci = ACIModule(module)
267 aci.construct_url(
268 root_class=dict(
269 aci_class="fvTenant",
270 aci_rn="tn-{0}".format(tenant),
271 module_object=tenant,
272 target_filter={"name": tenant},
273 ),
274 subclass_1=dict(
275 aci_class="bfdMhNodePol",
276 aci_rn="bfdMhNodePol-{0}".format(name),
277 module_object=name,
278 target_filter={"name": name},
279 ),
280 )
281
282 aci.get_existing()
283
284 if state == "present":
285 class_config = dict(
286 name=name,
287 descr=description,
288 adminSt=admin_state,
289 )
290
291 if detection_multiplier and detection_multiplier not in range(1, 50):
292 aci.fail_json(msg='The "detection_multiplier" must be a value between 1 and 50')
293 else:
294 class_config["detectMult"] = detection_multiplier
295 if min_transmit_interval and min_transmit_interval not in range(250, 999):
296 aci.fail_json(msg='The "min_transmit_interval" must be a value between 250 and 999')
297 else:
298 class_config["minTxIntvl"] = min_transmit_interval
299 if min_receive_interval and min_receive_interval not in range(250, 999):
300 aci.fail_json(msg='The "min_receive_interval" must be a value between 250 and 999')
301 else:
302 class_config["minRxIntvl"] = min_receive_interval
303
304 aci.payload(
305 aci_class="bfdMhNodePol",
306 class_config=class_config,
307 )
308
309 aci.get_diff(aci_class="bfdMhNodePol")
310
311 aci.post_config()
312
313 elif state == "absent":
314 aci.delete_config()
315
316 aci.exit_json()
317
318
319 if __name__ == "__main__":
320 main()