Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_fabric_external_connection_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_external_connection_profile
16 short_description: Manage Fabric External Connection Profiles (fv:FabricExtConnP).
17 description:
18 - Manage Fabric External Connection Profiles (Intrasite/Intersite profiles) on Cisco ACI fabrics.
19 options:
20 description:
21 description:
22 - Specifies a description of the profile definition.
23 type: str
24 aliases: [ descr ]
25 fabric_id:
26 description:
27 - The fabric identifier of the Fabric External Connection Profile.
28 type: int
29 aliases: [ id, fabric ]
30 name:
31 description:
32 - The name of the Fabric External Connection Profile.
33 type: str
34 aliases: [ profile_name ]
35 community:
36 description:
37 - Global EVPN Route Target of the Fabric External Connection Profile.
38 - eg. extended:as2-nn4:5:16
39 type: str
40 aliases: [ rt, route_target ]
41 site_id:
42 description:
43 - The site identifier of the Fabric External Connection Profile.
44 type: int
45 aliases: [ sid, site, s_id ]
46 peering_type:
47 description:
48 - The BGP EVPN Peering Type. Use either C(automatic_with_full_mesh) or C(automatic_with_rr).
49 type: str
50 choices: [ automatic_with_full_mesh, automatic_with_rr ]
51 aliases: [ p_type, peer, peer_t ]
52 peering_password:
53 description:
54 - The BGP EVPN Peering Password. Used for setting automatic peering sessions.
55 - Providing this option will always result in a change because it is a secure property that cannot be retrieved from APIC.
56 type: str
57 aliases: [ peer_password, peer_pwd ]
58 state:
59 description:
60 - Use C(present) or C(absent) for adding or removing.
61 - Use C(query) for listing an object or multiple objects.
62 type: str
63 choices: [ absent, present, query ]
64 default: present
65 extends_documentation_fragment:
66 - cisco.aci.aci
67 - cisco.aci.annotation
68 - cisco.aci.owner
69
70 seealso:
71 - name: APIC Management Information Model reference
72 description: More information about the internal APIC class B(fv:FabricExtConnP).
73 link: https://developer.cisco.com/docs/apic-mim-ref/
74 author:
75 - Samita Bhattacharjee (@samitab)
76 """
77
78 EXAMPLES = r"""
79 - name: Add a new Fabric External Connection Profile
80 cisco.aci.aci_fabric_external_connection_profile:
81 host: apic
82 username: admin
83 password: SomeSecretPassword
84 fabric_id: 1
85 name: ansible_fabric_ext_conn_profile
86 description: Fabric External Connection Profile
87 community: extended:as2-nn4:5:16
88 site_id: 1
89 peering_type: automatic_with_rr
90 peering_password: SomeSecretPeeringPassword
91 state: present
92 delegate_to: localhost
93
94 - name: Query a Fabric External Connection Profile
95 cisco.aci.aci_fabric_external_connection_profile:
96 host: apic
97 username: admin
98 password: SomeSecretPassword
99 fabric_id: 1
100 state: query
101 delegate_to: localhost
102 register: query_result
103
104 - name: Query all Fabric External Connection Profiles
105 cisco.aci.aci_fabric_external_connection_profile:
106 host: apic
107 username: admin
108 password: SomeSecretPassword
109 state: query
110 delegate_to: localhost
111 register: query_result
112
113 - name: Remove a Fabric External Connection Profile
114 cisco.aci.aci_fabric_external_connection_profile:
115 host: apic
116 username: admin
117 password: SomeSecretPassword
118 fabric_id: 1
119 state: absent
120 delegate_to: localhost
121 """
122
123 RETURN = r"""
124 current:
125 description: The existing configuration from the APIC after the module has finished
126 returned: success
127 type: list
128 sample:
129 [
130 {
131 "fvTenant": {
132 "attributes": {
133 "descr": "Production environment",
134 "dn": "uni/tn-production",
135 "name": "production",
136 "nameAlias": "",
137 "ownerKey": "",
138 "ownerTag": ""
139 }
140 }
141 }
142 ]
143 error:
144 description: The error information as returned from the APIC
145 returned: failure
146 type: dict
147 sample:
148 {
149 "code": "122",
150 "text": "unknown managed object class foo"
151 }
152 raw:
153 description: The raw output returned by the APIC REST API (xml or json)
154 returned: parse error
155 type: str
156 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
157 sent:
158 description: The actual/minimal configuration pushed to the APIC
159 returned: info
160 type: list
161 sample:
162 {
163 "fvTenant": {
164 "attributes": {
165 "descr": "Production environment"
166 }
167 }
168 }
169 previous:
170 description: The original configuration from the APIC before the module has started
171 returned: info
172 type: list
173 sample:
174 [
175 {
176 "fvTenant": {
177 "attributes": {
178 "descr": "Production",
179 "dn": "uni/tn-production",
180 "name": "production",
181 "nameAlias": "",
182 "ownerKey": "",
183 "ownerTag": ""
184 }
185 }
186 }
187 ]
188 proposed:
189 description: The assembled configuration from the user-provided parameters
190 returned: info
191 type: dict
192 sample:
193 {
194 "fvTenant": {
195 "attributes": {
196 "descr": "Production environment",
197 "name": "production"
198 }
199 }
200 }
201 filter_string:
202 description: The filter string used for the request
203 returned: failure or debug
204 type: str
205 sample: ?rsp-prop-include=config-only
206 method:
207 description: The HTTP method used for the request to the APIC
208 returned: failure or debug
209 type: str
210 sample: POST
211 response:
212 description: The HTTP response from the APIC
213 returned: failure or debug
214 type: str
215 sample: OK (30 bytes)
216 status:
217 description: The HTTP status from the APIC
218 returned: failure or debug
219 type: int
220 sample: 200
221 url:
222 description: The HTTP url used for the request to the APIC
223 returned: failure or debug
224 type: str
225 sample: https://10.11.12.13/api/mo/uni/tn-production.json
226 """
227
228 from ansible.module_utils.basic import AnsibleModule
229 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
230
231
232 def main():
233 argument_spec = aci_argument_spec()
234 argument_spec.update(aci_annotation_spec())
235 argument_spec.update(aci_owner_spec())
236 argument_spec.update(
237 description=dict(type="str", aliases=["descr"]),
238 fabric_id=dict(type="int", aliases=["id", "fabric"]),
239 name=dict(type="str", aliases=["profile_name"]),
240 community=dict(type="str", aliases=["rt", "route_target"]),
241 site_id=dict(type="int", aliases=["sid", "site", "s_id"]),
242 peering_type=dict(type="str", aliases=["p_type", "peer", "peer_t"], choices=["automatic_with_full_mesh", "automatic_with_rr"]),
243 peering_password=dict(type="str", aliases=["peer_password", "peer_pwd"], no_log=True),
244 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
245 )
246
247 module = AnsibleModule(
248 argument_spec=argument_spec,
249 supports_check_mode=True,
250 required_if=[
251 ["state", "absent", ["fabric_id"]],
252 ["state", "present", ["fabric_id"]],
253 ],
254 )
255
256 aci = ACIModule(module)
257
258 description = module.params.get("description")
259 fabric_id = module.params.get("fabric_id")
260 name = module.params.get("name")
261 community = module.params.get("community")
262 peering_type = module.params.get("peering_type")
263 peering_password = module.params.get("peering_password")
264 site_id = module.params.get("site_id")
265 state = module.params.get("state")
266
267 aci.construct_url(
268 root_class=dict(
269 aci_class="fvFabricExtConnP",
270 aci_rn="tn-infra/fabricExtConnP-{0}".format(fabric_id),
271 module_object=fabric_id,
272 target_filter={"id": fabric_id},
273 ),
274 child_classes=["fvPeeringP"],
275 )
276
277 aci.get_existing()
278
279 if state == "present":
280 child_configs = None
281 if peering_type is not None or peering_password is not None:
282 peering_p = {"fvPeeringP": {"attributes": {}}}
283 if peering_type is not None:
284 peering_p["fvPeeringP"]["attributes"]["type"] = peering_type
285 if peering_password is not None:
286 peering_p["fvPeeringP"]["attributes"]["password"] = peering_password
287 child_configs = [peering_p]
288
289 aci.payload(
290 aci_class="fvFabricExtConnP",
291 class_config=dict(
292 descr=description,
293 id=fabric_id,
294 name=name,
295 rt=community,
296 siteId=site_id,
297 ),
298 child_configs=child_configs,
299 )
300
301 aci.get_diff(aci_class="fvFabricExtConnP")
302
303 aci.post_config()
304
305 elif state == "absent":
306 aci.delete_config()
307
308 aci.exit_json()
309
310
311 if __name__ == "__main__":
312 main()