Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_qos_dscp_class.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": "community"}
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_qos_dscp_class
16 short_description: Manage QoS DSCP Class (qos:DscpClass)
17 description:
18 - Manage QoS Custom Differentiated Services Code Point (DSCP) Class levels for QoS Custom Policies on Cisco ACI fabrics.
19 - The class level for DSCP to prioritize the map.
20 options:
21 tenant:
22 description:
23 - The name of an existing tenant.
24 type: str
25 aliases: [ tenant_name ]
26 qos_custom_policy:
27 description:
28 - The name of the QoS Custom Policy.
29 type: str
30 aliases: [ qos_custom_policy_name ]
31 priority:
32 description:
33 - The desired QoS class level to be used.
34 - The APIC defaults to C(level3) when unset during creation.
35 type: str
36 choices: [ level1, level2, level3, level4, level5, level6, unspecified ]
37 aliases: [ prio ]
38 dscp_from:
39 description:
40 - The DSCP range starting value.
41 type: str
42 choices: [ AF11, AF12, AF13, AF21, AF22, AF23, AF31, AF32, AF33, AF41, AF42, AF43, CS0, CS1, CS2, CS3, CS4, CS5, CS6, CS7, EF, VA, unspecified ]
43 dscp_to:
44 description:
45 - The DSCP range ending value.
46 type: str
47 choices: [ AF11, AF12, AF13, AF21, AF22, AF23, AF31, AF32, AF33, AF41, AF42, AF43, CS0, CS1, CS2, CS3, CS4, CS5, CS6, CS7, EF, VA, unspecified ]
48 dscp_target:
49 description:
50 - The DSCP target value.
51 - The APIC defaults to C(unspecified) when unset during creation.
52 type: str
53 choices: [ AF11, AF12, AF13, AF21, AF22, AF23, AF31, AF32, AF33, AF41, AF42, AF43, CS0, CS1, CS2, CS3, CS4, CS5, CS6, CS7, EF, VA, unspecified ]
54 aliases: [ target ]
55 target_cos:
56 description:
57 - The target COS to be driven based on the range of input values of DSCP coming into the fabric.
58 - The APIC defaults to C(unspecified) when unset during creation.
59 type: str
60 choices: [ background, best_effort, excellent_effort, critical_applications, video, voice, internetwork_control, network_control, unspecified ]
61 state:
62 description:
63 - Use C(present) or C(absent) for adding or removing.
64 - Use C(query) for listing an object or multiple objects.
65 type: str
66 choices: [ absent, present, query ]
67 default: present
68 extends_documentation_fragment:
69 - cisco.aci.aci
70 - cisco.aci.annotation
71 - cisco.aci.owner
72
73 notes:
74 - The I(tenant) and I(qos_custom_policy) must exist before using this module in your playbook.
75 The M(cisco.aci.aci_tenant) and the M(cisco.aci.aci_qos_custom_policy) can be used for this.
76 seealso:
77 - module: cisco.aci.aci_tenant
78 - module: cisco.aci.aci_qos_custom_policy
79 - name: APIC Management Information Model reference
80 description: More information about the internal APIC class B(qos:DscpClass).
81 link: https://developer.cisco.com/docs/apic-mim-ref/
82 author:
83 - Gaspard Micol (@gmicol)
84 """
85
86 EXAMPLES = r"""
87 - name: Add a new QoS DSCP Class
88 cisco.aci.aci_qos_dscp_class:
89 host: apic
90 username: admin
91 password: SomeSecretPassword
92 tenant: my_tenant
93 qos_custom_policy: my_qos_custom_policy
94 priority: level3
95 dscp_from: AF11
96 dscp_to: AF21
97 dscp_target: unspecified
98 target_cos: best_effort
99 state: present
100 delegate_to: localhost
101
102 - name: Query a QoS DSCP Class
103 cisco.aci.aci_qos_dscp_class:
104 host: apic
105 username: admin
106 password: SomeSecretPassword
107 tenant: my_tenant
108 qos_custom_policy: my_qos_custom_policy
109 dscp_from: AF11
110 dscp_to: AF21
111 state: query
112 delegate_to: localhost
113
114 - name: Query all QoS DSCP Classes in my_qos_custom_policy
115 cisco.aci.aci_qos_dscp_class:
116 host: apic
117 username: admin
118 password: SomeSecretPassword
119 tenant: my_tenant
120 qos_custom_policy: my_qos_custom_policy
121 state: query
122 delegate_to: localhost
123
124 - name: Query all QoS DSCP Classes
125 cisco.aci.aci_qos_dscp_class:
126 host: apic
127 username: admin
128 password: SomeSecretPassword
129 state: query
130 delegate_to: localhost
131
132 - name: Delete a QoS DSCP Class
133 cisco.aci.aci_qos_dscp_class:
134 host: apic
135 username: admin
136 password: SomeSecretPassword
137 tenant: my_tenant
138 qos_custom_policy: my_qos_custom_policy
139 dscp_from: AF11
140 dscp_to: AF21
141 state: absent
142 delegate_to: localhost
143 """
144
145 RETURN = r"""
146 current:
147 description: The existing configuration from the APIC after the module has finished
148 returned: success
149 type: list
150 sample:
151 [
152 {
153 "fvTenant": {
154 "attributes": {
155 "descr": "Production environment",
156 "dn": "uni/tn-production",
157 "name": "production",
158 "nameAlias": "",
159 "ownerKey": "",
160 "ownerTag": ""
161 }
162 }
163 }
164 ]
165 error:
166 description: The error information as returned from the APIC
167 returned: failure
168 type: dict
169 sample:
170 {
171 "code": "122",
172 "text": "unknown managed object class foo"
173 }
174 raw:
175 description: The raw output returned by the APIC REST API (xml or json)
176 returned: parse error
177 type: str
178 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
179 sent:
180 description: The actual/minimal configuration pushed to the APIC
181 returned: info
182 type: list
183 sample:
184 {
185 "fvTenant": {
186 "attributes": {
187 "descr": "Production environment"
188 }
189 }
190 }
191 previous:
192 description: The original configuration from the APIC before the module has started
193 returned: info
194 type: list
195 sample:
196 [
197 {
198 "fvTenant": {
199 "attributes": {
200 "descr": "Production",
201 "dn": "uni/tn-production",
202 "name": "production",
203 "nameAlias": "",
204 "ownerKey": "",
205 "ownerTag": ""
206 }
207 }
208 }
209 ]
210 proposed:
211 description: The assembled configuration from the user-provided parameters
212 returned: info
213 type: dict
214 sample:
215 {
216 "fvTenant": {
217 "attributes": {
218 "descr": "Production environment",
219 "name": "production"
220 }
221 }
222 }
223 filter_string:
224 description: The filter string used for the request
225 returned: failure or debug
226 type: str
227 sample: ?rsp-prop-include=config-only
228 method:
229 description: The HTTP method used for the request to the APIC
230 returned: failure or debug
231 type: str
232 sample: POST
233 response:
234 description: The HTTP response from the APIC
235 returned: failure or debug
236 type: str
237 sample: OK (30 bytes)
238 status:
239 description: The HTTP status from the APIC
240 returned: failure or debug
241 type: int
242 sample: 200
243 url:
244 description: The HTTP url used for the request to the APIC
245 returned: failure or debug
246 type: str
247 sample: https://10.11.12.13/api/mo/uni/tn-production.json
248 """
249
250
251 from ansible.module_utils.basic import AnsibleModule
252 from ansible_collections.cisco.aci.plugins.module_utils.aci import (
253 ACIModule,
254 aci_argument_spec,
255 aci_annotation_spec,
256 aci_owner_spec,
257 aci_contract_dscp_spec,
258 )
259 from ansible_collections.cisco.aci.plugins.module_utils.constants import MATCH_TARGET_COS_MAPPING
260
261
262 def main():
263 new_dscp_spec = dict((k, aci_contract_dscp_spec()[k]) for k in aci_contract_dscp_spec() if k != "aliases")
264 argument_spec = aci_argument_spec()
265 argument_spec.update(aci_annotation_spec())
266 argument_spec.update(aci_owner_spec())
267 argument_spec.update(
268 tenant=dict(type="str", aliases=["tenant_name"]),
269 qos_custom_policy=dict(type="str", aliases=["qos_custom_policy_name"]),
270 priority=dict(
271 type="str",
272 choices=[
273 "level1",
274 "level2",
275 "level3",
276 "level4",
277 "level5",
278 "level6",
279 "unspecified",
280 ],
281 aliases=["prio"],
282 ),
283 dscp_from=new_dscp_spec,
284 dscp_to=new_dscp_spec,
285 dscp_target=aci_contract_dscp_spec(),
286 target_cos=dict(type="str", choices=list(MATCH_TARGET_COS_MAPPING.keys())),
287 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
288 )
289
290 module = AnsibleModule(
291 argument_spec=argument_spec,
292 supports_check_mode=True,
293 required_if=[
294 ["state", "absent", ["tenant", "qos_custom_policy", "dscp_from", "dscp_to"]],
295 ["state", "present", ["tenant", "qos_custom_policy", "dscp_from", "dscp_to"]],
296 ],
297 )
298
299 tenant = module.params.get("tenant")
300 qos_custom_policy = module.params.get("qos_custom_policy")
301 priority = module.params.get("priority")
302 dscp_from = module.params.get("dscp_from")
303 dscp_to = module.params.get("dscp_to")
304 dscp_target = module.params.get("dscp_target")
305 target_cos = MATCH_TARGET_COS_MAPPING.get(module.params.get("target_cos"))
306 state = module.params.get("state")
307
308 aci = ACIModule(module)
309
310 aci.construct_url(
311 root_class=dict(
312 aci_class="fvTenant",
313 aci_rn="tn-{0}".format(tenant),
314 module_object=tenant,
315 target_filter={"name": tenant},
316 ),
317 subclass_1=dict(
318 aci_class="qosCustomPol",
319 aci_rn="qoscustom-{0}".format(qos_custom_policy),
320 module_object=qos_custom_policy,
321 target_filter={"name": qos_custom_policy},
322 ),
323 subclass_2=dict(
324 aci_class="qosDscpClass",
325 aci_rn="dcsp-{0}-{1}".format(dscp_from, dscp_to),
326 module_object=qos_custom_policy,
327 target_filter={"from": dscp_from, "to": dscp_to},
328 ),
329 )
330
331 aci.get_existing()
332
333 if state == "present":
334 aci.payload(
335 aci_class="qosDscpClass",
336 class_config={
337 "prio": priority,
338 "from": dscp_from,
339 "to": dscp_to,
340 "target": dscp_target,
341 "targetCos": target_cos,
342 },
343 )
344
345 aci.get_diff(aci_class="qosDscpClass")
346
347 aci.post_config()
348
349 elif state == "absent":
350 aci.delete_config()
351
352 aci.exit_json()
353
354
355 if __name__ == "__main__":
356 main()