Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_l4l7_service_graph_template.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
17 version_added: "2.12.0"
18 short_description: Manage L4-L7 Service Graph Templates (vns:AbsGraph)
19 description:
20 - Manage Layer 4 to Layer 7 (L4-L7) Service Graph Templates on Cisco ACI fabrics.
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 Service Graph Template.
30 type: str
31 ui_template_type:
32 description:
33 - The UI Template Type.
34 - The APIC defaults to C(unspecified) when unset during creation.
35 type: str
36 choices: [
37 ndo_implicit_template,
38 one_node_adc_one_arm,
39 one_node_adc_one_arm_l3ext,
40 one_node_adc_two_arm,
41 one_node_fw_routed,
42 one_node_fw_trans,
43 two_node_fw_routed_adc_one_arm,
44 two_node_fw_routed_adc_one_arm_l3ext,
45 two_node_fw_routed_adc_two_arm,
46 two_node_fw_trans_adc_one_arm,
47 two_node_fw_trans_adc_one_arm_l3ext,
48 two_node_fw_trans_adc_two_arm,
49 unspecified
50 ]
51 type:
52 description:
53 - Specifies the type of Service Graph Template.
54 - The APIC defaults to C(legacy) when unset during creation.
55 type: str
56 choices: [ cloud, legacy ]
57 service_rule_type:
58 description:
59 - Defines the type of service rule applied within the Service Graph Template.
60 - The APIC defaults to C(vrf) when unset during creation.
61 type: str
62 choices: [ epg, subnet, vrf ]
63 filter_between_nodes:
64 description:
65 - Determines how traffic is filtered between nodes in the Service Graph Template.
66 - The APIC defaults to C(allow-all) when unset during creation.
67 type: str
68 choices: [ allow-all, filters-from-contract ]
69 description:
70 description:
71 - A description of the Service Graph Template.
72 type: str
73 state:
74 description:
75 - Use C(present) or C(absent) for adding or removing.
76 - Use C(query) for listing an object or multiple objects.
77 type: str
78 choices: [ absent, present, query ]
79 default: present
80 extends_documentation_fragment:
81 - cisco.aci.aci
82 - cisco.aci.annotation
83 - cisco.aci.owner
84 notes:
85 - The I(tenant) must exist before using this module in your playbook.
86 The M(cisco.aci.aci_tenant) module can be used for this.
87 seealso:
88 - module: cisco.aci.aci_tenant
89 - name: APIC Management Information Model reference
90 description: More information about the internal APIC class B(vns:AbsGraph)
91 link: https://developer.cisco.com/docs/apic-mim-ref/
92 author:
93 - Tim Cragg (@timcragg)
94 - Shreyas Srish (@shrsr)
95 """
96
97 EXAMPLES = r"""
98 - name: Add a new L4-L7 Service Graph Template
99 cisco.aci.aci_l4l7_service_graph_template:
100 host: apic
101 username: admin
102 password: SomeSecretPassword
103 tenant: my_tenant
104 service_graph: my_service_graph
105 state: present
106 delegate_to: localhost
107
108 - name: Query a Service Graph Template
109 cisco.aci.aci_l4l7_service_graph_template:
110 host: apic
111 username: admin
112 password: SomeSecretPassword
113 tenant: my_tenant
114 service_graph: my_service_graph
115 state: query
116 register: query_result
117 delegate_to: localhost
118
119 - name: Query all Service Graph Templates
120 cisco.aci.aci_l4l7_service_graph_template:
121 host: apic
122 username: admin
123 password: SomeSecretPassword
124 state: query
125 delegate_to: localhost
126 register: query_result
127
128 - name: Delete a Service Graph Template
129 cisco.aci.aci_l4l7_service_graph_template:
130 host: apic
131 username: admin
132 password: SomeSecretPassword
133 tenant: my_tenant
134 service_graph: my_service_graph
135 state: absent
136 delegate_to: localhost
137 """
138
139 RETURN = r"""
140 current:
141 description: The existing configuration from the APIC after the module has finished
142 returned: success
143 type: list
144 sample:
145 [
146 {
147 "fvTenant": {
148 "attributes": {
149 "descr": "Production environment",
150 "dn": "uni/tn-production",
151 "name": "production",
152 "nameAlias": "",
153 "ownerKey": "",
154 "ownerTag": ""
155 }
156 }
157 }
158 ]
159 error:
160 description: The error information as returned from the APIC
161 returned: failure
162 type: dict
163 sample:
164 {
165 "code": "122",
166 "text": "unknown managed object class foo"
167 }
168 raw:
169 description: The raw output returned by the APIC REST API (xml or json)
170 returned: parse error
171 type: str
172 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
173 sent:
174 description: The actual/minimal configuration pushed to the APIC
175 returned: info
176 type: list
177 sample:
178 {
179 "fvTenant": {
180 "attributes": {
181 "descr": "Production environment"
182 }
183 }
184 }
185 previous:
186 description: The original configuration from the APIC before the module has started
187 returned: info
188 type: list
189 sample:
190 [
191 {
192 "fvTenant": {
193 "attributes": {
194 "descr": "Production",
195 "dn": "uni/tn-production",
196 "name": "production",
197 "nameAlias": "",
198 "ownerKey": "",
199 "ownerTag": ""
200 }
201 }
202 }
203 ]
204 proposed:
205 description: The assembled configuration from the user-provided parameters
206 returned: info
207 type: dict
208 sample:
209 {
210 "fvTenant": {
211 "attributes": {
212 "descr": "Production environment",
213 "name": "production"
214 }
215 }
216 }
217 filter_string:
218 description: The filter string used for the request
219 returned: failure or debug
220 type: str
221 sample: ?rsp-prop-include=config-only
222 method:
223 description: The HTTP method used for the request to the APIC
224 returned: failure or debug
225 type: str
226 sample: POST
227 response:
228 description: The HTTP response from the APIC
229 returned: failure or debug
230 type: str
231 sample: OK (30 bytes)
232 status:
233 description: The HTTP status from the APIC
234 returned: failure or debug
235 type: int
236 sample: 200
237 url:
238 description: The HTTP url used for the request to the APIC
239 returned: failure or debug
240 type: str
241 sample: https://10.11.12.13/api/mo/uni/tn-production.json
242 """
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 from ansible_collections.cisco.aci.plugins.module_utils.constants import L4L7_UI_TEMPLATE_TYPE
248
249
250 def main():
251 argument_spec = aci_argument_spec()
252 argument_spec.update(aci_annotation_spec())
253 argument_spec.update(aci_owner_spec())
254 argument_spec.update(
255 tenant=dict(type="str", aliases=["tenant_name"]),
256 service_graph=dict(type="str"),
257 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
258 ui_template_type=dict(type="str", choices=list(L4L7_UI_TEMPLATE_TYPE)),
259 type=dict(type="str", choices=["cloud", "legacy"]),
260 service_rule_type=dict(type="str", choices=["epg", "subnet", "vrf"]),
261 filter_between_nodes=dict(type="str", choices=["allow-all", "filters-from-contract"]),
262 description=dict(type="str"),
263 )
264
265 module = AnsibleModule(
266 argument_spec=argument_spec,
267 supports_check_mode=True,
268 required_if=[
269 ["state", "absent", ["tenant", "service_graph"]],
270 ["state", "present", ["tenant", "service_graph"]],
271 ],
272 )
273
274 tenant = module.params.get("tenant")
275 service_graph = module.params.get("service_graph")
276 state = module.params.get("state")
277 ui_template_type = L4L7_UI_TEMPLATE_TYPE.get(module.params.get("ui_template_type"))
278 type = module.params.get("type")
279 service_rule_type = module.params.get("service_rule_type")
280 filter_between_nodes = module.params.get("filter_between_nodes")
281 description = module.params.get("description")
282
283 aci = ACIModule(module)
284
285 aci.construct_url(
286 root_class=dict(
287 aci_class="fvTenant",
288 aci_rn="tn-{0}".format(tenant),
289 module_object=tenant,
290 target_filter={"name": tenant},
291 ),
292 subclass_1=dict(
293 aci_class="vnsAbsGraph",
294 aci_rn="AbsGraph-{0}".format(service_graph),
295 module_object=service_graph,
296 target_filter={"name": service_graph},
297 ),
298 child_classes=["vnsAbsTermNodeProv", "vnsAbsTermNodeCon"],
299 )
300
301 aci.get_existing()
302
303 if state == "present":
304 aci.payload(
305 aci_class="vnsAbsGraph",
306 class_config=dict(
307 name=service_graph,
308 uiTemplateType=ui_template_type,
309 type=type,
310 svcRuleType=service_rule_type,
311 filterBetweenNodes=filter_between_nodes,
312 descr=description,
313 ),
314 )
315 aci.get_diff(aci_class="vnsAbsGraph")
316
317 aci.post_config()
318
319 elif state == "absent":
320 aci.delete_config()
321
322 aci.exit_json()
323
324
325 if __name__ == "__main__":
326 main()