Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2023, Gaspard Micol (@gmicol) <[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_bgp_route_summarization_policy
16 short_description: Manage BGP route summarization policy (bgp:RtSummPol)
17 description:
18 - Manage BGP route summarization policies for the Tenants on Cisco ACI fabrics.
19 options:
20 tenant:
21 description:
22 - The name of an existing tenant.
23 type: str
24 aliases: [ tenant_name ]
25 route_summarization_policy:
26 description:
27 - The name of the BGP route summarization policy.
28 type: str
29 aliases: [ route_summarization_policy_name, name ]
30 address_type_af_control:
31 description:
32 - The Ucast/Mcast address type AF control.
33 - The APIC defaults to C(af-ucast) when unset during creation.
34 - Can not be configured for APIC version 4.2(7s) or prior.
35 type: list
36 elements: str
37 choices: [ af-label-ucast, af-ucast, af-mcast ]
38 aliases: [ address_type_control ]
39 control_state:
40 description:
41 - The summary control.
42 - The C(summary_only) option can not be configured for APIC version 4.2(7s) or prior.
43 type: list
44 elements: str
45 choices: [ as-set, summary-only ]
46 aliases: [ summary_control, control ]
47 description:
48 description:
49 - Description for the BGP route summarization policy.
50 type: str
51 aliases: [ descr ]
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 name_alias:
60 description:
61 - The alias for the current object. This relates to the nameAlias field in ACI.
62 type: str
63 extends_documentation_fragment:
64 - cisco.aci.aci
65 - cisco.aci.annotation
66 - cisco.aci.owner
67
68 notes:
69 - The C(tenant) used must exist before using this module in your playbook.
70 The M(cisco.aci.aci_tenant) module can be used for this.
71 seealso:
72 - module: cisco.aci.aci_tenant
73 - name: APIC Management Information Model reference
74 description: More information about the internal APIC class B(bgp:RtSummPol).
75 link: https://developer.cisco.com/docs/apic-mim-ref/
76 author:
77 - Gaspard Micol (@gmicol)
78 """
79
80 EXAMPLES = r"""
81 - name: Create a BGP route summarization policy
82 cisco.aci.aci_bgp_route_summarization_policy:
83 host: apic
84 username: admin
85 password: SomeSecretPassword
86 route_summarization_policy: my_route_summarization_policy
87 address_type_af_control: [af-mcast, af-ucast]
88 control_state: [as-set, summary-only]
89 tenant: production
90 state: present
91 delegate_to: localhost
92
93 - name: Delete a BGP route summarization policy
94 cisco.aci.aci_bgp_route_summarization_policy:
95 host: apic
96 username: admin
97 password: SomeSecretPassword
98 route_summarization_policy: my_route_summarization_policy
99 tenant: production
100 state: absent
101 delegate_to: localhost
102
103 - name: Query all BGP route summarization policies
104 cisco.aci.aci_bgp_route_summarization_policy:
105 host: apic
106 username: admin
107 password: SomeSecretPassword
108 state: query
109 delegate_to: localhost
110 register: query_result
111
112 - name: Query a specific BGP route summarization policy
113 cisco.aci.aci_bgp_route_summarization_policy:
114 host: apic
115 username: admin
116 password: SomeSecretPassword
117 route_summarization_policy: my_route_summarization_policy
118 tenant: production
119 state: query
120 delegate_to: localhost
121 register: query_result
122 """
123
124 RETURN = r"""
125 current:
126 description: The existing configuration from the APIC after the module has finished
127 returned: success
128 type: list
129 sample:
130 [
131 {
132 "fvTenant": {
133 "attributes": {
134 "descr": "Production environment",
135 "dn": "uni/tn-production",
136 "name": "production",
137 "nameAlias": "",
138 "ownerKey": "",
139 "ownerTag": ""
140 }
141 }
142 }
143 ]
144 error:
145 description: The error information as returned from the APIC
146 returned: failure
147 type: dict
148 sample:
149 {
150 "code": "122",
151 "text": "unknown managed object class foo"
152 }
153 raw:
154 description: The raw output returned by the APIC REST API (xml or json)
155 returned: parse error
156 type: str
157 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
158 sent:
159 description: The actual/minimal configuration pushed to the APIC
160 returned: info
161 type: list
162 sample:
163 {
164 "fvTenant": {
165 "attributes": {
166 "descr": "Production environment"
167 }
168 }
169 }
170 previous:
171 description: The original configuration from the APIC before the module has started
172 returned: info
173 type: list
174 sample:
175 [
176 {
177 "fvTenant": {
178 "attributes": {
179 "descr": "Production",
180 "dn": "uni/tn-production",
181 "name": "production",
182 "nameAlias": "",
183 "ownerKey": "",
184 "ownerTag": ""
185 }
186 }
187 }
188 ]
189 proposed:
190 description: The assembled configuration from the user-provided parameters
191 returned: info
192 type: dict
193 sample:
194 {
195 "fvTenant": {
196 "attributes": {
197 "descr": "Production environment",
198 "name": "production"
199 }
200 }
201 }
202 filter_string:
203 description: The filter string used for the request
204 returned: failure or debug
205 type: str
206 sample: ?rsp-prop-include=config-only
207 method:
208 description: The HTTP method used for the request to the APIC
209 returned: failure or debug
210 type: str
211 sample: POST
212 response:
213 description: The HTTP response from the APIC
214 returned: failure or debug
215 type: str
216 sample: OK (30 bytes)
217 status:
218 description: The HTTP status from the APIC
219 returned: failure or debug
220 type: int
221 sample: 200
222 url:
223 description: The HTTP url used for the request to the APIC
224 returned: failure or debug
225 type: str
226 sample: https://10.11.12.13/api/mo/uni/tn-production.json
227 """
228
229 from ansible.module_utils.basic import AnsibleModule
230 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
231
232
233 def main():
234 argument_spec = aci_argument_spec()
235 argument_spec.update(aci_annotation_spec())
236 argument_spec.update(aci_owner_spec())
237 argument_spec.update(
238 tenant=dict(type="str", aliases=["tenant_name"]), # Not required for querying all objects
239 route_summarization_policy=dict(type="str", aliases=["route_summarization_policy_name", "name"]), # Not required for querying all objects
240 address_type_af_control=dict(type="list", elements="str", choices=["af-label-ucast", "af-ucast", "af-mcast"], aliases=["address_type_control"]),
241 control_state=dict(type="list", elements="str", choices=["as-set", "summary-only"], aliases=["summary_control", "control"]),
242 description=dict(type="str", aliases=["descr"]),
243 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
244 name_alias=dict(type="str"),
245 )
246
247 module = AnsibleModule(
248 argument_spec=argument_spec,
249 supports_check_mode=True,
250 required_if=[
251 ["state", "absent", ["route_summarization_policy", "tenant"]],
252 ["state", "present", ["route_summarization_policy", "tenant"]],
253 ],
254 )
255
256 route_summarization_policy = module.params.get("route_summarization_policy")
257 address_type_af_control = ",".join(module.params.get("address_type_af_control")) if module.params.get("address_type_af_control") else None
258 control_state = ",".join(module.params.get("control_state")) if module.params.get("control_state") else None
259 description = module.params.get("description")
260 state = module.params.get("state")
261 tenant = module.params.get("tenant")
262 name_alias = module.params.get("name_alias")
263
264 aci = ACIModule(module)
265
266 aci.construct_url(
267 root_class=dict(
268 aci_class="fvTenant",
269 aci_rn="tn-{0}".format(tenant),
270 module_object=tenant,
271 target_filter={"name": tenant},
272 ),
273 subclass_1=dict(
274 aci_class="bgpRtSummPol",
275 aci_rn="bgprtsum-{0}".format(route_summarization_policy),
276 module_object=route_summarization_policy,
277 target_filter={"name": route_summarization_policy},
278 ),
279 )
280
281 aci.get_existing()
282
283 if state == "present":
284 class_config = dict(
285 name=route_summarization_policy,
286 ctrl=control_state,
287 descr=description,
288 nameAlias=name_alias,
289 )
290
291 if address_type_af_control is not None:
292 class_config.update(dict(addrTCtrl=address_type_af_control))
293
294 aci.payload(
295 aci_class="bgpRtSummPol",
296 class_config=class_config,
297 )
298
299 aci.get_diff(aci_class="bgpRtSummPol")
300
301 aci.post_config()
302
303 elif state == "absent":
304 aci.delete_config()
305
306 aci.exit_json()
307
308
309 if __name__ == "__main__":
310 main()