Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_l4l7_concrete_interface.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_concrete_interface
17 version_added: "2.12.0"
18 short_description: Manage L4-L7 Concrete Interfaces (vns:CIf)
19 description:
20 - Manage Layer 4 to Layer 7 (L4-L7) Concrete Interfaces.
21 options:
22 tenant:
23 description:
24 - The name of an existing tenant.
25 type: str
26 aliases: [ tenant_name ]
27 logical_device:
28 description:
29 - The name of an existing logical device.
30 type: str
31 aliases: [ device_name, device, logical_device_name ]
32 concrete_device:
33 description:
34 - The name of an existing concrete device.
35 type: str
36 aliases: [ concrete_device_name ]
37 name:
38 description:
39 - The name of the concrete interface.
40 type: str
41 aliases: [ concrete_interface ]
42 pod_id:
43 description:
44 - The unique identifier for the pod where the concrete interface is located.
45 type: int
46 node_id:
47 description:
48 - The unique identifier for the node where the concrete interface is located.
49 - For Ports and Port-channels, this is represented as a single node ID.
50 - For virtual Port Channels (vPCs), this is represented as a hyphen-separated pair of node IDs, such as "201-202".
51 type: str
52 interface:
53 description:
54 - The path to the physical interface.
55 - For single ports, this is the port name, e.g. "eth1/15".
56 - For Port-channels and vPCs, this is the Interface Policy Group name.
57 type: str
58 aliases: [ path_ep, interface_name, interface_policy_group, interface_policy_group_name ]
59 vnic_name:
60 description:
61 - The concrete interface vNIC name.
62 type: str
63 state:
64 description:
65 - Use C(present) or C(absent) for adding or removing.
66 - Use C(query) for listing an object or multiple objects.
67 type: str
68 choices: [ absent, present, query ]
69 default: present
70 extends_documentation_fragment:
71 - cisco.aci.aci
72 - cisco.aci.annotation
73 notes:
74 - The I(tenant), I(logical_device) and I(concrete_device) must exist before using this module in your playbook.
75 The M(cisco.aci.aci_tenant), M(cisco.aci.aci_l4l7_device) and M(cisco.aci.aci_l4l7_concrete_device) modules can be used for this.
76 seealso:
77 - module: cisco.aci.aci_l4l7_device
78 - module: cisco.aci.aci_l4l7_concrete_device
79 - name: APIC Management Information Model reference
80 description: More information about the internal APIC class B(vns:CIf)
81 link: https://developer.cisco.com/docs/apic-mim-ref/
82 author:
83 - Tim Cragg (@timcragg)
84 - Shreyas Srish (@shrsr)
85 """
86
87 EXAMPLES = r"""
88 - name: Add a new concrete interface on a single port
89 cisco.aci.aci_l4l7_concrete_interface:
90 host: apic
91 username: admin
92 password: SomeSecretPassword
93 tenant: my_tenant
94 device: my_device
95 concrete_device: my_concrete_device
96 name: my_concrete_interface
97 pod_id: 1
98 node_id: 201
99 interface: eth1/16
100 state: present
101 delegate_to: localhost
102
103 - name: Add a new concrete interface on a vPC
104 cisco.aci.aci_l4l7_concrete_interface:
105 host: apic
106 username: admin
107 password: SomeSecretPassword
108 tenant: my_tenant
109 device: my_device
110 concrete_device: my_concrete_device
111 name: my_concrete_interface
112 pod_id: 1
113 node_id: 201-202
114 interface: my_vpc_ipg
115 state: present
116 delegate_to: localhost
117
118 - name: Query a concrete interface
119 cisco.aci.aci_l4l7_concrete_interface:
120 host: apic
121 username: admin
122 password: SomeSecretPassword
123 tenant: my_tenant
124 device: my_device
125 concrete_device: my_concrete_device
126 name: my_concrete_interface
127 pod_id: 1
128 node_id: 201-202
129 interface: my_vpc_ipg
130 state: query
131 delegate_to: localhost
132 register: query_result
133
134 - name: Query all concrete interfaces
135 cisco.aci.aci_l4l7_concrete_interface:
136 host: apic
137 username: admin
138 password: SomeSecretPassword
139 state: query
140 delegate_to: localhost
141 register: query_result
142
143 - name: Delete a concrete interface
144 cisco.aci.aci_l4l7_concrete_interface:
145 host: apic
146 username: admin
147 password: SomeSecretPassword
148 tenant: my_tenant
149 device: my_device
150 concrete_device: my_concrete_device
151 name: my_concrete_interface
152 state: absent
153 delegate_to: localhost
154 """
155
156 RETURN = r"""
157 current:
158 description: The existing configuration from the APIC after the module has finished
159 returned: success
160 type: list
161 sample:
162 [
163 {
164 "fvTenant": {
165 "attributes": {
166 "descr": "Production environment",
167 "dn": "uni/tn-production",
168 "name": "production",
169 "nameAlias": "",
170 "ownerKey": "",
171 "ownerTag": ""
172 }
173 }
174 }
175 ]
176 error:
177 description: The error information as returned from the APIC
178 returned: failure
179 type: dict
180 sample:
181 {
182 "code": "122",
183 "text": "unknown managed object class foo"
184 }
185 raw:
186 description: The raw output returned by the APIC REST API (xml or json)
187 returned: parse error
188 type: str
189 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
190 sent:
191 description: The actual/minimal configuration pushed to the APIC
192 returned: info
193 type: list
194 sample:
195 {
196 "fvTenant": {
197 "attributes": {
198 "descr": "Production environment"
199 }
200 }
201 }
202 previous:
203 description: The original configuration from the APIC before the module has started
204 returned: info
205 type: list
206 sample:
207 [
208 {
209 "fvTenant": {
210 "attributes": {
211 "descr": "Production",
212 "dn": "uni/tn-production",
213 "name": "production",
214 "nameAlias": "",
215 "ownerKey": "",
216 "ownerTag": ""
217 }
218 }
219 }
220 ]
221 proposed:
222 description: The assembled configuration from the user-provided parameters
223 returned: info
224 type: dict
225 sample:
226 {
227 "fvTenant": {
228 "attributes": {
229 "descr": "Production environment",
230 "name": "production"
231 }
232 }
233 }
234 filter_string:
235 description: The filter string used for the request
236 returned: failure or debug
237 type: str
238 sample: ?rsp-prop-include=config-only
239 method:
240 description: The HTTP method used for the request to the APIC
241 returned: failure or debug
242 type: str
243 sample: POST
244 response:
245 description: The HTTP response from the APIC
246 returned: failure or debug
247 type: str
248 sample: OK (30 bytes)
249 status:
250 description: The HTTP status from the APIC
251 returned: failure or debug
252 type: int
253 sample: 200
254 url:
255 description: The HTTP url used for the request to the APIC
256 returned: failure or debug
257 type: str
258 sample: https://10.11.12.13/api/mo/uni/tn-production.json
259 """
260
261
262 from ansible.module_utils.basic import AnsibleModule
263 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
264
265
266 def main():
267 argument_spec = aci_argument_spec()
268 argument_spec.update(aci_annotation_spec())
269 argument_spec.update(
270 tenant=dict(type="str", aliases=["tenant_name"]),
271 logical_device=dict(type="str", aliases=["device_name", "device", "logical_device_name"]),
272 concrete_device=dict(type="str", aliases=["concrete_device_name"]),
273 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
274 name=dict(type="str", aliases=["concrete_interface"]),
275 pod_id=dict(type="int"),
276 node_id=dict(type="str"),
277 interface=dict(type="str", aliases=["path_ep", "interface_name", "interface_policy_group", "interface_policy_group_name"]),
278 vnic_name=dict(type="str"),
279 )
280
281 module = AnsibleModule(
282 argument_spec=argument_spec,
283 supports_check_mode=True,
284 required_if=[
285 ["state", "absent", ["tenant", "logical_device", "concrete_device", "name"]],
286 ["state", "present", ["tenant", "logical_device", "concrete_device", "name", "pod_id", "node_id", "interface"]],
287 ],
288 )
289
290 tenant = module.params.get("tenant")
291 state = module.params.get("state")
292 logical_device = module.params.get("logical_device")
293 concrete_device = module.params.get("concrete_device")
294 name = module.params.get("name")
295 pod_id = module.params.get("pod_id")
296 node_id = module.params.get("node_id")
297 interface = module.params.get("interface")
298 vnic_name = module.params.get("vnic_name")
299
300 aci = ACIModule(module)
301
302 aci.construct_url(
303 root_class=dict(
304 aci_class="fvTenant",
305 aci_rn="tn-{0}".format(tenant),
306 module_object=tenant,
307 target_filter={"name": tenant},
308 ),
309 subclass_1=dict(
310 aci_class="vnsLDevVip",
311 aci_rn="lDevVip-{0}".format(logical_device),
312 module_object=logical_device,
313 target_filter={"name": logical_device},
314 ),
315 subclass_2=dict(
316 aci_class="vnsCDev",
317 aci_rn="cDev-{0}".format(concrete_device),
318 module_object=concrete_device,
319 target_filter={"name": concrete_device},
320 ),
321 subclass_3=dict(
322 aci_class="vnsCIf",
323 aci_rn="cIf-[{0}]".format(name),
324 module_object=name,
325 target_filter={"name": name},
326 ),
327 child_classes=["vnsRsCIfPathAtt"],
328 )
329
330 aci.get_existing()
331
332 if state == "present":
333 path_dn = "topology/pod-{0}/{1}-{2}/pathep-[{3}]".format(pod_id, "protpaths" if "-" in node_id else "paths", node_id, interface)
334 aci.payload(
335 aci_class="vnsCIf",
336 class_config=dict(
337 name=name,
338 vnicName=vnic_name,
339 ),
340 child_configs=[
341 dict(
342 vnsRsCIfPathAtt=dict(
343 attributes=dict(tDn=path_dn),
344 ),
345 ),
346 ],
347 )
348 aci.get_diff(aci_class="vnsCIf")
349
350 aci.post_config()
351
352 elif state == "absent":
353 aci.delete_config()
354
355 aci.exit_json()
356
357
358 if __name__ == "__main__":
359 main()