Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_qos_dot1p_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_dot1p_class
16 short_description: Manage QoS Dot1P Class (qos:Dot1PClass)
17 description:
18 - Manage Dot1P Class levels for QoS Custom Policies on Cisco ACI fabrics.
19 - The class level for Dot1P 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(unspecified) when unset during creation.
35 type: str
36 choices: [ level1, level2, level3, level4, level5, level6, unspecified ]
37 aliases: [ prio ]
38 dot1p_from:
39 description:
40 - The Dot1P range starting value.
41 type: str
42 choices: [ background, best_effort, excellent_effort, critical_applications, video, voice, internetwork_control, network_control, unspecified ]
43 dot1p_to:
44 description:
45 - The Dot1P range ending value.
46 type: str
47 choices: [ background, best_effort, excellent_effort, critical_applications, video, voice, internetwork_control, network_control, unspecified ]
48 dot1p_target:
49 description:
50 - The Dot1P 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 Dot1P 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:Dot1PClass).
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 dot1P Class
88 cisco.aci.aci_qos_dot1p_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 dot1p_from: best_effort
96 dot1p_to: excellent_effort
97 dot1p_target: unspecified
98 target_cos: unspecified
99 state: present
100 delegate_to: localhost
101
102 - name: Query a QoS dot1P Class
103 cisco.aci.aci_qos_dot1p_class:
104 host: apic
105 username: admin
106 password: SomeSecretPassword
107 tenant: my_tenant
108 qos_custom_policy: my_qos_custom_policy
109 dot1p_from: best_effort
110 dot1p_to: excellent_effort
111 state: query
112 delegate_to: localhost
113
114 - name: Query all QoS dot1P Classes in my_qos_custom_policy
115 cisco.aci.aci_qos_dot1p_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 dot1P Classes
125 cisco.aci.aci_qos_dot1p_class:
126 host: apic
127 username: admin
128 password: SomeSecretPassword
129 state: query
130 delegate_to: localhost
131
132 - name: Delete a QoS dot1P Class
133 cisco.aci.aci_qos_dot1p_class:
134 host: apic
135 username: admin
136 password: SomeSecretPassword
137 tenant: my_tenant
138 qos_custom_policy: my_qos_custom_policy
139 dot1p_from: best_effort
140 dot1p_to: excellent_effort
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 argument_spec = aci_argument_spec()
264 argument_spec.update(aci_annotation_spec())
265 argument_spec.update(aci_owner_spec())
266 argument_spec.update(
267 tenant=dict(type="str", aliases=["tenant_name"]),
268 qos_custom_policy=dict(type="str", aliases=["qos_custom_policy_name"]),
269 priority=dict(
270 type="str",
271 choices=[
272 "level1",
273 "level2",
274 "level3",
275 "level4",
276 "level5",
277 "level6",
278 "unspecified",
279 ],
280 aliases=["prio"],
281 ),
282 dot1p_from=dict(type="str", choices=list(MATCH_TARGET_COS_MAPPING.keys())),
283 dot1p_to=dict(type="str", choices=list(MATCH_TARGET_COS_MAPPING.keys())),
284 dot1p_target=aci_contract_dscp_spec(),
285 target_cos=dict(type="str", choices=list(MATCH_TARGET_COS_MAPPING.keys())),
286 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
287 )
288
289 module = AnsibleModule(
290 argument_spec=argument_spec,
291 supports_check_mode=True,
292 required_if=[
293 ["state", "absent", ["tenant", "qos_custom_policy", "dot1p_from", "dot1p_to"]],
294 ["state", "present", ["tenant", "qos_custom_policy", "dot1p_from", "dot1p_to"]],
295 ],
296 )
297
298 tenant = module.params.get("tenant")
299 qos_custom_policy = module.params.get("qos_custom_policy")
300 priority = module.params.get("priority")
301 dot1p_from = MATCH_TARGET_COS_MAPPING.get(module.params.get("dot1p_from"))
302 dot1p_to = MATCH_TARGET_COS_MAPPING.get(module.params.get("dot1p_to"))
303 dot1p_target = module.params.get("dot1p_target")
304 target_cos = MATCH_TARGET_COS_MAPPING.get(module.params.get("target_cos"))
305 state = module.params.get("state")
306
307 aci = ACIModule(module)
308
309 aci.construct_url(
310 root_class=dict(
311 aci_class="fvTenant",
312 aci_rn="tn-{0}".format(tenant),
313 module_object=tenant,
314 target_filter={"name": tenant},
315 ),
316 subclass_1=dict(
317 aci_class="qosCustomPol",
318 aci_rn="qoscustom-{0}".format(qos_custom_policy),
319 module_object=qos_custom_policy,
320 target_filter={"name": qos_custom_policy},
321 ),
322 subclass_2=dict(
323 aci_class="qosDot1PClass",
324 aci_rn="dot1P-{0}-{1}".format(dot1p_from, dot1p_to),
325 module_object=qos_custom_policy,
326 target_filter={"from": dot1p_from, "to": dot1p_to},
327 ),
328 )
329
330 aci.get_existing()
331
332 if state == "present":
333 aci.payload(
334 aci_class="qosDot1PClass",
335 class_config={
336 "prio": priority,
337 "from": dot1p_from,
338 "to": dot1p_to,
339 "target": dot1p_target,
340 "targetCos": target_cos,
341 },
342 )
343
344 aci.get_diff(aci_class="qosDot1PClass")
345
346 aci.post_config()
347
348 elif state == "absent":
349 aci.delete_config()
350
351 aci.exit_json()
352
353
354 if __name__ == "__main__":
355 main()