Debian Codegraph @

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