Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7
8 __metaclass__ = type
9
10 ANSIBLE_METADATA = {
11 "metadata_version": "1.1",
12 "status": ["preview"],
13 "supported_by": "community",
14 }
15
16 DOCUMENTATION = r"""
17 ---
18 module: aci_l3out_interface_secondary_ip
19 short_description: Manage Layer 3 Outside (L3Out) interface secondary IP addresses (l3ext:Ip)
20 description:
21 - Manage Layer 3 Outside (L3Out) interface secondary IP addresses.
22 options:
23 tenant:
24 description:
25 - Name of an existing tenant.
26 type: str
27 aliases: [ tenant_name ]
28 l3out:
29 description:
30 - Name of an existing L3Out.
31 type: str
32 aliases: [ l3out_name ]
33 node_profile:
34 description:
35 - Name of the node profile.
36 type: str
37 aliases: [ node_profile_name, logical_node ]
38 interface_profile:
39 description:
40 - Name of the interface profile.
41 type: str
42 aliases: [ interface_profile_name, logical_interface ]
43 pod_id:
44 description:
45 - Pod to build the interface on.
46 type: str
47 node_id:
48 description:
49 - Node to build the interface on for Port-channels and single ports.
50 - Hyphen separated pair of nodes (e.g. "201-202") for vPCs.
51 type: str
52 path_ep:
53 description:
54 - Path to interface
55 - Interface Policy Group name for Port-channels and vPCs
56 - Port number for single ports (e.g. "eth1/12")
57 type: str
58 side:
59 description:
60 - Provides the side for vPC member interfaces.
61 type: str
62 choices: [ A, B ]
63 address:
64 description:
65 - Secondary IP address.
66 type: str
67 aliases: [ addr, ip_address]
68 ipv6_dad:
69 description:
70 - IPv6 DAD feature.
71 type: str
72 choices: [ enabled, disabled]
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
84 seealso:
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_logical_interface
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 - Marcel Zehnder (@maercu)
94 """
95
96 EXAMPLES = r"""
97 - name: Add a new secondary IP to a routed interface
98 cisco.aci.aci_l3out_interface_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 path_ep: eth1/12
109 address: 192.168.10.2/27
110 state: present
111 delegate_to: localhost
112
113 - name: Add a new secondary IP to a vPC member
114 cisco.aci.aci_l3out_interface_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-202
124 path_ep: my_vpc_ipg
125 side: A
126 address: 192.168.10.2/27
127 state: present
128 delegate_to: localhost
129
130 - name: Delete a secondary IP
131 cisco.aci.aci_l3out_interface_secondary_ip:
132 host: apic
133 username: admin
134 password: SomeSecretPassword
135 tenant: my_tenant
136 l3out: my_l3out
137 node_profile: my_node_profile
138 interface_profile: my_interface_profile
139 pod_id: 1
140 node_id: 201
141 path_ep: eth1/12
142 address: 192.168.10.2/27
143 state: absent
144 delegate_to: localhost
145
146 - name: Query a secondary IP
147 cisco.aci.aci_l3out_interface_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 path_ep: eth1/12
158 address: 192.168.10.2/27
159 state: query
160 delegate_to: localhost
161 register: query_result
162 """
163
164 RETURN = r"""
165 current:
166 description: The existing configuration from the APIC after the module has finished
167 returned: success
168 type: list
169 sample:
170 [
171 {
172 "fvTenant": {
173 "attributes": {
174 "descr": "Production environment",
175 "dn": "uni/tn-production",
176 "name": "production",
177 "nameAlias": "",
178 "ownerKey": "",
179 "ownerTag": ""
180 }
181 }
182 }
183 ]
184 error:
185 description: The error information as returned from the APIC
186 returned: failure
187 type: dict
188 sample:
189 {
190 "code": "122",
191 "text": "unknown managed object class foo"
192 }
193 raw:
194 description: The raw output returned by the APIC REST API (xml or json)
195 returned: parse error
196 type: str
197 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
198 sent:
199 description: The actual/minimal configuration pushed to the APIC
200 returned: info
201 type: list
202 sample:
203 {
204 "fvTenant": {
205 "attributes": {
206 "descr": "Production environment"
207 }
208 }
209 }
210 previous:
211 description: The original configuration from the APIC before the module has started
212 returned: info
213 type: list
214 sample:
215 [
216 {
217 "fvTenant": {
218 "attributes": {
219 "descr": "Production",
220 "dn": "uni/tn-production",
221 "name": "production",
222 "nameAlias": "",
223 "ownerKey": "",
224 "ownerTag": ""
225 }
226 }
227 }
228 ]
229 proposed:
230 description: The assembled configuration from the user-provided parameters
231 returned: info
232 type: dict
233 sample:
234 {
235 "fvTenant": {
236 "attributes": {
237 "descr": "Production environment",
238 "name": "production"
239 }
240 }
241 }
242 filter_string:
243 description: The filter string used for the request
244 returned: failure or debug
245 type: str
246 sample: ?rsp-prop-include=config-only
247 method:
248 description: The HTTP method used for the request to the APIC
249 returned: failure or debug
250 type: str
251 sample: POST
252 response:
253 description: The HTTP response from the APIC
254 returned: failure or debug
255 type: str
256 sample: OK (30 bytes)
257 status:
258 description: The HTTP status from the APIC
259 returned: failure or debug
260 type: int
261 sample: 200
262 url:
263 description: The HTTP url used for the request to the APIC
264 returned: failure or debug
265 type: str
266 sample: https://10.11.12.13/api/mo/uni/tn-production.json
267 """
268
269 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
270 from ansible.module_utils.basic import AnsibleModule
271
272
273 def main():
274 argument_spec = aci_argument_spec()
275 argument_spec.update(aci_annotation_spec())
276 argument_spec.update(
277 tenant=dict(type="str", aliases=["tenant_name"]),
278 l3out=dict(type="str", aliases=["l3out_name"]),
279 node_profile=dict(type="str", aliases=["node_profile_name", "logical_node"]),
280 interface_profile=dict(type="str", aliases=["interface_profile_name", "logical_interface"]),
281 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
282 pod_id=dict(type="str"),
283 node_id=dict(type="str"),
284 path_ep=dict(type="str"),
285 side=dict(type="str", choices=["A", "B"]),
286 address=dict(type="str", aliases=["addr", "ip_address"]),
287 ipv6_dad=dict(type="str", choices=["enabled", "disabled"]),
288 )
289
290 module = AnsibleModule(
291 argument_spec=argument_spec,
292 supports_check_mode=True,
293 required_if=[
294 [
295 "state",
296 "absent",
297 [
298 "tenant",
299 "l3out",
300 "node_profile",
301 "interface_profile",
302 "pod_id",
303 "node_id",
304 "path_ep",
305 ],
306 ],
307 [
308 "state",
309 "present",
310 [
311 "tenant",
312 "l3out",
313 "node_profile",
314 "interface_profile",
315 "pod_id",
316 "node_id",
317 "path_ep",
318 ],
319 ],
320 ],
321 )
322
323 tenant = module.params.get("tenant")
324 l3out = module.params.get("l3out")
325 node_profile = module.params.get("node_profile")
326 interface_profile = module.params.get("interface_profile")
327 pod_id = module.params.get("pod_id")
328 node_id = module.params.get("node_id")
329 path_ep = module.params.get("path_ep")
330 side = module.params.get("side")
331 address = module.params.get("address")
332 ipv6_dad = module.params.get("ipv6_dad")
333 state = module.params.get("state")
334
335 aci = ACIModule(module)
336
337 path_type = "paths"
338 rn_prefix = ""
339
340 if node_id:
341 if "-" in node_id:
342 path_type = "protpaths"
343 rn_prefix = "mem-{0}/".format(side)
344
345 path_dn = None
346 if pod_id and node_id and path_ep:
347 path_dn = "topology/pod-{0}/{1}-{2}/pathep-[{3}]".format(pod_id, path_type, node_id, path_ep)
348
349 aci.construct_url(
350 root_class=dict(
351 aci_class="fvTenant",
352 aci_rn="tn-{0}".format(tenant),
353 module_object=tenant,
354 target_filter={"name": tenant},
355 ),
356 subclass_1=dict(
357 aci_class="l3extOut",
358 aci_rn="out-{0}".format(l3out),
359 module_object=l3out,
360 target_filter={"name": l3out},
361 ),
362 subclass_2=dict(
363 aci_class="l3extLNodeP",
364 aci_rn="lnodep-{0}".format(node_profile),
365 module_object=node_profile,
366 target_filter={"name": node_profile},
367 ),
368 subclass_3=dict(
369 aci_class="l3extLIfP",
370 aci_rn="lifp-{0}".format(interface_profile),
371 module_object=interface_profile,
372 target_filter={"name": interface_profile},
373 ),
374 subclass_4=dict(
375 aci_class="l3extRsPathL3OutAtt",
376 aci_rn="rspathL3OutAtt-[{0}]".format(path_dn),
377 module_object=path_dn,
378 target_filter={"tDn": path_dn},
379 ),
380 subclass_5=dict(
381 aci_class="l3extIp",
382 aci_rn="{0}addr-[{1}]".format(rn_prefix, address),
383 module_object=address,
384 target_filter={"addr": address},
385 ),
386 )
387
388 aci.get_existing()
389
390 if state == "present":
391 aci.payload(aci_class="l3extIp", class_config=dict(addr=address, ipv6Dad=ipv6_dad))
392
393 aci.get_diff(aci_class="l3extIp")
394 aci.post_config()
395
396 elif state == "absent":
397 aci.delete_config()
398
399 aci.exit_json()
400
401
402 if __name__ == "__main__":
403 main()