Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_prefix_lists.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_prefix_lists
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_prefix_lists
17 version_added: "2.0.0"
18 author: Kerry Meyer (@kerry-meyer)
19 notes:
20 - Supports C(check_mode).
21 - Supports D(diff_mode).
22 short_description: prefix list configuration handling for SONiC
23 description:
24 - This module provides configuration management for prefix list parameters on devices running SONiC.
25 options:
26 config:
27 description:
28 - Specifies a list of prefix set configuration dictionaries
29 type: list
30 elements: dict
31 suboptions:
32 name:
33 description:
34 - Name of a prefix set (a list of prefix entries)
35 type: str
36 required: true
37 afi:
38 description:
39 - Specifies the Address Family for addresses in the prefix list entries
40 type: str
41 choices: ["ipv4", "ipv6"]
42 default: "ipv4"
43 prefixes:
44 description:
45 - A list of prefix entries
46 type: list
47 elements: dict
48 suboptions:
49 sequence:
50 description:
51 - Precedence for this prefix entry (unique within the prefix list)
52 type: int
53 required: true
54 action:
55 description:
56 - Action to be taken for addresses matching this prefix entry
57 type: str
58 required: true
59 choices: ["permit", "deny"]
60 prefix:
61 description:
62 - IPv4 or IPv6 prefix in A.B.C.D/LEN or A:B::C:D/LEN format
63 type: str
64 required: true
65 ge:
66 description: Minimum prefix length to be matched
67 type: int
68 le:
69 description: Maximum prefix length to be matched
70 type: int
71 state:
72 description:
73 - Specifies the type of configuration update to be performed on the device.
74 - For "merged", merge specified attributes with existing configured attributes.
75 - For "deleted", delete the specified attributes from existing configuration.
76 - For "replaced", replace the specified existing configuration with the provided configuration.
77 - For "overridden", override the existing configuration with the provided configuration.
78 type: str
79 choices:
80 - merged
81 - deleted
82 - replaced
83 - overridden
84 default: merged
85 """
86
87 EXAMPLES = """
88 # Using "merged" state to create initial configuration
89 #
90 # Before state:
91 # -------------
92 #
93 # sonic# show running-configuration ip prefix-list
94 # sonic#
95 # (No configuration present)
96 #
97 # -------------
98 #
99 - name: Merge initial prefix-list configuration
100 dellemc.enterprise_sonic.sonic_prefix_lists:
101 config:
102 - name: pfx1
103 afi: "ipv4"
104 prefixes:
105 - sequence: 10
106 prefix: "1.2.3.4/24"
107 action: "permit"
108 ge: 26
109 le: 30
110 state: merged
111
112 # After state:
113 # ------------
114 #
115 # sonic# show running-configuration ip prefix-list
116 # !
117 # ip prefix-list pfx1 seq 10 permit 1.2.3.4/24 ge 26 le 30
118 # ------------
119 #
120 # ***************************************************************
121 # Using "merged" state to update and add configuration
122 #
123 # Before state:
124 # ------------
125 #
126 # sonic# show running-configuration ip prefix-list
127 # !
128 # ip prefix-list pfx1 seq 10 permit 1.2.3.4/24 ge 26 le 30
129 #
130 # sonic# show running-configuration ipv6 prefix-list
131 # sonic#
132 # (no IPv6 prefix-list configuration present)
133 #
134 # ------------
135 #
136 - name: Merge additional prefix-list configuration
137 dellemc.enterprise_sonic.sonic_prefix_lists:
138 config:
139 - name: pfx1
140 afi: "ipv4"
141 prefixes:
142 - sequence: 20
143 action: "deny"
144 prefix: "1.2.3.12/26"
145 - sequence: 30
146 action: "permit"
147 prefix: "7.8.9.0/24"
148 - name: pfx6
149 afi: "ipv6"
150 prefixes:
151 - sequence: 25
152 action: "permit"
153 prefix: "40::300/124"
154 state: merged
155
156 # After state:
157 # ------------
158 #
159 # sonic# show running-configuration ip prefix-list
160 # !
161 # ip prefix-list pfx1 seq 10 permit 1.2.3.4/24 ge 26 le 30
162 # ip prefix-list pfx1 seq 20 deny 1.2.3.12/26
163 # ip prefix-list pfx1 seq 30 permit 7.8.9.0/24
164 #
165 # sonic# show running-configuration ipv6 prefix-list
166 # !
167 # ipv6 prefix-list pfx6 seq 25 permit 40::300/124
168 #
169 # ***************************************************************
170 # Using "deleted" state to remove configuration
171 #
172 # Before state:
173 # ------------
174 #
175 # sonic# show running-configuration ip prefix-list
176 # !
177 # ip prefix-list pfx1 seq 10 permit 1.2.3.4/24 ge 26 le 30
178 # ip prefix-list pfx1 seq 20 deny 1.2.3.12/26
179 # ip prefix-list pfx1 seq 30 permit 7.8.9.0/24
180 #
181 # sonic# show running-configuration ipv6 prefix-list
182 # !
183 # ipv6 prefix-list pfx6 seq 25 permit 40::300/124
184 #
185 # ------------
186 #
187 - name: Delete selected prefix-list configuration
188 dellemc.enterprise_sonic.sonic_prefix_lists:
189 config:
190 - name: pfx1
191 afi: "ipv4"
192 prefixes:
193 - sequence: 10
194 prefix: "1.2.3.4/24"
195 action: "permit"
196 ge: 26
197 le: 30
198 - sequence: 20
199 action: "deny"
200 prefix: "1.2.3.12/26"
201 - name: pfx6
202 afi: "ipv6"
203 prefixes:
204 - sequence: 25
205 action: "permit"
206 prefix: "40::300/124"
207 state: deleted
208
209 # After state:
210 # ------------
211 #
212 # sonic# show running-configuration ip prefix-list
213 # !
214 # ip prefix-list pfx1 seq 30 permit 7.8.9.0/24
215 #
216 # sonic# show running-configuration ipv6 prefix-list
217 # sonic#
218 # (no IPv6 prefix-list configuration present)
219 #
220 # ***************************************************************
221 # Using "overriden" state to override configuration
222 #
223 # Before state:
224 # ------------
225 #
226 # sonic# show running-configuration ip prefix-list
227 # !
228 # ip prefix-list pfx1 seq 10 permit 1.2.3.4/24 ge 26 le 30
229 # ip prefix-list pfx3 seq 20 deny 1.2.3.12/26
230 # ip prefix-list pfx4 seq 30 permit 7.8.9.0/24
231 #
232 # sonic# show running-configuration ipv6 prefix-list
233 # !
234 # ipv6 prefix-list pfx6 seq 25 permit 40::300/124
235 #
236 # ------------
237 #
238 - name: Override prefix-list configuration
239 dellemc.enterprise_sonic.sonic_prefix_lists:
240 config:
241 - name: pfx2
242 afi: "ipv4"
243 prefixes:
244 - sequence: 10
245 prefix: "10.20.30.128/24"
246 action: "deny"
247 ge: 25
248 le: 30
249 state: overridden
250
251 # After state:
252 # ------------
253 #
254 # sonic# show running-configuration ip prefix-list
255 # !
256 # ip prefix-list pfx2 seq 10 deny 10.20.30.128/24 ge 25 le 30
257 #
258 # sonic# show running-configuration ipv6 prefix-list
259 # sonic#
260 # (no IPv6 prefix-list configuration present)
261 #
262 # ***************************************************************
263 # Using "replaced" state to replace configuration
264 #
265 # Before state:
266 # ------------
267 #
268 # sonic# show running-configuration ip prefix-list
269 # !
270 # ip prefix-list pfx2 seq 10 deny 10.20.30.128/24 ge 25 le 30
271 #
272 # sonic# show running-configuration ipv6 prefix-list
273 # sonic#
274 # (no IPv6 prefix-list configuration present)
275 #
276 # ------------
277 #
278 - name: Replace prefix-list configuration
279 dellemc.enterprise_sonic.sonic_prefix_lists:
280 config:
281 - name: pfx2
282 afi: "ipv4"
283 prefixes:
284 - sequence: 10
285 prefix: "10.20.30.128/24"
286 action: "permit"
287 ge: 25
288 le: 30
289 - name: pfx3
290 afi: "ipv6"
291 prefixes:
292 - sequence: 20
293 action: "deny"
294 prefix: "60::70/124"
295 state: replaced
296
297 # After state:
298 # ------------
299 #
300 # sonic# show running-configuration ip prefix-list
301 # !
302 # ip prefix-list pfx2 seq 10 permit 10.20.30.128/24 ge 25 le 30
303 #
304 # sonic# show running-configuration ipv6 prefix-list
305 # sonic#
306 # !
307 # ipv6 prefix-list pfx3 seq 20 deny 60::70/124
308 #
309 """
310
311 RETURN = """
312 before:
313 description: The configuration prior to the module invocation.
314 returned: always
315 type: list
316 sample: >
317 The configuration returned will always be in the same format
318 as the parameters above.
319 after:
320 description: The resulting configuration module invocation.
321 returned: when changed
322 type: list
323 sample: >
324 The configuration returned will always be in the same format
325 as the parameters above.
326 after_generated:
327 description: The generated configuration module invocation.
328 returned: when C(check_mode)
329 type: list
330 sample: >
331 The configuration returned will always be in the same format
332 as the parameters above.
333 diff:
334 description: The difference between 'before' and 'after' (or 'after_generated').
335 returned: when D(diff_mode)
336 type: list
337 sample: >
338 The difference shows several lines of context around the lines that differ.
339 commands:
340 description: The set of commands pushed to the remote device.
341 returned: always
342 type: list
343 sample: ['command 1', 'command 2', 'command 3']
344 """
345
346
347 from ansible.module_utils.basic import AnsibleModule
348 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.prefix_lists.prefix_lists import Prefix_listsArgs
349 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.prefix_lists.prefix_lists import Prefix_lists
350
351
352 def main():
353 """
354 Main entry point for module execution
355
356 :returns: the result form module invocation
357 """
358 module = AnsibleModule(argument_spec=Prefix_listsArgs.argument_spec,
359 supports_check_mode=True)
360
361 result = Prefix_lists(module).execute_module()
362 module.exit_json(**result)
363
364
365 if __name__ == '__main__':
366 main()