Debian Codegraph @

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