Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_bgp_ext_communities.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2025 Dell Inc. or its subsidiaries. All Rights Reserved.
4 # GNU General Public License v3.0+
5 # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 """
8 The module file for sonic_bgp_ext_communities
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_bgp_ext_communities
17 version_added: 1.0.0
18 notes:
19 - Tested against Enterprise SONiC Distribution by Dell Technologies.
20 - Supports C(check_mode).
21 short_description: Manage BGP extended community-list and its parameters
22 description:
23 - This module provides configuration management of BGP extcommunity-list for devices running
24 Enterprise SONiC Distribution by Dell Technologies.
25 author: Kumaraguru Narayanan (@nkumaraguru)
26 options:
27 config:
28 description: A list of 'bgp_extcommunity_list' configurations.
29 type: list
30 elements: dict
31 suboptions:
32 name:
33 required: True
34 type: str
35 description:
36 - Name of the BGP ext communitylist.
37 type:
38 type: str
39 description:
40 - Whether it is a standard or expanded ext community_list entry.
41 required: False
42 choices:
43 - standard
44 - expanded
45 default: standard
46 permit:
47 required: False
48 type: bool
49 description:
50 - Permits or denies this community.
51 - Default value while adding a new ext-community-list is False.
52 members:
53 required: False
54 type: dict
55 suboptions:
56 regex:
57 type: list
58 elements: str
59 required: False
60 description:
61 - Members of this BGP ext community list. Regular expression string can be given here. Applicable for expanded ext BGP community type.
62 route_target:
63 type: list
64 elements: str
65 required: False
66 description:
67 - Members of this BGP ext community list. The format of route_target is in either 0..65535:0..65535 or A.B.C.D:[1..65535] format.
68 route_origin:
69 type: list
70 elements: str
71 required: False
72 description:
73 - Members of this BGP ext community list. The format of route_origin is in either 0..65535:0..65535 or A.B.C.D:[1..65535] format.
74 description:
75 - Members of this BGP ext community list.
76 match:
77 required: False
78 type: str
79 description:
80 - Matches any/all of the the members.
81 choices:
82 - all
83 - any
84 default: any
85 state:
86 description:
87 - The state of the configuration after module completion.
88 type: str
89 choices:
90 - merged
91 - deleted
92 - replaced
93 - overridden
94 default: merged
95 """
96
97 EXAMPLES = """
98 # Using "deleted" state
99
100 # Before state:
101 # -------------
102 #
103 # show bgp ext-community-list
104 # Standard extended community list test: match: ANY
105 # permit rt:101:101
106 # permit rt:201:201
107
108 - name: Deletes a BGP ext community member
109 dellemc.enterprise_sonic.sonic_bgp_ext_communities:
110 config:
111 - name: test
112 type: standard
113 members:
114 route_target:
115 - 201:201
116 state: deleted
117
118 # After state:
119 # ------------
120 #
121 # show bgp ext-community-list
122 # Standard extended community list test: match: ANY
123 # permit rt:101:101
124 #
125
126
127 # Using "deleted" state
128
129 # Before state:
130 # -------------
131 #
132 # show bgp ext-community-list
133 # Standard extended community list test: match: ANY
134 # permit rt:101:101
135 # permit rt:201:201
136 # Expanded extended community list test1: match: ALL
137 # deny 101:102
138
139 - name: Deletes a single BGP extended community
140 dellemc.enterprise_sonic.sonic_bgp_ext_communities:
141 config:
142 - name: test1
143 members:
144 state: deleted
145
146 # After state:
147 # ------------
148 #
149 # show bgp ext-community-list
150 # Standard extended community list test: match: ANY
151 # permit rt:101:101
152 # permit rt:201:201
153 #
154
155
156 # Using "deleted" state
157
158 # Before state:
159 # -------------
160 #
161 # show bgp ext-community-list
162 # Standard extended community list test: match: ANY
163 # permit rt:101:101
164 # permit rt:201:201
165 # Expanded extended community list test1: match: ALL
166 # deny 101:102
167
168 - name: Deletes all BGP extended communities
169 dellemc.enterprise_sonic.sonic_bgp_ext_communities:
170 config:
171 state: deleted
172
173 # After state:
174 # ------------
175 #
176 # show bgp ext-community-list
177 #
178
179
180 # Using "deleted" state
181
182 # Before state:
183 # -------------
184 #
185 # show bgp ext-community-list
186 # Standard extended community list test: match: ANY
187 # permit rt:101:101
188 # permit rt:201:201
189 # Expanded extended community list test1: match: ALL
190 # deny 101:102
191
192 - name: Deletes all members in a single BGP extended community
193 dellemc.enterprise_sonic.sonic_bgp_ext_communities:
194 config:
195 - name: test1
196 members:
197 regex:
198 state: deleted
199
200 # After state:
201 # ------------
202 #
203 # show bgp ext-community-list
204 # Standard extended community list test: match: ANY
205 # permit rt:101:101
206 # permit rt:201:201
207 #
208
209
210 # Using "merged" state
211
212 # Before state:
213 # -------------
214 #
215 # show bgp ext-community-list
216 # Standard extended community list test: match: ANY
217 # permit rt:101:101
218 # permit rt:201:201
219 # Expanded extended community list test1: match: ALL
220 # deny 101:102
221
222 - name: Adds new community list
223 dellemc.enterprise_sonic.sonic_bgp_ext_communities:
224 config:
225 - name: test3
226 type: standard
227 match: any
228 permit: true
229 members:
230 route_origin:
231 - "301:301"
232 - "401:401"
233 state: merged
234
235 # After state:
236 # ------------
237 #
238 # show bgp ext-community-list
239 # Standard extended community list test: match: ANY
240 # permit rt:101:101
241 # permit rt:201:201
242 # Expanded extended community list test1: match: ALL
243 # deny 101:102
244 # Standard extended community list test3: match: ANY
245 # permit soo:301:301
246 # permit soo:401:401
247
248
249 # Using "replaced" state
250
251 # Before state:
252 # -------------
253 #
254 # show bgp ext-community-list
255 # Standard extended community list test: match: ANY
256 # permit rt:101:101
257 # permit rt:201:201
258 # Expanded extended community list test1: match: ALL
259 # deny 101:102
260
261 - name: Replacing a single BGP extended community
262 dellemc.enterprise_sonic.sonic_bgp_ext_communities:
263 config:
264 - name: test
265 type: expanded
266 permit: true
267 match: all
268 members:
269 regex:
270 - 301:302
271 state: replaced
272
273 # After state:
274 # ------------
275 #
276 # show bgp ext-community-list
277 # Expanded extended community list test: match: ALL
278 # permit 301:302
279 # Expanded extended community list test1: match: ALL
280 # deny 101:102
281 #
282
283
284 # Using "overridden" state
285
286 # Before state:
287 # -------------
288 #
289 # show bgp ext-community-list
290 # Standard extended community list test: match: ANY
291 # permit rt:101:101
292 # permit rt:201:201
293 # Expanded extended community list test1: match: ALL
294 # deny 101:102
295
296
297 - name: Override the entire list of BGP extended community
298 dellemc.enterprise_sonic.sonic_bgp_ext_communities:
299 config:
300 - name: test3
301 type: expanded
302 permit: true
303 match: all
304 members:
305 regex:
306 - 301:302
307 state: overridden
308
309 # After state:
310 # ------------
311 #
312 # show bgp ext-community-list
313 # Expanded extended community list test3: match: ALL
314 # permit 301:302
315 #
316 """
317
318 RETURN = """
319 before:
320 description: The configuration prior to the module invocation.
321 returned: always
322 type: list
323 sample: >
324 The configuration returned will always be in the same format
325 as the parameters above.
326 after:
327 description: The resulting configuration module invocation.
328 returned: when changed
329 type: list
330 sample: >
331 The configuration returned will always be in the same format
332 as the parameters above.
333 commands:
334 description: The set of commands pushed to the remote device.
335 returned: always
336 type: list
337 sample: ['command 1', 'command 2', 'command 3']
338 """
339
340
341 from ansible.module_utils.basic import AnsibleModule
342 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.bgp_ext_communities.bgp_ext_communities import (
343 Bgp_ext_communitiesArgs,
344 )
345 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.bgp_ext_communities.bgp_ext_communities import Bgp_ext_communities
346
347
348 def main():
349 """
350 Main entry point for module execution
351
352 :returns: the result form module invocation
353 """
354 module = AnsibleModule(argument_spec=Bgp_ext_communitiesArgs.argument_spec,
355 supports_check_mode=True)
356
357 result = Bgp_ext_communities(module).execute_module()
358 module.exit_json(**result)
359
360
361 if __name__ == '__main__':
362 main()