Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2023, Akini Ross (@akinross) <[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_l3out_logical_node_profile
16 short_description: Manage Layer 3 Outside (L3Out) logical node profiles (l3ext:LNodeP)
17 description:
18 - Manage Layer 3 Outside (L3Out) logical node profiles on Cisco ACI fabrics.
19 options:
20 node_profile:
21 description:
22 - Name of the node profile.
23 type: str
24 aliases: [ node_profile_name, name, logical_node ]
25 description:
26 description:
27 - Description for the node profile.
28 type: str
29 aliases: [ descr ]
30 tenant:
31 description:
32 - Name of an existing tenant.
33 type: str
34 aliases: [ tenant_name ]
35 l3out:
36 description:
37 - Name of an existing L3Out.
38 type: str
39 aliases: [ l3out_name ]
40 dscp:
41 description:
42 - The target Differentiated Service (DSCP) value.
43 - The APIC defaults to C(unspecified) when unset during creation.
44 type: str
45 choices: [ AF11, AF12, AF13, AF21, AF22, AF23, AF31, AF32, AF33, AF41, AF42, AF43, CS0, CS1, CS2, CS3, CS4, CS5, CS6, CS7, EF, VA, unspecified ]
46 aliases: [ target_dscp ]
47 mpls_custom_qos_policy:
48 description:
49 - The MPLS custom QoS policy name for the node profile.
50 - This argument should only be used for Infra SR-MPLS L3Outs.
51 aliases: [ mpls_custom_qos_policy_name ]
52 type: str
53 state:
54 description:
55 - Use C(present) or C(absent) for adding or removing.
56 - Use C(query) for listing an object or multiple objects.
57 type: str
58 choices: [ absent, present, query ]
59 default: present
60 name_alias:
61 description:
62 - The alias for the current object. This relates to the nameAlias field in ACI.
63 type: str
64 extends_documentation_fragment:
65 - cisco.aci.aci
66 - cisco.aci.annotation
67 - cisco.aci.owner
68
69 seealso:
70 - module: cisco.aci.aci_l3out
71 - name: APIC Management Information Model reference
72 description: More information about the internal APIC classes B(l3ext:LNodeP).
73 link: https://developer.cisco.com/docs/apic-mim-ref/
74 author:
75 - Jason Juenger (@jasonjuenger)
76 - Akini Ross (@akinross)
77 """
78
79 EXAMPLES = r"""
80 - name: Add a new node profile
81 cisco.aci.aci_l3out_logical_node_profile:
82 host: apic
83 username: admin
84 password: SomeSecretPassword
85 node_profile: my_node_profile
86 description: node profile for my_l3out
87 l3out: my_l3out
88 tenant: my_tenant
89 dscp: CS0
90 state: present
91 delegate_to: localhost
92
93 - name: Add a new node profile with MPLS custom QOS policy to SR-MPLS infra l3out
94 cisco.aci.aci_l3out_logical_node_profile:
95 host: apic
96 username: admin
97 password: SomeSecretPassword
98 tenant: infra
99 l3out: infra_sr_mpls_l3out
100 node_profile: infra_sr_mpls_l3out_node_profile
101 mpls_custom_qos_policy: infra_mpls_custom_qos_policy
102 state: present
103 delegate_to: localhost
104
105 - name: Delete a node profile
106 cisco.aci.aci_l3out_logical_node_profile:
107 host: apic
108 username: admin
109 password: SomeSecretPassword
110 node_profile: my_node_profile
111 l3out: my_l3out
112 tenant: my_tenant
113 state: absent
114 delegate_to: localhost
115
116 - name: Query a node profile
117 cisco.aci.aci_l3out_logical_node_profile:
118 host: apic
119 username: admin
120 password: SomeSecretPassword
121 node_profile: my_node_profile
122 l3out: my_l3out
123 tenant: my_tenant
124 state: query
125 delegate_to: localhost
126 register: query_result
127
128 - name: Query all node profile for L3out
129 cisco.aci.aci_l3out_logical_node_profile:
130 host: apic
131 username: admin
132 password: SomeSecretPassword
133 l3out: my_l3out
134 tenant: my_tenant
135 state: query
136 delegate_to: localhost
137 register: query_result
138 """
139
140 RETURN = r"""
141 current:
142 description: The existing configuration from the APIC after the module has finished
143 returned: success
144 type: list
145 sample:
146 [
147 {
148 "fvTenant": {
149 "attributes": {
150 "descr": "Production environment",
151 "dn": "uni/tn-production",
152 "name": "production",
153 "nameAlias": "",
154 "ownerKey": "",
155 "ownerTag": ""
156 }
157 }
158 }
159 ]
160 error:
161 description: The error information as returned from the APIC
162 returned: failure
163 type: dict
164 sample:
165 {
166 "code": "122",
167 "text": "unknown managed object class foo"
168 }
169 raw:
170 description: The raw output returned by the APIC REST API (xml or json)
171 returned: parse error
172 type: str
173 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
174 sent:
175 description: The actual/minimal configuration pushed to the APIC
176 returned: info
177 type: list
178 sample:
179 {
180 "fvTenant": {
181 "attributes": {
182 "descr": "Production environment"
183 }
184 }
185 }
186 previous:
187 description: The original configuration from the APIC before the module has started
188 returned: info
189 type: list
190 sample:
191 [
192 {
193 "fvTenant": {
194 "attributes": {
195 "descr": "Production",
196 "dn": "uni/tn-production",
197 "name": "production",
198 "nameAlias": "",
199 "ownerKey": "",
200 "ownerTag": ""
201 }
202 }
203 }
204 ]
205 proposed:
206 description: The assembled configuration from the user-provided parameters
207 returned: info
208 type: dict
209 sample:
210 {
211 "fvTenant": {
212 "attributes": {
213 "descr": "Production environment",
214 "name": "production"
215 }
216 }
217 }
218 filter_string:
219 description: The filter string used for the request
220 returned: failure or debug
221 type: str
222 sample: ?rsp-prop-include=config-only
223 method:
224 description: The HTTP method used for the request to the APIC
225 returned: failure or debug
226 type: str
227 sample: POST
228 response:
229 description: The HTTP response from the APIC
230 returned: failure or debug
231 type: str
232 sample: OK (30 bytes)
233 status:
234 description: The HTTP status from the APIC
235 returned: failure or debug
236 type: int
237 sample: 200
238 url:
239 description: The HTTP url used for the request to the APIC
240 returned: failure or debug
241 type: str
242 sample: https://10.11.12.13/api/mo/uni/tn-production.json
243 """
244
245 from ansible.module_utils.basic import AnsibleModule
246 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
247
248
249 def main():
250 argument_spec = aci_argument_spec()
251 argument_spec.update(aci_annotation_spec())
252 argument_spec.update(aci_owner_spec())
253 argument_spec.update(
254 node_profile=dict(type="str", aliases=["name", "node_profile_name", "logical_node"]),
255 tenant=dict(type="str", aliases=["tenant_name"]),
256 l3out=dict(type="str", aliases=["l3out_name"]),
257 description=dict(type="str", aliases=["descr"]),
258 dscp=dict(
259 type="str",
260 choices=[
261 "AF11",
262 "AF12",
263 "AF13",
264 "AF21",
265 "AF22",
266 "AF23",
267 "AF31",
268 "AF32",
269 "AF33",
270 "AF41",
271 "AF42",
272 "AF43",
273 "CS0",
274 "CS1",
275 "CS2",
276 "CS3",
277 "CS4",
278 "CS5",
279 "CS6",
280 "CS7",
281 "EF",
282 "VA",
283 "unspecified",
284 ],
285 aliases=["target_dscp"],
286 ),
287 # alias=dict(type="str"), not implemented because of different (api/alias/mo/uni/) api endpoint
288 mpls_custom_qos_policy=dict(type="str", aliases=["mpls_custom_qos_policy_name"]),
289 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
290 name_alias=dict(type="str"),
291 )
292
293 module = AnsibleModule(
294 argument_spec=argument_spec,
295 supports_check_mode=True,
296 required_if=[
297 ["state", "absent", ["tenant", "l3out", "node_profile"]],
298 ["state", "present", ["tenant", "l3out", "node_profile"]],
299 ],
300 )
301
302 node_profile = module.params.get("node_profile")
303 tenant = module.params.get("tenant")
304 l3out = module.params.get("l3out")
305 description = module.params.get("description")
306 dscp = module.params.get("dscp")
307 mpls_custom_qos_policy = module.params.get("mpls_custom_qos_policy")
308 state = module.params.get("state")
309 name_alias = module.params.get("name_alias")
310
311 aci = ACIModule(module)
312
313 child_classes = []
314 if mpls_custom_qos_policy is not None:
315 child_classes.append("l3extRsLNodePMplsCustQosPol")
316
317 aci.construct_url(
318 root_class=dict(
319 aci_class="fvTenant",
320 aci_rn="tn-{0}".format(tenant),
321 module_object=tenant,
322 target_filter={"name": tenant},
323 ),
324 subclass_1=dict(
325 aci_class="l3extOut",
326 aci_rn="out-{0}".format(l3out),
327 module_object=l3out,
328 target_filter={"name": l3out},
329 ),
330 subclass_2=dict(
331 aci_class="l3extLNodeP",
332 aci_rn="lnodep-{0}".format(node_profile),
333 module_object=node_profile,
334 target_filter={"name": node_profile},
335 ),
336 child_classes=child_classes,
337 )
338
339 aci.get_existing()
340
341 if state == "present":
342 child_configs = []
343 if mpls_custom_qos_policy is not None:
344 if mpls_custom_qos_policy == "":
345 child_configs.append(dict(l3extRsLNodePMplsCustQosPol=dict(attributes=dict(status="deleted"))))
346 else:
347 child_configs.append(
348 dict(l3extRsLNodePMplsCustQosPol=dict(attributes=dict(tDn="uni/tn-infra/qosmplscustom-{0}".format(mpls_custom_qos_policy))))
349 )
350
351 aci.payload(
352 aci_class="l3extLNodeP",
353 class_config=dict(
354 descr=description,
355 name=node_profile,
356 targetDscp=dscp,
357 nameAlias=name_alias,
358 ),
359 child_configs=child_configs,
360 )
361
362 aci.get_diff(aci_class="l3extLNodeP")
363
364 aci.post_config()
365
366 elif state == "absent":
367 aci.delete_config()
368
369 aci.exit_json()
370
371
372 if __name__ == "__main__":
373 main()