Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright: (c) 2024, Samita Bhattacharjee (@samitab) <samitab.cisco.com>
4
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_fabric_pod_connectivity_profile
16 short_description: Manage Fabric External Pod Connectivity Profiles (fv:PodConnP)
17 description:
18 - Manage Fabric External Pod Connectivity Profiles on Cisco ACI fabrics.
19 options:
20 pod_id:
21 description:
22 - The Pod ID associated with the Pod Connectivity Profile.
23 type: int
24 aliases: [ pod, pid ]
25 fabric_id:
26 description:
27 - The Fabric ID associated with the Pod Connectivity Profile.
28 type: int
29 aliases: [ fabric, fid ]
30 virtual_pod_id:
31 description:
32 - The Pod ID in the main fabric to which this I(pod_id) is associated. This property is valid only if this pod is a virtual pod.
33 type: int
34 aliases: [ vpod, vpod_id ]
35 description:
36 description:
37 - The description of the Pod Connectivity Profile.
38 type: str
39 aliases: [ descr ]
40 data_plane_tep:
41 description:
42 - The Data Plane TEP IPv4 address and prefix.
43 - eg. 10.1.1.1/32
44 type: str
45 aliases: [ dp_tep ]
46 unicast_tep:
47 description:
48 - The Unicast TEP IPv4 address and prefix.
49 - eg. 10.1.1.2/32
50 type: str
51 aliases: [ u_tep ]
52 state:
53 description:
54 - Use C(present) or C(absent) for adding or removing.
55 - Use C(query) for listing an object or multiple objects.
56 type: str
57 choices: [ absent, present, query ]
58 default: present
59 extends_documentation_fragment:
60 - cisco.aci.aci
61 - cisco.aci.annotation
62 - cisco.aci.owner
63
64 notes:
65 - This module requires an existing I(fabric_external_connection_profile).
66 The module M(cisco.aci.aci_fabric_external_connection_profile) can be used for this.
67 seealso:
68 - module: cisco.aci.aci_fabric_external_connection_profile
69 - name: APIC Management Information Model reference
70 description: More information about the internal APIC class B(fv:PodConnP).
71 link: https://developer.cisco.com/docs/apic-mim-ref/
72 author:
73 - Samita Bhattacharjee (@samitab)
74 """
75
76 EXAMPLES = r"""
77 - name: Add a Pod Connectivity Profile
78 cisco.aci.aci_fabric_pod_connectivity_profile:
79 host: apic
80 username: admin
81 password: SomeSecretPassword
82 fabric_id: 1
83 pod_id: 1
84 description: First pod connectivity profile
85 data_plane_tep: 10.1.1.1/32
86 unicast_tep: 10.1.1.2/32
87 state: present
88 delegate_to: localhost
89
90 - name: Query a Pod Connectivity Profile
91 cisco.aci.aci_fabric_pod_connectivity_profile:
92 host: apic
93 username: admin
94 password: SomeSecretPassword
95 fabric_id: 1
96 pod_id: 1
97 state: query
98 delegate_to: localhost
99 register: query_result
100
101 - name: Query all Pod Connectivity Profiles
102 cisco.aci.aci_fabric_pod_connectivity_profile:
103 host: apic
104 username: admin
105 password: SomeSecretPassword
106 state: query
107 delegate_to: localhost
108 register: query_result
109
110 - name: Remove a Pod Connectivity Profile
111 cisco.aci.aci_fabric_pod_connectivity_profile:
112 host: apic
113 username: admin
114 password: SomeSecretPassword
115 fabric_id: 1
116 pod_id: 1
117 state: absent
118 delegate_to: localhost
119 """
120
121 RETURN = r"""
122 current:
123 description: The existing configuration from the APIC after the module has finished
124 returned: success
125 type: list
126 sample:
127 [
128 {
129 "fvTenant": {
130 "attributes": {
131 "descr": "Production environment",
132 "dn": "uni/tn-production",
133 "name": "production",
134 "nameAlias": "",
135 "ownerKey": "",
136 "ownerTag": ""
137 }
138 }
139 }
140 ]
141 error:
142 description: The error information as returned from the APIC
143 returned: failure
144 type: dict
145 sample:
146 {
147 "code": "122",
148 "text": "unknown managed object class foo"
149 }
150 raw:
151 description: The raw output returned by the APIC REST API (xml or json)
152 returned: parse error
153 type: str
154 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
155 sent:
156 description: The actual/minimal configuration pushed to the APIC
157 returned: info
158 type: list
159 sample:
160 {
161 "fvTenant": {
162 "attributes": {
163 "descr": "Production environment"
164 }
165 }
166 }
167 previous:
168 description: The original configuration from the APIC before the module has started
169 returned: info
170 type: list
171 sample:
172 [
173 {
174 "fvTenant": {
175 "attributes": {
176 "descr": "Production",
177 "dn": "uni/tn-production",
178 "name": "production",
179 "nameAlias": "",
180 "ownerKey": "",
181 "ownerTag": ""
182 }
183 }
184 }
185 ]
186 proposed:
187 description: The assembled configuration from the user-provided parameters
188 returned: info
189 type: dict
190 sample:
191 {
192 "fvTenant": {
193 "attributes": {
194 "descr": "Production environment",
195 "name": "production"
196 }
197 }
198 }
199 filter_string:
200 description: The filter string used for the request
201 returned: failure or debug
202 type: str
203 sample: ?rsp-prop-include=config-only
204 method:
205 description: The HTTP method used for the request to the APIC
206 returned: failure or debug
207 type: str
208 sample: POST
209 response:
210 description: The HTTP response from the APIC
211 returned: failure or debug
212 type: str
213 sample: OK (30 bytes)
214 status:
215 description: The HTTP status from the APIC
216 returned: failure or debug
217 type: int
218 sample: 200
219 url:
220 description: The HTTP url used for the request to the APIC
221 returned: failure or debug
222 type: str
223 sample: https://10.11.12.13/api/mo/uni/tn-production.json
224 """
225
226 from ansible.module_utils.basic import AnsibleModule
227 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
228
229
230 def main():
231 argument_spec = aci_argument_spec()
232 argument_spec.update(aci_annotation_spec())
233 argument_spec.update(aci_owner_spec())
234 argument_spec.update(
235 pod_id=dict(type="int", aliases=["pod", "pid"]),
236 fabric_id=dict(type="int", aliases=["fabric", "fid"]),
237 virtual_pod_id=dict(type="int", aliases=["vpod", "vpod_id"]),
238 description=dict(type="str", aliases=["descr"]),
239 data_plane_tep=dict(type="str", aliases=["dp_tep"]),
240 unicast_tep=dict(type="str", aliases=["u_tep"]),
241 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
242 )
243
244 module = AnsibleModule(
245 argument_spec=argument_spec,
246 supports_check_mode=True,
247 required_if=[
248 ["state", "absent", ["fabric_id", "pod_id"]],
249 ["state", "present", ["fabric_id", "pod_id"]],
250 ],
251 )
252
253 aci = ACIModule(module)
254
255 pod_id = module.params.get("pod_id")
256 fabric_id = module.params.get("fabric_id")
257 virtual_pod_id = module.params.get("virtual_pod_id")
258 description = module.params.get("description")
259 data_plane_tep = module.params.get("data_plane_tep")
260 unicast_tep = module.params.get("unicast_tep")
261 state = module.params.get("state")
262
263 aci.construct_url(
264 root_class=dict(
265 aci_class="fvFabricExtConnP",
266 aci_rn="tn-infra/fabricExtConnP-{0}".format(fabric_id),
267 module_object=fabric_id,
268 target_filter={"id": fabric_id},
269 ),
270 subclass_1=dict(
271 aci_class="fvPodConnP",
272 aci_rn="podConnP-{0}".format(pod_id),
273 module_object=pod_id,
274 target_filter={"id": pod_id},
275 ),
276 child_classes=["fvIp", "fvExtRoutableUcastConnP"],
277 )
278
279 aci.get_existing()
280
281 if state == "present":
282 child_configs = []
283
284 # Validate if existing and remove child objects when the config does not match the provided config.
285 if isinstance(aci.existing, list) and len(aci.existing) > 0:
286 for child in aci.existing[0].get("fvPodConnP", {}).get("children", {}):
287 if child.get("fvExtRoutableUcastConnP") and child.get("fvExtRoutableUcastConnP").get("attributes").get("addr") != unicast_tep:
288 child_configs.append(
289 {
290 "fvExtRoutableUcastConnP": {
291 "attributes": {
292 "addr": child.get("fvExtRoutableUcastConnP").get("attributes").get("addr"),
293 "status": "deleted",
294 }
295 }
296 }
297 )
298 if child.get("fvIp") and child.get("fvIp").get("attributes").get("addr") != data_plane_tep:
299 child_configs.append(
300 {
301 "fvIp": {
302 "attributes": {
303 "addr": child.get("fvIp").get("attributes").get("addr"),
304 "status": "deleted",
305 }
306 }
307 }
308 )
309
310 if unicast_tep is not None:
311 child_configs.append({"fvExtRoutableUcastConnP": {"attributes": {"addr": unicast_tep}}})
312 if data_plane_tep is not None:
313 child_configs.append({"fvIp": {"attributes": {"addr": data_plane_tep}}})
314
315 aci.payload(
316 aci_class="fvPodConnP",
317 class_config=dict(
318 id=pod_id,
319 assocIntersitePodId=virtual_pod_id,
320 descr=description,
321 ),
322 child_configs=child_configs,
323 )
324
325 aci.get_diff(aci_class="fvPodConnP")
326
327 aci.post_config()
328
329 elif state == "absent":
330 aci.delete_config()
331
332 aci.exit_json()
333
334
335 if __name__ == "__main__":
336 main()