Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2025, Tim Cragg (@timcragg)
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_ip_sla_monitoring_policy
16 short_description: Manage IP SLA Monitoring Policies (fv:IPSLAMonitoringPol)
17 description:
18 - Manage Internet Protocol (IP) Service Level Agreement (SLA) Monitoring Policies used for L4-L7 Policy Based Redirection
19 options:
20 tenant:
21 description:
22 - The name of an existing tenant.
23 type: str
24 aliases: [ tenant_name ]
25 name:
26 description:
27 - The SLA Policy name.
28 type: str
29 aliases: [ sla_policy ]
30 description:
31 description:
32 - The SLA Policy description.
33 type: str
34 sla_type:
35 description:
36 - The type of monitoring.
37 - The APIC defaults to C(icmp) when unset during creation.
38 - I(sla_type=http) is only supported in APIC v5.0 and above.
39 type: str
40 choices: [ icmp, tcp, l2ping, http ]
41 sla_port:
42 description:
43 - The Port to monitor for TCP SLAs.
44 - Permitted values are in the range of [1, 65535].
45 type: int
46 aliases: [ destination_port ]
47 frequency:
48 description:
49 - Defines the interval at which probes are conducted.
50 - The APIC defaults to C(60) when unset during creation.
51 - Permitted values are in the range of [1, 300].
52 type: int
53 multiplier:
54 description:
55 - Specifies the number of consecutive probe failures required to determine the SLA as down.
56 - The APIC defaults to C(3) when unset during creation.
57 - Permitted values are in the range of [1, 100].
58 type: int
59 aliases: [ detect_multiplier ]
60 request_data_size:
61 description:
62 - The number of bytes to send in the request.
63 - Only used if I(sla_type=http).
64 - The APIC defaults to C(28) when unset during creation.
65 - Permitted values are in the range of [0, 17512]
66 - This is only supported in APIC v5.1 and above.
67 type: int
68 type_of_service:
69 description:
70 - The Type of Service (ToS) value to set in the IPv4 header.
71 - The APIC defaults to C(0) when unset during creation.
72 - Permitted values are in the range of [0, 255].
73 - This is only supported in APIC v5.1 and above.
74 type: int
75 aliases: [ tos ]
76 operation_timeout:
77 description:
78 - The amount of time in milliseconds that the IP SLA operation waits for a response from its request packet.
79 - The APIC defaults to C(900) when unset during creation.
80 - Permitted values are in the range of [0, 604800000].
81 - This is only supported in APIC v5.1 and above.
82 type: int
83 threshold:
84 description:
85 - The upper threshold value in milliseconds for calculating network monitoring statistics created by the IP SLA operation.
86 - The value specified for this property must not exceed the value specified for I(operation_timeout).
87 - The APIC defaults to C(900) when unset during creation.
88 - Permitted values are in the range of [0, 604800000].
89 - This is only supported in APIC v5.1 and above.
90 type: int
91 traffic_class:
92 description:
93 - Sets the Traffic Class value in the IPv6 header.
94 - The APIC defaults to C(0) when unset during creation.
95 - Permitted values are in the range of [0, 255].
96 - This is only supported in APIC v5.1 and above.
97 type: int
98 aliases: ["traffic_class_value"]
99 http_version:
100 description:
101 - The HTTP version to use.
102 - The APIC defaults to C(1.0) when unset during creation.
103 - This is only supported in APIC v5.0 and above.
104 type: str
105 choices: [ "1.0", "1.1" ]
106 http_uri:
107 description:
108 - The HTTP URI to use as the SLA destination.
109 - The APIC defaults to C(/) when unset during creation.
110 - This is only supported in APIC v5.0 and above.
111 type: str
112 state:
113 description:
114 - Use C(present) or C(absent) for adding or removing.
115 - Use C(query) for listing an object or multiple objects.
116 type: str
117 choices: [ absent, present, query ]
118 default: present
119 extends_documentation_fragment:
120 - cisco.aci.aci
121 - cisco.aci.annotation
122 - cisco.aci.owner
123
124 notes:
125 - The I(tenant) must exist before using this module in your playbook.
126 The M(cisco.aci.aci_tenant) modules can be used for this.
127 seealso:
128 - name: APIC Management Information Model reference
129 description: More information about the internal APIC class B(fv:IPSLAMonitoringPol)
130 link: https://developer.cisco.com/docs/apic-mim-ref/
131 author:
132 - Tim Cragg (@timcragg)
133 """
134
135 EXAMPLES = r"""
136 - name: Add a new ICMP SLA monitoring policy
137 cisco.aci.aci_ip_sla_monitoring_policy:
138 host: apic
139 username: admin
140 password: SomeSecretPassword
141 tenant: my_tenant
142 name: my_policy
143 sla_type: icmp
144 frequency: 40
145 multiplier: 6
146 state: present
147 delegate_to: localhost
148
149 - name: Update to TCP SLA monitoring policy
150 cisco.aci.aci_ip_sla_monitoring_policy:
151 host: apic
152 username: admin
153 password: SomeSecretPassword
154 tenant: my_tenant
155 name: my_policy
156 sla_type: tcp
157 sla_port: 2345
158 frequency: 45
159 multiplier: 5
160 state: present
161 delegate_to: localhost
162
163 - name: Query an SLA monitoring policy
164 cisco.aci.aci_ip_sla_monitoring_policy:
165 host: apic
166 username: admin
167 password: SomeSecretPassword
168 tenant: my_tenant
169 name: my_policy
170 state: query
171 delegate_to: localhost
172 register: query_result
173
174 - name: Query all SLA monitoring policies
175 cisco.aci.aci_ip_sla_monitoring_policy:
176 host: apic
177 username: admin
178 password: SomeSecretPassword
179 state: query
180 delegate_to: localhost
181 register: query_result
182
183 - name: Delete an SLA monitoring policy
184 cisco.aci.aci_ip_sla_monitoring_policy:
185 host: apic
186 username: admin
187 password: SomeSecretPassword
188 tenant: my_tenant
189 name: my_policy
190 state: absent
191 delegate_to: localhost
192 """
193
194 RETURN = r"""
195 current:
196 description: The existing configuration from the APIC after the module has finished
197 returned: success
198 type: list
199 sample:
200 [
201 {
202 "fvTenant": {
203 "attributes": {
204 "descr": "Production environment",
205 "dn": "uni/tn-production",
206 "name": "production",
207 "nameAlias": "",
208 "ownerKey": "",
209 "ownerTag": ""
210 }
211 }
212 }
213 ]
214 error:
215 description: The error information as returned from the APIC
216 returned: failure
217 type: dict
218 sample:
219 {
220 "code": "122",
221 "text": "unknown managed object class foo"
222 }
223 raw:
224 description: The raw output returned by the APIC REST API (xml or json)
225 returned: parse error
226 type: str
227 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
228 sent:
229 description: The actual/minimal configuration pushed to the APIC
230 returned: info
231 type: list
232 sample:
233 {
234 "fvTenant": {
235 "attributes": {
236 "descr": "Production environment"
237 }
238 }
239 }
240 previous:
241 description: The original configuration from the APIC before the module has started
242 returned: info
243 type: list
244 sample:
245 [
246 {
247 "fvTenant": {
248 "attributes": {
249 "descr": "Production",
250 "dn": "uni/tn-production",
251 "name": "production",
252 "nameAlias": "",
253 "ownerKey": "",
254 "ownerTag": ""
255 }
256 }
257 }
258 ]
259 proposed:
260 description: The assembled configuration from the user-provided parameters
261 returned: info
262 type: dict
263 sample:
264 {
265 "fvTenant": {
266 "attributes": {
267 "descr": "Production environment",
268 "name": "production"
269 }
270 }
271 }
272 filter_string:
273 description: The filter string used for the request
274 returned: failure or debug
275 type: str
276 sample: ?rsp-prop-include=config-only
277 method:
278 description: The HTTP method used for the request to the APIC
279 returned: failure or debug
280 type: str
281 sample: POST
282 response:
283 description: The HTTP response from the APIC
284 returned: failure or debug
285 type: str
286 sample: OK (30 bytes)
287 status:
288 description: The HTTP status from the APIC
289 returned: failure or debug
290 type: int
291 sample: 200
292 url:
293 description: The HTTP url used for the request to the APIC
294 returned: failure or debug
295 type: str
296 sample: https://10.11.12.13/api/mo/uni/tn-production.json
297 """
298
299
300 from ansible.module_utils.basic import AnsibleModule
301 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
302 from ansible_collections.cisco.aci.plugins.module_utils.constants import HTTP_VERSIONS_MAPPING
303
304
305 def main():
306 argument_spec = aci_argument_spec()
307 argument_spec.update(aci_annotation_spec())
308 argument_spec.update(aci_owner_spec())
309 argument_spec.update(
310 tenant=dict(type="str", aliases=["tenant_name"]),
311 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
312 name=dict(type="str", aliases=["sla_policy"]),
313 description=dict(type="str"),
314 sla_type=dict(type="str", choices=["icmp", "tcp", "l2ping", "http"]),
315 sla_port=dict(type="int", aliases=["destination_port"]),
316 frequency=dict(type="int"),
317 multiplier=dict(type="int", aliases=["detect_multiplier"]),
318 request_data_size=dict(type="int"),
319 type_of_service=dict(type="int", aliases=["tos"]),
320 operation_timeout=dict(type="int"),
321 threshold=dict(type="int"),
322 traffic_class=dict(type="int", aliases=["traffic_class_value"]),
323 http_version=dict(type="str", choices=list(HTTP_VERSIONS_MAPPING)),
324 http_uri=dict(type="str"),
325 )
326
327 module = AnsibleModule(
328 argument_spec=argument_spec,
329 supports_check_mode=True,
330 required_if=[
331 ["state", "absent", ["tenant", "name"]],
332 ["state", "present", ["tenant", "name"]],
333 ],
334 )
335
336 tenant = module.params.get("tenant")
337 state = module.params.get("state")
338 description = module.params.get("description")
339 name = module.params.get("name")
340 sla_type = module.params.get("sla_type")
341 sla_port = module.params.get("sla_port")
342 frequency = module.params.get("frequency")
343 multiplier = module.params.get("multiplier")
344 request_data_size = module.params.get("request_data_size")
345 type_of_service = module.params.get("type_of_service")
346 operation_timeout = module.params.get("operation_timeout")
347 threshold = module.params.get("threshold")
348 traffic_class = module.params.get("traffic_class")
349 http_version = HTTP_VERSIONS_MAPPING.get(module.params.get("http_version"))
350 http_uri = module.params.get("http_uri")
351
352 aci = ACIModule(module)
353
354 aci.construct_url(
355 root_class=dict(
356 aci_class="fvTenant",
357 aci_rn="tn-{0}".format(tenant),
358 module_object=tenant,
359 target_filter={"name": tenant},
360 ),
361 subclass_1=dict(
362 aci_class="fvIPSLAMonitoringPol",
363 aci_rn="ipslaMonitoringPol-{0}".format(name),
364 module_object=name,
365 target_filter={"name": name},
366 ),
367 )
368 aci.get_existing()
369
370 if state == "present":
371 if sla_port is not None and sla_type != "tcp":
372 aci.fail_json("Setting 'sla_port' is not allowed when 'sla_type' is not set to 'tcp'.")
373 if sla_type == "tcp" and request_data_size is not None:
374 aci.fail_json("Setting 'request_data_size' is not allowed when 'sla_type' is set to 'tcp'.")
375
376 if sla_type == "http":
377 sla_port = 80
378 elif sla_type != "tcp":
379 sla_port = 0
380
381 aci.payload(
382 aci_class="fvIPSLAMonitoringPol",
383 class_config=dict(
384 name=name,
385 descr=description,
386 slaType=sla_type,
387 slaPort=sla_port,
388 slaFrequency=frequency,
389 slaDetectMultiplier=multiplier,
390 reqDataSize=request_data_size,
391 ipv4Tos=type_of_service,
392 timeout=operation_timeout,
393 threshold=threshold,
394 ipv6TrfClass=traffic_class,
395 httpVersion=http_version,
396 httpUri=http_uri,
397 ),
398 )
399 aci.get_diff(aci_class="fvIPSLAMonitoringPol")
400
401 aci.post_config()
402
403 elif state == "absent":
404 aci.delete_config()
405
406 aci.exit_json()
407
408
409 if __name__ == "__main__":
410 main()