Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2025, Tim Cragg (@timcragg)
5 # Copyright: (c) 2025, Shreyas Srish (@shrsr)
6 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
7
8 from __future__ import absolute_import, division, print_function
9
10 __metaclass__ = type
11
12 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "community"}
13
14 DOCUMENTATION = r"""
15 ---
16 module: aci_l4l7_service_graph_template_node
17 version_added: "2.12.0"
18 short_description: Manage L4-L7 Service Graph Templates Nodes (vns:AbsNode)
19 description:
20 - Manage Manage L4-L7 Service Graph Templates Nodes.
21 options:
22 tenant:
23 description:
24 - The name of an existing tenant.
25 type: str
26 aliases: [ tenant_name ]
27 service_graph:
28 description:
29 - The name of an existing Service Graph.
30 type: str
31 description:
32 description:
33 - The description of the Service Graph Template Node.
34 type: str
35 node:
36 description:
37 - The name of the Service Graph Template Node.
38 type: str
39 functional_template_type:
40 description:
41 - The functional template type for the node.
42 - The APIC defaults to C(other) when unset during creation.
43 type: str
44 choices: [
45 adc_one_arm,
46 adc_two_arm,
47 cloud_native_fw,
48 cloud_native_lb,
49 cloud_vendor_fw,
50 cloud_vendor_lb,
51 fw_routed,
52 fw_trans,
53 other
54 ]
55 aliases: [ func_template_type ]
56 function_type:
57 description:
58 - The type of function.
59 - The APIC defaults to C(go_to) when unset during creation.
60 type: str
61 choices: [ go_to, go_through, l1, l2 ]
62 aliases: [ func_type ]
63 device:
64 description:
65 - The name of an existing logical device.
66 type: str
67 device_tenant:
68 description:
69 - The tenant the logical device exists under.
70 - This variable is only used if logical device and node exist within different tenants.
71 - Intended use case is when the device is in the C(common) tenant but the node is not.
72 type: str
73 managed:
74 description:
75 - Whether this device managed by the apic.
76 - The APIC defaults to C(true) when unset during creation.
77 type: bool
78 routing_mode:
79 description:
80 - The routing mode for the node.
81 - The APIC defaults to C(unspecified) when unset during creation.
82 type: str
83 choices: [ redirect, unspecified ]
84 is_copy:
85 description:
86 - Whether the device is a copy device.
87 - The APIC defaults to C(false) when unset during creation.
88 type: bool
89 share_encap:
90 description:
91 - Whether to share encapsulation across the service graph.
92 - The APIC defaults to C(false) when unset during creation.
93 type: bool
94 state:
95 description:
96 - Use C(present) or C(absent) for adding or removing.
97 - Use C(query) for listing an object or multiple objects.
98 type: str
99 choices: [ absent, present, query ]
100 default: present
101 extends_documentation_fragment:
102 - cisco.aci.aci
103 - cisco.aci.annotation
104 - cisco.aci.owner
105 notes:
106 - The I(tenant), I(service_graph) and I(device) must exist before using this module in your playbook.
107 The M(cisco.aci.aci_tenant), M(cisco.aci.aci_l4l7_service_graph_template) and M(cisco.aci.aci_l4l7_device) modules can be used for this.
108 seealso:
109 - module: cisco.aci.aci_tenant
110 - module: cisco.aci.aci_l4l7_service_graph_template
111 - module: cisco.aci.aci_l4l7_device
112 - name: APIC Management Information Model reference
113 description: More information about the internal APIC classes B(vnsAbsNode)
114 link: https://developer.cisco.com/docs/apic-mim-ref/
115 author:
116 - Tim Cragg (@timcragg)
117 - Shreyas Srish (@shrsr)
118 """
119
120 EXAMPLES = r"""
121 - name: Add a new Service Graph Template Node
122 cisco.aci.aci_l4l7_service_graph_template_node:
123 host: apic
124 username: admin
125 password: SomeSecretPassword
126 tenant: my_tenant
127 service_graph: test-graph
128 node: test-node
129 functional_template_type: adc_one_arm
130 function_type: GoTo
131 device: test-device
132 managed: false
133 routing_mode: redirect
134 state: present
135 delegate_to: localhost
136
137 - name: Query a Service Graph Template Node
138 cisco.aci.aci_l4l7_service_graph_template_node:
139 host: apic
140 username: admin
141 password: SomeSecretPassword
142 tenant: my_tenant
143 service_graph: test-graph
144 node: test-node
145 state: query
146 delegate_to: localhost
147 register: query_result
148
149 - name: Query all Service Graph Template Nodes
150 cisco.aci.aci_l4l7_service_graph_template_node:
151 host: apic
152 username: admin
153 password: SomeSecretPassword
154 state: query
155 delegate_to: localhost
156 register: query_result
157
158 - name: Delete a Service Graph Template Node
159 cisco.aci.aci_l4l7_service_graph_template_node:
160 host: apic
161 username: admin
162 password: SomeSecretPassword
163 tenant: my_tenant
164 service_graph: test-graph
165 node: test-node
166 state: absent
167 delegate_to: localhost
168 """
169
170 RETURN = r"""
171 current:
172 description: The existing configuration from the APIC after the module has finished
173 returned: success
174 type: list
175 sample:
176 [
177 {
178 "fvTenant": {
179 "attributes": {
180 "descr": "Production environment",
181 "dn": "uni/tn-production",
182 "name": "production",
183 "nameAlias": "",
184 "ownerKey": "",
185 "ownerTag": ""
186 }
187 }
188 }
189 ]
190 error:
191 description: The error information as returned from the APIC
192 returned: failure
193 type: dict
194 sample:
195 {
196 "code": "122",
197 "text": "unknown managed object class foo"
198 }
199 raw:
200 description: The raw output returned by the APIC REST API (xml or json)
201 returned: parse error
202 type: str
203 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
204 sent:
205 description: The actual/minimal configuration pushed to the APIC
206 returned: info
207 type: list
208 sample:
209 {
210 "fvTenant": {
211 "attributes": {
212 "descr": "Production environment"
213 }
214 }
215 }
216 previous:
217 description: The original configuration from the APIC before the module has started
218 returned: info
219 type: list
220 sample:
221 [
222 {
223 "fvTenant": {
224 "attributes": {
225 "descr": "Production",
226 "dn": "uni/tn-production",
227 "name": "production",
228 "nameAlias": "",
229 "ownerKey": "",
230 "ownerTag": ""
231 }
232 }
233 }
234 ]
235 proposed:
236 description: The assembled configuration from the user-provided parameters
237 returned: info
238 type: dict
239 sample:
240 {
241 "fvTenant": {
242 "attributes": {
243 "descr": "Production environment",
244 "name": "production"
245 }
246 }
247 }
248 filter_string:
249 description: The filter string used for the request
250 returned: failure or debug
251 type: str
252 sample: ?rsp-prop-include=config-only
253 method:
254 description: The HTTP method used for the request to the APIC
255 returned: failure or debug
256 type: str
257 sample: POST
258 response:
259 description: The HTTP response from the APIC
260 returned: failure or debug
261 type: str
262 sample: OK (30 bytes)
263 status:
264 description: The HTTP status from the APIC
265 returned: failure or debug
266 type: int
267 sample: 200
268 url:
269 description: The HTTP url used for the request to the APIC
270 returned: failure or debug
271 type: str
272 sample: https://10.11.12.13/api/mo/uni/tn-production.json
273 """
274
275
276 from ansible.module_utils.basic import AnsibleModule
277 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
278 from ansible_collections.cisco.aci.plugins.module_utils.constants import L4L7_FUNC_TYPES_MAPPING, L4L7_FUNCTIONAL_TEMPLATE_TYPES_MAPPING
279
280
281 def main():
282 argument_spec = aci_argument_spec()
283 argument_spec.update(aci_annotation_spec())
284 argument_spec.update(aci_owner_spec())
285 argument_spec.update(
286 tenant=dict(type="str", aliases=["tenant_name"]),
287 service_graph=dict(type="str"),
288 node=dict(type="str"),
289 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
290 functional_template_type=dict(type="str", aliases=["func_template_type"], choices=list(L4L7_FUNCTIONAL_TEMPLATE_TYPES_MAPPING)),
291 function_type=dict(type="str", aliases=["func_type"], choices=list(L4L7_FUNC_TYPES_MAPPING)),
292 device=dict(type="str"),
293 device_tenant=dict(type="str"),
294 managed=dict(type="bool"),
295 routing_mode=dict(type="str", choices=["redirect", "unspecified"]),
296 is_copy=dict(type="bool"),
297 description=dict(type="str"),
298 share_encap=dict(type="bool"),
299 )
300
301 module = AnsibleModule(
302 argument_spec=argument_spec,
303 supports_check_mode=True,
304 required_if=[
305 ["state", "absent", ["tenant", "service_graph", "node"]],
306 ["state", "present", ["tenant", "service_graph", "node", "device"]],
307 ],
308 )
309
310 aci = ACIModule(module)
311
312 tenant = module.params.get("tenant")
313 service_graph = module.params.get("service_graph")
314 node = module.params.get("node")
315 state = module.params.get("state")
316 functional_template_type = L4L7_FUNCTIONAL_TEMPLATE_TYPES_MAPPING.get(module.params.get("functional_template_type"))
317 function_type = L4L7_FUNC_TYPES_MAPPING.get(module.params.get("function_type"))
318 device = module.params.get("device")
319 device_tenant = module.params.get("device_tenant")
320 managed = aci.boolean(module.params.get("managed"))
321 routing_mode = "Redirect" if module.params.get("routing_mode") == "redirect" else module.params.get("routing_mode")
322 is_copy = aci.boolean(module.params.get("is_copy"))
323 description = module.params.get("description")
324 share_encap = aci.boolean(module.params.get("share_encap"))
325
326 aci.construct_url(
327 root_class=dict(
328 aci_class="fvTenant",
329 aci_rn="tn-{0}".format(tenant),
330 module_object=tenant,
331 target_filter={"name": tenant},
332 ),
333 subclass_1=dict(
334 aci_class="vnsAbsGraph",
335 aci_rn="AbsGraph-{0}".format(service_graph),
336 module_object=service_graph,
337 target_filter={"name": service_graph},
338 ),
339 subclass_2=dict(
340 aci_class="vnsAbsNode",
341 aci_rn="AbsNode-{0}".format(node),
342 module_object=node,
343 target_filter={"name": node},
344 ),
345 child_classes=["vnsRsNodeToLDev"],
346 )
347
348 aci.get_existing()
349 if not device_tenant:
350 device_tenant = tenant
351 dev_tdn = "uni/tn-{0}/lDevVip-{1}".format(device_tenant, device)
352
353 if state == "present":
354 aci.payload(
355 aci_class="vnsAbsNode",
356 class_config=dict(
357 name=node,
358 funcTemplateType=functional_template_type,
359 funcType=function_type,
360 managed=managed,
361 routingMode=routing_mode,
362 isCopy=is_copy,
363 descr=description,
364 shareEncap=share_encap,
365 ),
366 child_configs=[
367 dict(
368 vnsRsNodeToLDev=dict(
369 attributes=dict(tDn=dev_tdn),
370 ),
371 ),
372 ],
373 )
374 aci.get_diff(aci_class="vnsAbsNode")
375
376 aci.post_config()
377
378 elif state == "absent":
379 aci.delete_config()
380
381 aci.exit_json()
382
383
384 if __name__ == "__main__":
385 main()