Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_qos_custom_policy.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_custom_policy
16 short_description: Manage QoS Custom Policy (qos:CustomPol)
17 description:
18 - Manage QoS Custom Policies for tenants on Cisco ACI fabrics.
19 - The custom QoS policy enables different levels of service to be assigned to network traffic,
20 including specifications for the Differentiated Services Code Point (DSCP) value(s), and the 802.1p Dot1p priority.
21 options:
22 tenant:
23 description:
24 - The name of an existing tenant.
25 type: str
26 aliases: [ tenant_name ]
27 qos_custom_policy:
28 description:
29 - The name of the QoS Custom Policy.
30 type: str
31 aliases: [ qos_custom_policy_name, name ]
32 description:
33 description:
34 - The description for the QoS Custom Policy.
35 type: str
36 aliases: [ descr ]
37 state:
38 description:
39 - Use C(present) or C(absent) for adding or removing.
40 - Use C(query) for listing an object or multiple objects.
41 type: str
42 choices: [ absent, present, query ]
43 default: present
44 extends_documentation_fragment:
45 - cisco.aci.aci
46 - cisco.aci.annotation
47 - cisco.aci.owner
48
49 notes:
50 - The I(tenant) must exist before using this module in your playbook.
51 The M(cisco.aci.aci_tenant) can be used for this.
52 seealso:
53 - module: cisco.aci.aci_tenant
54 - name: APIC Management Information Model reference
55 description: More information about the internal APIC class B(qos:CustomPol).
56 link: https://developer.cisco.com/docs/apic-mim-ref/
57 author:
58 - Gaspard Micol (@gmicol)
59 """
60
61 EXAMPLES = r"""
62 - name: Add a new QoS Custom Policy
63 cisco.aci.aci_qos_custom_policy:
64 host: apic
65 username: admin
66 password: SomeSecretPassword
67 tenant: my_tenant
68 qos_custom_policy: my_qos_custom_policy
69 state: present
70 delegate_to: localhost
71
72 - name: Query a QoS Custom Policy
73 cisco.aci.aci_qos_custom_policy:
74 host: apic
75 username: admin
76 password: SomeSecretPassword
77 tenant: my_tenant
78 qos_custom_policy: my_qos_custom_policy
79 state: query
80 delegate_to: localhost
81
82 - name: Query all QoS Custom Policies in my_tenant
83 cisco.aci.aci_qos_custom_policy:
84 host: apic
85 username: admin
86 password: SomeSecretPassword
87 tenant: my_tenant
88 state: query
89 delegate_to: localhost
90
91 - name: Query all QoS Custom Policies
92 cisco.aci.aci_qos_custom_policy:
93 host: apic
94 username: admin
95 password: SomeSecretPassword
96 state: query
97 delegate_to: localhost
98
99 - name: Delete a QoS Custom Policy
100 cisco.aci.aci_qos_custom_policy:
101 host: apic
102 username: admin
103 password: SomeSecretPassword
104 tenant: my_tenant
105 qos_custom_policy: my_qos_custom_policy
106 state: absent
107 delegate_to: localhost
108 """
109
110 RETURN = r"""
111 current:
112 description: The existing configuration from the APIC after the module has finished
113 returned: success
114 type: list
115 sample:
116 [
117 {
118 "fvTenant": {
119 "attributes": {
120 "descr": "Production environment",
121 "dn": "uni/tn-production",
122 "name": "production",
123 "nameAlias": "",
124 "ownerKey": "",
125 "ownerTag": ""
126 }
127 }
128 }
129 ]
130 error:
131 description: The error information as returned from the APIC
132 returned: failure
133 type: dict
134 sample:
135 {
136 "code": "122",
137 "text": "unknown managed object class foo"
138 }
139 raw:
140 description: The raw output returned by the APIC REST API (xml or json)
141 returned: parse error
142 type: str
143 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
144 sent:
145 description: The actual/minimal configuration pushed to the APIC
146 returned: info
147 type: list
148 sample:
149 {
150 "fvTenant": {
151 "attributes": {
152 "descr": "Production environment"
153 }
154 }
155 }
156 previous:
157 description: The original configuration from the APIC before the module has started
158 returned: info
159 type: list
160 sample:
161 [
162 {
163 "fvTenant": {
164 "attributes": {
165 "descr": "Production",
166 "dn": "uni/tn-production",
167 "name": "production",
168 "nameAlias": "",
169 "ownerKey": "",
170 "ownerTag": ""
171 }
172 }
173 }
174 ]
175 proposed:
176 description: The assembled configuration from the user-provided parameters
177 returned: info
178 type: dict
179 sample:
180 {
181 "fvTenant": {
182 "attributes": {
183 "descr": "Production environment",
184 "name": "production"
185 }
186 }
187 }
188 filter_string:
189 description: The filter string used for the request
190 returned: failure or debug
191 type: str
192 sample: ?rsp-prop-include=config-only
193 method:
194 description: The HTTP method used for the request to the APIC
195 returned: failure or debug
196 type: str
197 sample: POST
198 response:
199 description: The HTTP response from the APIC
200 returned: failure or debug
201 type: str
202 sample: OK (30 bytes)
203 status:
204 description: The HTTP status from the APIC
205 returned: failure or debug
206 type: int
207 sample: 200
208 url:
209 description: The HTTP url used for the request to the APIC
210 returned: failure or debug
211 type: str
212 sample: https://10.11.12.13/api/mo/uni/tn-production.json
213 """
214
215
216 from ansible.module_utils.basic import AnsibleModule
217 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
218
219
220 def main():
221 argument_spec = aci_argument_spec()
222 argument_spec.update(aci_annotation_spec())
223 argument_spec.update(aci_owner_spec())
224 argument_spec.update(
225 tenant=dict(type="str", aliases=["tenant_name"]),
226 qos_custom_policy=dict(type="str", aliases=["qos_custom_policy_name", "name"]),
227 description=dict(type="str", aliases=["descr"]),
228 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
229 )
230
231 module = AnsibleModule(
232 argument_spec=argument_spec,
233 supports_check_mode=True,
234 required_if=[
235 ["state", "absent", ["tenant", "qos_custom_policy"]],
236 ["state", "present", ["tenant", "qos_custom_policy"]],
237 ],
238 )
239
240 tenant = module.params.get("tenant")
241 description = module.params.get("description")
242 qos_custom_policy = module.params.get("qos_custom_policy")
243 state = module.params.get("state")
244
245 aci = ACIModule(module)
246
247 aci.construct_url(
248 root_class=dict(
249 aci_class="fvTenant",
250 aci_rn="tn-{0}".format(tenant),
251 module_object=tenant,
252 target_filter={"name": tenant},
253 ),
254 subclass_1=dict(
255 aci_class="qosCustomPol",
256 aci_rn="qoscustom-{0}".format(qos_custom_policy),
257 module_object=qos_custom_policy,
258 target_filter={"name": qos_custom_policy},
259 ),
260 )
261
262 aci.get_existing()
263
264 if state == "present":
265 aci.payload(
266 aci_class="qosCustomPol",
267 class_config=dict(
268 name=qos_custom_policy,
269 descr=description,
270 ),
271 )
272
273 aci.get_diff(aci_class="qosCustomPol")
274
275 aci.post_config()
276
277 elif state == "absent":
278 aci.delete_config()
279
280 aci.exit_json()
281
282
283 if __name__ == "__main__":
284 main()