Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2023, Shreyas Srish <[email protected]>
5 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8
9 __metaclass__ = type
10
11 ANSIBLE_METADATA = {
12 "metadata_version": "1.1",
13 "status": ["preview"],
14 "supported_by": "community",
15 }
16
17 DOCUMENTATION = r"""
18 ---
19 module: aci_l3out_floating_svi_secondary_ip
20 short_description: Manages Layer 3 Outside (L3Out) Floating SVI Secondary IP addresses (l3ext:Ip)
21 description:
22 - Manages L3Out Floating SVI secondary IP addresses on Cisco ACI fabrics.
23 options:
24 tenant:
25 description:
26 - Name of an existing tenant.
27 type: str
28 aliases: [ tenant_name ]
29 required: true
30 l3out:
31 description:
32 - Name of an existing L3Out.
33 type: str
34 aliases: [ l3out_name ]
35 required: true
36 node_profile:
37 description:
38 - Name of the node profile.
39 type: str
40 aliases: [ node_profile_name, logical_node ]
41 required: true
42 interface_profile:
43 description:
44 - Name of the interface profile.
45 type: str
46 aliases: [ interface_profile_name, logical_interface ]
47 required: true
48 pod_id:
49 description:
50 - Pod to build the interface on.
51 type: str
52 required: true
53 node_id:
54 description:
55 - Node to build the interface on for Port-channels and single ports.
56 type: str
57 required: true
58 encap:
59 description:
60 - Encapsulation on the interface (e.g. "vlan-500")
61 type: str
62 required: true
63 secondary_ip:
64 description:
65 - The secondary floating IP address.
66 type: str
67 aliases: [ secondary_floating_address ]
68 state:
69 description:
70 - Use C(present) or C(absent) for adding or removing.
71 - Use C(query) for listing an object or multiple objects.
72 type: str
73 choices: [ absent, present, query ]
74 default: present
75 extends_documentation_fragment:
76 - cisco.aci.aci
77 - cisco.aci.annotation
78
79 notes:
80 - The C(tenant), C(l3out), C(logical_node_profile), C(logical_interface_profile) and C(floating_svi) must exist before using this module in your playbook.
81 The M(cisco.aci.aci_tenant), M(cisco.aci.aci_l3out), M(cisco.aci.aci_l3out_logical_node_profile), M(cisco.aci.aci_l3out_logical_interface_profile) and \
82 M(cisco.aci.aci_l3out_floating_svi) can be used for this.
83 seealso:
84 - module: cisco.aci.aci_tenant
85 - module: cisco.aci.aci_l3out
86 - module: cisco.aci.aci_l3out_logical_node_profile
87 - module: cisco.aci.aci_l3out_logical_interface_profile
88 - module: cisco.aci.aci_l3out_floating_svi
89 - name: APIC Management Information Model reference
90 description: More information about the internal APIC class B(l3ext:Ip)
91 link: https://developer.cisco.com/docs/apic-mim-ref/
92 author:
93 - Shreyas Srish (@shrsr)
94 """
95
96 EXAMPLES = r"""
97 - name: Create a Floating SVI secondary IP
98 cisco.aci.aci_l3out_floating_svi_secondary_ip:
99 host: apic
100 username: admin
101 password: SomeSecretPassword
102 tenant: my_tenant
103 l3out: my_l3out
104 node_profile: my_node_profile
105 interface_profile: my_interface_profile
106 pod_id: 1
107 node_id: 201
108 encap: vlan-1
109 secondary_ip: 23.45.67.90/24
110 state: present
111 delegate_to: localhost
112
113 - name: Remove a Floating SVI secondary IP
114 cisco.aci.aci_l3out_floating_svi_secondary_ip:
115 host: apic
116 username: admin
117 password: SomeSecretPassword
118 tenant: my_tenant
119 l3out: my_l3out
120 node_profile: my_node_profile
121 interface_profile: my_interface_profile
122 pod_id: 1
123 node_id: 201
124 encap: vlan-1
125 secondary_ip: 23.45.67.90/24
126 state: absent
127 delegate_to: localhost
128
129 - name: Query a Floating SVI secondary IP
130 cisco.aci.aci_l3out_floating_svi_secondary_ip:
131 host: apic
132 username: admin
133 password: SomeSecretPassword
134 tenant: my_tenant
135 l3out: my_l3out
136 node_profile: my_node_profile
137 interface_profile: my_interface_profile
138 pod_id: 1
139 node_id: 201
140 encap: vlan-1
141 secondary_ip: 23.45.67.90/24
142 state: query
143 delegate_to: localhost
144 register: query_result
145
146 - name: Query all the secondary IPs under a Floating SVI
147 cisco.aci.aci_l3out_floating_svi_secondary_ip:
148 host: apic
149 username: admin
150 password: SomeSecretPassword
151 tenant: my_tenant
152 l3out: my_l3out
153 node_profile: my_node_profile
154 interface_profile: my_interface_profile
155 pod_id: 1
156 node_id: 201
157 encap: vlan-1
158 state: query
159 delegate_to: localhost
160 register: query_results
161 """
162
163 RETURN = r"""
164 current:
165 description: The existing configuration from the APIC after the module has finished
166 returned: success
167 type: list
168 sample:
169 [
170 {
171 "fvTenant": {
172 "attributes": {
173 "descr": "Production environment",
174 "dn": "uni/tn-production",
175 "name": "production",
176 "nameAlias": "",
177 "ownerKey": "",
178 "ownerTag": ""
179 }
180 }
181 }
182 ]
183 error:
184 description: The error information as returned from the APIC
185 returned: failure
186 type: dict
187 sample:
188 {
189 "code": "122",
190 "text": "unknown managed object class foo"
191 }
192 raw:
193 description: The raw output returned by the APIC REST API (xml or json)
194 returned: parse error
195 type: str
196 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
197 sent:
198 description: The actual/minimal configuration pushed to the APIC
199 returned: info
200 type: list
201 sample:
202 {
203 "fvTenant": {
204 "attributes": {
205 "descr": "Production environment"
206 }
207 }
208 }
209 previous:
210 description: The original configuration from the APIC before the module has started
211 returned: info
212 type: list
213 sample:
214 [
215 {
216 "fvTenant": {
217 "attributes": {
218 "descr": "Production",
219 "dn": "uni/tn-production",
220 "name": "production",
221 "nameAlias": "",
222 "ownerKey": "",
223 "ownerTag": ""
224 }
225 }
226 }
227 ]
228 proposed:
229 description: The assembled configuration from the user-provided parameters
230 returned: info
231 type: dict
232 sample:
233 {
234 "fvTenant": {
235 "attributes": {
236 "descr": "Production environment",
237 "name": "production"
238 }
239 }
240 }
241 filter_string:
242 description: The filter string used for the request
243 returned: failure or debug
244 type: str
245 sample: ?rsp-prop-include=config-only
246 method:
247 description: The HTTP method used for the request to the APIC
248 returned: failure or debug
249 type: str
250 sample: POST
251 response:
252 description: The HTTP response from the APIC
253 returned: failure or debug
254 type: str
255 sample: OK (30 bytes)
256 status:
257 description: The HTTP status from the APIC
258 returned: failure or debug
259 type: int
260 sample: 200
261 url:
262 description: The HTTP url used for the request to the APIC
263 returned: failure or debug
264 type: str
265 sample: https://10.11.12.13/api/mo/uni/tn-production.json
266 """
267
268 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
269 from ansible.module_utils.basic import AnsibleModule
270
271
272 def main():
273 argument_spec = aci_argument_spec()
274 argument_spec.update(aci_annotation_spec())
275 argument_spec.update(
276 tenant=dict(type="str", aliases=["tenant_name"], required=True),
277 l3out=dict(type="str", aliases=["l3out_name"], required=True),
278 node_profile=dict(type="str", aliases=["node_profile_name", "logical_node"], required=True),
279 interface_profile=dict(type="str", aliases=["interface_profile_name", "logical_interface"], required=True),
280 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
281 pod_id=dict(type="str", required=True),
282 node_id=dict(type="str", required=True),
283 encap=dict(type="str", required=True),
284 secondary_ip=dict(type="str", aliases=["secondary_floating_address"]),
285 )
286
287 module = AnsibleModule(
288 argument_spec=argument_spec,
289 supports_check_mode=True,
290 required_if=[
291 ["state", "absent", ["secondary_ip"]],
292 ["state", "present", ["secondary_ip"]],
293 ],
294 )
295
296 tenant = module.params.get("tenant")
297 l3out = module.params.get("l3out")
298 node_profile = module.params.get("node_profile")
299 interface_profile = module.params.get("interface_profile")
300 pod_id = module.params.get("pod_id")
301 node_id = module.params.get("node_id")
302 encap = module.params.get("encap")
303 secondary_ip = module.params.get("secondary_ip")
304 state = module.params.get("state")
305
306 aci = ACIModule(module)
307
308 node_dn = "topology/pod-{0}/node-{1}".format(pod_id, node_id)
309
310 aci.construct_url(
311 root_class=dict(
312 aci_class="fvTenant",
313 aci_rn="tn-{0}".format(tenant),
314 module_object=tenant,
315 target_filter={"name": tenant},
316 ),
317 subclass_1=dict(
318 aci_class="l3extOut",
319 aci_rn="out-{0}".format(l3out),
320 module_object=l3out,
321 target_filter={"name": l3out},
322 ),
323 subclass_2=dict(
324 aci_class="l3extLNodeP",
325 aci_rn="lnodep-{0}".format(node_profile),
326 module_object=node_profile,
327 target_filter={"name": node_profile},
328 ),
329 subclass_3=dict(
330 aci_class="l3extLIfP",
331 aci_rn="lifp-{0}".format(interface_profile),
332 module_object=interface_profile,
333 target_filter={"name": interface_profile},
334 ),
335 subclass_4=dict(
336 aci_class="l3extVirtualLIfP", aci_rn="vlifp-[{0}]-[{1}]".format(node_dn, encap), module_object=node_dn, target_filter={"nodeDn": node_dn}
337 ),
338 subclass_5=dict(
339 aci_class="l3extIp",
340 aci_rn="addr-[{0}]".format(secondary_ip),
341 module_object=secondary_ip,
342 target_filter={"addr": secondary_ip},
343 ),
344 )
345
346 aci.get_existing()
347
348 if state == "present":
349 aci.payload(aci_class="l3extIp", class_config=dict(addr=secondary_ip, ipv6Dad="enabled"))
350
351 aci.get_diff(aci_class="l3extIp")
352
353 aci.post_config()
354
355 elif state == "absent":
356 aci.delete_config()
357
358 aci.exit_json()
359
360
361 if __name__ == "__main__":
362 main()