Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_bgp_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_communities
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14
15 DOCUMENTATION = """
16 ---
17 module: sonic_bgp_communities
18 version_added: 1.0.0
19 notes:
20 - Tested against Enterprise SONiC Distribution by Dell Technologies.
21 - Supports C(check_mode).
22 short_description: Manage BGP community and its parameters
23 description:
24 - This module provides configuration management of BGP bgp_communities for device
25 running Enterprise SONiC Distribution by Dell Technologies.
26 author: Kumaraguru Narayanan (@nkumaraguru)
27 options:
28 config:
29 description: A list of 'bgp_communities' configurations.
30 type: list
31 elements: dict
32 suboptions:
33 name:
34 required: True
35 type: str
36 description:
37 - Name of the BGP community-list.
38 type:
39 type: str
40 description:
41 - Whether it is a standard or expanded community-list entry.
42 - If unspecified, operational default value is C(standard).
43 required: False
44 choices:
45 - standard
46 - expanded
47 permit:
48 required: False
49 type: bool
50 description:
51 - Permits or denies this community.
52 - If unspecified, operational default value is C(False).
53 local_as:
54 required: False
55 type: bool
56 description:
57 - Do not send outside local AS (well-known community); applicable for standard BGP community type.
58 no_advertise:
59 required: False
60 type: bool
61 description:
62 - Do not advertise to any peer (well-known community); applicable for standard BGP community type.
63 no_export:
64 required: False
65 type: bool
66 description:
67 - Do not export to next AS (well-known community); applicable for standard BGP community type.
68 no_peer:
69 required: False
70 type: bool
71 description:
72 - Do not export to next AS (well-known community); applicable for standard BGP community type.
73 members:
74 required: False
75 type: dict
76 suboptions:
77 aann:
78 required: False
79 type: list
80 elements: str
81 version_added: 3.0.0
82 description:
83 - Community number aa:nn format 0..65535:0..65535; applicable for standard BGP community type.
84 regex:
85 type: list
86 elements: str
87 required: False
88 description:
89 - Members of this BGP community list. Regular expression string can be given here. Applicable for expanded BGP community type.
90 description:
91 - Members of this BGP community list.
92 match:
93 required: False
94 type: str
95 description:
96 - Matches any/all of the members.
97 - If unspecified, operational default value is C(ANY).
98 choices:
99 - ALL
100 - ANY
101 state:
102 description:
103 - The state of the configuration after module completion.
104 type: str
105 choices:
106 - merged
107 - deleted
108 - replaced
109 - overridden
110 default: merged
111 """
112
113 EXAMPLES = """
114 # Using "deleted" state
115
116 # Before state:
117 # -------------
118 #
119 # show bgp community-list
120 # Standard community list test: match: ANY
121 # permit local-as
122 # permit no-peer
123 # Expanded community list test1: match: ANY
124 # deny 101
125 # deny 302
126
127 - name: Delete a BGP community-list member
128 dellemc.enterprise_sonic.sonic_bgp_communities:
129 config:
130 - name: test1
131 type: expanded
132 permit: false
133 members:
134 regex:
135 - 302
136 state: deleted
137
138 # After state:
139 # ------------
140 #
141 # show bgp community-list
142 # Standard community list test: match: ANY
143 # permit local-as
144 # permit no-peer
145 # Expanded community list test1: match: ANY
146 # deny 101
147
148
149 # Using "deleted" state
150
151 # Before state:
152 # -------------
153 #
154 # show bgp community-list
155 # Standard community list test: match: ANY
156 # permit local-as
157 # permit no-peer
158 # Expanded community list test1: match: ANY
159 # deny 101
160 # deny 302
161
162 - name: Delete a single BGP community-list
163 dellemc.enterprise_sonic.sonic_bgp_communities:
164 config:
165 - name: test
166 type: standard
167 state: deleted
168
169 # After state:
170 # ------------
171 #
172 # show bgp community-list
173 # Expanded community list test1: match: ANY
174 # deny 101
175 # deny 302
176
177
178 # Using "deleted" state
179
180 # Before state:
181 # -------------
182 #
183 # show bgp community-list
184 # Standard community list test: match: ANY
185 # permit local-as
186 # permit no-peer
187 # Expanded community list test1: match: ANY
188 # deny 101
189 # deny 302
190
191 - name: Delete All BGP community-lists
192 dellemc.enterprise_sonic.sonic_bgp_communities:
193 config:
194 state: deleted
195
196 # After state:
197 # ------------
198 #
199 # show bgp community-list
200 #
201
202
203 # Using "deleted" state
204
205 # Before state:
206 # -------------
207 #
208 # show bgp community-list
209 # Standard community list test: match: ANY
210 # permit local-as
211 # permit no-peer
212 # Expanded community list test1: match: ANY
213 # deny 101
214 # deny 302
215
216 - name: Delete all members in a single BGP community-list
217 dellemc.enterprise_sonic.sonic_bgp_communities:
218 config:
219 - name: test1
220 type: expanded
221 members:
222 regex:
223 state: deleted
224
225 # After state:
226 # ------------
227 #
228 # show bgp community-list
229 # Standard community list test: match: ANY
230 # permit local-as
231 # permit no-peer
232
233
234 # Using "merged" state
235
236 # Before state:
237 # -------------
238 #
239 # show bgp community-list
240 # Expanded community list test1: match: ANY
241 # permit 101
242 # permit 302
243
244 - name: Add new BGP community-lists
245 dellemc.enterprise_sonic.sonic_bgp_communities:
246 config:
247 - name: test2
248 type: expanded
249 permit: true
250 members:
251 regex:
252 - 909
253 - name: test3
254 type: standard
255 permit: true
256 no_peer: true
257 members:
258 aann:
259 - 1000:10
260 state: merged
261
262 # After state:
263 # ------------
264 #
265 # show bgp community-list
266 # Expanded community list test1: match: ANY
267 # permit 101
268 # permit 302
269 # Expanded community list test2: match: ANY
270 # permit 909
271 # Standard community list test3: match: ANY
272 # permit 1000:10
273 # permit no-peer
274
275
276 # Using "replaced" state
277
278 # Before state:
279 # -------------
280 #
281 # show bgp community-list
282 # Standard community list test: match: ANY
283 # permit local-as
284 # permit no-peer
285 # Expanded community list test1: match: ANY
286 # deny 101
287 # deny 302
288
289 - name: Replacing a single BGP community-list
290 dellemc.enterprise_sonic.sonic_bgp_communities:
291 config:
292 - name: test
293 type: expanded
294 members:
295 regex:
296 - 301
297 - name: test2
298 type: standard
299 members:
300 aann:
301 - 1000:10
302 - 2000:20
303 - name: test3
304 type: standard
305 no_advertise: true
306 no_peer: true
307 permit: false
308 match: ALL
309 state: replaced
310
311 # After state:
312 # ------------
313 #
314 # show bgp community-list
315 # Expanded community list test: match: ANY
316 # deny 301
317 # Expanded community list test1: match: ANY
318 # deny 101
319 # deny 302
320 # Standard community list test2: match: ANY
321 # deny 1000:10
322 # deny 2000:10
323 # Standard community list test3: match: ALL
324 # deny no-advertise
325 # deny no-peer
326
327
328 # Using "overridden" state
329
330 # Before state:
331 # -------------
332 #
333 # show bgp community-list
334 # Standard community list test: match: ANY
335 # permit local-as
336 # permit no-peer
337 # Expanded community list test1: match: ANY
338 # deny 101
339 # deny 302
340
341 - name: Override entire BGP community-lists
342 dellemc.enterprise_sonic.sonic_bgp_communities:
343 config:
344 - name: test3
345 type: expanded
346 members:
347 regex:
348 - 301
349 state: overridden
350
351 # After state:
352 # ------------
353 #
354 # show bgp community-list
355 # Expanded community list test3: match: ANY
356 # deny 301
357 #
358 """
359
360 RETURN = """
361 before:
362 description: The configuration prior to the module invocation.
363 returned: always
364 type: list
365 sample: >
366 The configuration that is returned is always in the same format
367 as the parameters above.
368 after:
369 description: The resulting configuration module invocation.
370 returned: when changed
371 type: list
372 sample: >
373 The configuration that is returned is always in the same format
374 as the parameters above.
375 commands:
376 description: The set of commands that are pushed to the remote device.
377 returned: always
378 type: list
379 sample: ['command 1', 'command 2', 'command 3']
380 """
381
382
383 from ansible.module_utils.basic import AnsibleModule
384 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.bgp_communities.bgp_communities import Bgp_communitiesArgs
385 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.bgp_communities.bgp_communities import Bgp_communities
386
387
388 def main():
389 """
390 Main entry point for module execution
391
392 :returns: the result form module invocation
393 """
394 module = AnsibleModule(argument_spec=Bgp_communitiesArgs.argument_spec,
395 supports_check_mode=True)
396
397 result = Bgp_communities(module).execute_module()
398 module.exit_json(**result)
399
400
401 if __name__ == '__main__':
402 main()