Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2020, Anvitha Jain(@anvitha-jain) <[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 = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"}
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_l3out_logical_interface_vpc_member
16 short_description: Manage Member Node objects (l3ext:Member)
17 description:
18 - Manage Member Node objects (l3ext:Member)
19 options:
20 description:
21 description:
22 - The description for the logical interface VPC member.
23 type: str
24 aliases: [ descr ]
25 tenant:
26 description:
27 - Name of an existing tenant.
28 type: str
29 aliases: [ tenant_name ]
30 l3out:
31 description:
32 - Name of an existing L3Out.
33 type: str
34 aliases: [ l3out_name ]
35 node_profile:
36 description:
37 - Name of the node profile.
38 type: str
39 aliases: [ node_profile_name, logical_node ]
40 interface_profile:
41 description:
42 - Name of the interface profile.
43 type: str
44 aliases: [ interface_profile_name, logical_interface ]
45 pod_id:
46 description:
47 - Pod to of the interface.
48 type: str
49 node_id:
50 description:
51 - Hyphen separated pair of nodes (e.g. "201-202")
52 type: str
53 path_ep:
54 description:
55 - vPC Interface Policy Group name
56 type: str
57 path_dn:
58 description:
59 - DN of existing path endpoint (fabricPathEp).
60 type: str
61 side:
62 description:
63 - Provides the side of member.
64 type: str
65 choices: [ A, B ]
66 address:
67 description:
68 - IP address.
69 type: str
70 aliases: [ addr, ip_address]
71 ipv6_dad:
72 description:
73 - IPv6 DAD feature.
74 type: str
75 choices: [ enabled, disabled]
76 state:
77 description:
78 - Use C(present) or C(absent) for adding or removing.
79 - Use C(query) for listing an object or multiple objects.
80 type: str
81 choices: [ absent, present, query ]
82 default: present
83 name_alias:
84 description:
85 - The alias for the current object. This relates to the nameAlias field in ACI.
86 type: str
87 extends_documentation_fragment:
88 - cisco.aci.aci
89 - cisco.aci.annotation
90
91 notes:
92 - The L3Out vPC inteface used must exist before using this module in your playbook.
93 The M(cisco.aci.aci_l3out_logical_interface_profile) module can be used for this.
94 seealso:
95 - module: cisco.aci.aci_l3out_logical_interface_profile
96 - name: APIC Management Information Model reference
97 description: More information about the internal APIC class B(l3ext:Member).
98 link: https://developer.cisco.com/docs/apic-mim-ref/
99 author:
100 - Anvitha Jain (@anvitha-jain)
101 - Marcel Zehnder (@maercu)
102 """
103
104 EXAMPLES = r"""
105 - name: Create a VPC member based on the path_dn
106 cisco.aci.aci_l3out_logical_interface_vpc_member:
107 host: apic
108 username: admin
109 password: SomeSecretPassword
110 tenant: tenantName
111 l3out: l3out
112 node_profile: nodeName
113 interface_profile: interfaceName
114 path_dn: topology/pod-1/protpaths-101-102/pathep-[policy_group_name]
115 side: A
116 state: present
117 delegate_to: localhost
118
119 - name: Create a VPC member based pod, node and path
120 cisco.aci.aci_l3out_logical_interface_vpc_member:
121 host: apic
122 username: admin
123 password: SomeSecretPassword
124 tenant: tenantName
125 l3out: l3out
126 node_profile: nodeName
127 interface_profile: interfaceName
128 pod_id: 1
129 node_id: 101-102
130 path_ep: policy_group_name
131 side: A
132 address: 192.168.1.252/24
133 state: present
134 delegate_to: localhost
135
136 - name: Delete a VPC member
137 cisco.aci.aci_l3out_logical_interface_vpc_member:
138 host: apic
139 username: admin
140 password: SomeSecretPassword
141 tenant: tenantName
142 l3out: l3out
143 node_profile: nodeName
144 interface_profile: interfaceName
145 path_dn: topology/pod-1/protpaths-101-102/pathep-[policy_group_name]
146 side: A
147 state: absent
148 delegate_to: localhost
149
150 - name: Query all VPC members
151 cisco.aci.aci_l3out_logical_interface_vpc_member:
152 host: apic
153 username: admin
154 password: SomeSecretPassword
155 tenant: production
156 state: query
157 delegate_to: localhost
158 register: query_result
159
160 - name: Query a specific VPC member under l3out
161 cisco.aci.aci_l3out_logical_interface_vpc_member:
162 host: apic
163 username: admin
164 password: SomeSecretPassword
165 tenant: tenantName
166 l3out: l3out
167 node_profile: nodeName
168 interface_profile: interfaceName
169 path_dn: topology/pod-1/protpaths-101-102/pathep-[policy_group_name]
170 side: A
171 state: query
172 delegate_to: localhost
173 register: query_result
174 """
175
176 RETURN = r"""
177 current:
178 description: The existing configuration from the APIC after the module has finished
179 returned: success
180 type: list
181 sample:
182 [
183 {
184 "fvTenant": {
185 "attributes": {
186 "descr": "Production environment",
187 "dn": "uni/tn-production",
188 "name": "production",
189 "nameAlias": "",
190 "ownerKey": "",
191 "ownerTag": ""
192 }
193 }
194 }
195 ]
196 error:
197 description: The error information as returned from the APIC
198 returned: failure
199 type: dict
200 sample:
201 {
202 "code": "122",
203 "text": "unknown managed object class foo"
204 }
205 raw:
206 description: The raw output returned by the APIC REST API (xml or json)
207 returned: parse error
208 type: str
209 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
210 sent:
211 description: The actual/minimal configuration pushed to the APIC
212 returned: info
213 type: list
214 sample:
215 {
216 "fvTenant": {
217 "attributes": {
218 "descr": "Production environment"
219 }
220 }
221 }
222 previous:
223 description: The original configuration from the APIC before the module has started
224 returned: info
225 type: list
226 sample:
227 [
228 {
229 "fvTenant": {
230 "attributes": {
231 "descr": "Production",
232 "dn": "uni/tn-production",
233 "name": "production",
234 "nameAlias": "",
235 "ownerKey": "",
236 "ownerTag": ""
237 }
238 }
239 }
240 ]
241 proposed:
242 description: The assembled configuration from the user-provided parameters
243 returned: info
244 type: dict
245 sample:
246 {
247 "fvTenant": {
248 "attributes": {
249 "descr": "Production environment",
250 "name": "production"
251 }
252 }
253 }
254 filter_string:
255 description: The filter string used for the request
256 returned: failure or debug
257 type: str
258 sample: ?rsp-prop-include=config-only
259 method:
260 description: The HTTP method used for the request to the APIC
261 returned: failure or debug
262 type: str
263 sample: POST
264 response:
265 description: The HTTP response from the APIC
266 returned: failure or debug
267 type: str
268 sample: OK (30 bytes)
269 status:
270 description: The HTTP status from the APIC
271 returned: failure or debug
272 type: int
273 sample: 200
274 url:
275 description: The HTTP url used for the request to the APIC
276 returned: failure or debug
277 type: str
278 sample: https://10.11.12.13/api/mo/uni/tn-production.json
279 """
280
281 from ansible.module_utils.basic import AnsibleModule
282 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
283
284
285 def main():
286 argument_spec = aci_argument_spec()
287 argument_spec.update(aci_annotation_spec())
288 argument_spec.update(
289 tenant=dict(type="str", aliases=["tenant_name"]), # Not required for querying all objects
290 l3out=dict(type="str", aliases=["l3out_name"]), # Not required for querying all objects
291 node_profile=dict(type="str", aliases=["node_profile_name", "logical_node"]), # Not required for querying all objects
292 interface_profile=dict(type="str", aliases=["interface_profile_name", "logical_interface"]),
293 path_dn=dict(type="str"),
294 pod_id=dict(type="str"),
295 node_id=dict(type="str"),
296 path_ep=dict(type="str"),
297 side=dict(type="str", choices=["A", "B"]),
298 address=dict(type="str", aliases=["addr", "ip_address"]),
299 ipv6_dad=dict(type="str", choices=["enabled", "disabled"]),
300 description=dict(type="str", aliases=["descr"]),
301 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
302 name_alias=dict(type="str"),
303 )
304
305 module = AnsibleModule(
306 argument_spec=argument_spec,
307 supports_check_mode=True,
308 required_if=[
309 ["state", "present", ["side", "interface_profile", "node_profile", "l3out", "tenant"]],
310 ["state", "absent", ["side", "interface_profile", "node_profile", "l3out", "tenant"]],
311 ],
312 mutually_exclusive=[
313 ["path_dn", "pod_id"],
314 ["path_dn", "node_id"],
315 ["path_dn", "path_ep"],
316 ],
317 required_together=[
318 ["pod_id", "node_id", "path_ep"],
319 ],
320 )
321
322 aci = ACIModule(module)
323
324 tenant = module.params.get("tenant")
325 l3out = module.params.get("l3out")
326 node_profile = module.params.get("node_profile")
327 interface_profile = module.params.get("interface_profile")
328 pod_id = module.params.get("pod_id")
329 node_id = module.params.get("node_id")
330 path_ep = module.params.get("path_ep")
331 path_dn = module.params.get("path_dn")
332 side = module.params.get("side")
333 address = module.params.get("address")
334 ipv6_dad = module.params.get("ipv6_dad")
335 description = module.params.get("description")
336 state = module.params.get("state")
337 name_alias = module.params.get("name_alias")
338
339 if not path_dn:
340 if pod_id and node_id and path_ep:
341 path_dn = "topology/pod-{0}/protpaths-{1}/pathep-[{2}]".format(pod_id, node_id, path_ep)
342 else:
343 path_dn = None
344
345 aci.construct_url(
346 root_class=dict(
347 aci_class="fvTenant",
348 aci_rn="tn-{0}".format(tenant),
349 module_object=tenant,
350 target_filter={"name": tenant},
351 ),
352 subclass_1=dict(
353 aci_class="l3extOut",
354 aci_rn="out-{0}".format(l3out),
355 module_object=l3out,
356 target_filter={"name": l3out},
357 ),
358 subclass_2=dict(
359 aci_class="l3extLNodeP",
360 aci_rn="lnodep-{0}".format(node_profile),
361 module_object=node_profile,
362 target_filter={"name": node_profile},
363 ),
364 subclass_3=dict(
365 aci_class="l3extLIfP",
366 aci_rn="lifp-{0}".format(interface_profile),
367 module_object=interface_profile,
368 target_filter={"name": interface_profile},
369 ),
370 subclass_4=dict(
371 aci_class="l3extRsPathL3OutAtt",
372 aci_rn="rspathL3OutAtt-[{0}]".format(path_dn),
373 module_object=path_dn,
374 target_filter={"name": path_dn},
375 ),
376 subclass_5=dict(
377 aci_class="l3extMember",
378 aci_rn="mem-{0}".format(side),
379 module_object=side,
380 target_filter={"side": side},
381 ),
382 )
383
384 aci.get_existing()
385
386 if state == "present":
387 aci.payload(
388 aci_class="l3extMember",
389 class_config=dict(
390 side=side,
391 addr=address,
392 ipv6Dad=ipv6_dad,
393 descr=description,
394 nameAlias=name_alias,
395 ),
396 )
397
398 aci.get_diff(aci_class="l3extMember")
399
400 aci.post_config()
401
402 elif state == "absent":
403 aci.delete_config()
404
405 aci.exit_json()
406
407
408 if __name__ == "__main__":
409 main()