Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_lst.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_lst
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_lst
17 version_added: 3.1.0
18 notes:
19 - Tested against Enterprise SONiC Distribution by Dell Technologies.
20 - Supports C(check_mode).
21 short_description: Manage link state tracking (LST) configuration on SONiC
22 description:
23 - This module provides configuration management of LST for devices running SONiC
24 author: S. Talabi (@stalabi1)
25 options:
26 config:
27 description:
28 - LST configuration
29 type: dict
30 suboptions:
31 lst_groups:
32 description:
33 - LST groups configuration
34 type: list
35 elements: dict
36 suboptions:
37 name:
38 description:
39 - Name of LST group
40 type: str
41 required: true
42 all_evpn_es_downstream:
43 description:
44 - Indicates that the LST group tracks all EVPN ethernet segments as downstream interfaces
45 type: bool
46 all_mclags_downstream:
47 description:
48 - Indicates that the LST group tracks all MCLAGs as downstream interfaces
49 type: bool
50 group_description:
51 description:
52 - Description of LST group
53 type: str
54 group_type:
55 description:
56 - LST group type
57 type: str
58 choices: ['l3']
59 threshold_down:
60 description:
61 - Downstream ports will shut down if the threshold falls below this value
62 - Range 0-100
63 type: int
64 threshold_type:
65 description:
66 - Type of threshold calculation scheme to use
67 type: str
68 choices: ['percentage']
69 threshold_up:
70 description:
71 - Downstream ports will go online if the threshold is greater than or equal to this value
72 - Range 0-100
73 type: int
74 timeout:
75 description:
76 - Time in seconds to wait to bring up the downstream ports after the first upstream port is online
77 - Range 1-1800
78 type: int
79 interfaces:
80 description:
81 - LST configuration for interfaces
82 type: list
83 elements: dict
84 suboptions:
85 name:
86 description:
87 - Name of interface
88 type: str
89 required: true
90 downstream_group:
91 description:
92 - LST group name used to track the interface as downstream
93 type: str
94 upstream_groups:
95 description:
96 - Upstream groups configuration
97 type: list
98 elements: dict
99 suboptions:
100 group_name:
101 description:
102 - LST group name used to track the interface as upstream
103 type: str
104 required: true
105 state:
106 description:
107 - The state of the configuration after module completion
108 type: str
109 choices: ['merged', 'deleted', 'replaced', 'overridden']
110 default: merged
111 """
112
113 EXAMPLES = """
114 # Using "merged" state
115 #
116 # Before state:
117 # -------------
118 #
119 # sonic# show running-configuration link state tracking
120 # (No link state tracking configuration present)
121 # sonic# show running-configuration interface Ethernet 20
122 # !
123 # interface Ethernet20
124 # (No link state tracking configuration present for interface Ethernet20)
125 # sonic# show running-configuration interface Ethernet 24
126 # !
127 # interface Ethernet24
128 # (No link state tracking configuration present for interface Ethernet24)
129
130 - name: Merge LST configuration
131 dellemc.enterprise_sonic.sonic_lst:
132 config:
133 lst_groups:
134 - name: lst
135 all_evpn_es_downstream: true
136 group_description: abc
137 group_type: l3
138 threshold_down: 20
139 threshold_type: percentage
140 threshold_up: 40
141 timeout: 120
142 interfaces:
143 - name: Ethernet20
144 downstream_group: lst
145 - name: Ethernet24
146 upstream_groups:
147 - group_name: lst
148 state: merged
149
150 # After state:
151 # ------------
152 #
153 # sonic# show running-configuration link state tracking
154 # !
155 # link state track lst
156 # timeout 120
157 # description abc
158 # downstream all-evpn-es
159 # threshold type percentage up 40 down 20
160 # sonic# show running-configuration interface Ethernet 20
161 # !
162 # interface Ethernet20
163 # link state track lst downstream
164 # sonic# show running-configuration interface Ethernet 24
165 # !
166 # interface Ethernet24
167 # link state track lst upstream
168
169
170 # Using "replaced" state
171 #
172 # Before state:
173 # -------------
174 #
175 # sonic# show running-configuration link state tracking
176 # !
177 # link state track lst
178 # timeout 120
179 # description abc
180 # downstream all-evpn-es
181 # threshold type percentage up 40 down 20
182 # sonic# show running-configuration interface Ethernet 20
183 # !
184 # interface Ethernet20
185 # link state track lst downstream
186 # sonic# show running-configuration interface Ethernet 24
187 # !
188 # interface Ethernet24
189 # link state track lst upstream
190
191 - name: Replace LST configuration
192 dellemc.enterprise_sonic.sonic_lst:
193 config:
194 lst_groups:
195 - name: lst
196 all_mclags_downstream: true
197 timeout: 75
198 interfaces:
199 - name: Ethernet20
200 upstream_groups:
201 - group_name: lst
202 - name: Ethernet24
203 downstream_group: lst
204 state: replaced
205
206 # After state:
207 # ------------
208 #
209 # sonic# show running-configuration link state tracking
210 # !
211 # link state track lst
212 # timeout 75
213 # downstream all-mclag
214 # sonic# show running-configuration interface Ethernet 20
215 # !
216 # interface Ethernet20
217 # link state track lst upstream
218 # sonic# show running-configuration interface Ethernet 24
219 # !
220 # interface Ethernet24
221 # link state track lst downstream
222
223
224 # Using "overridden" state
225 #
226 # Before state:
227 # -------------
228 #
229 # sonic# show running-configuration link state tracking
230 # !
231 # link state track lst
232 # timeout 75
233 # downstream all-mclag
234 # sonic# show running-configuration interface Ethernet 20
235 # !
236 # interface Ethernet20
237 # link state track lst upstream
238 # sonic# show running-configuration interface Ethernet 24
239 # !
240 # interface Ethernet24
241 # link state track lst downstream
242
243 - name: Override LST configuration
244 dellemc.enterprise_sonic.sonic_lst:
245 config:
246 lst_groups:
247 - name: lst2
248 all_evpn_es_downstream: true
249 group_description: xyz
250 group_type: l3
251 threshold_down: 30
252 threshold_type: percentage
253 threshold_up: 50
254 timeout: 130
255 interfaces:
256 - name: Ethernet20
257 downstream_group: lst2
258 state: overridden
259
260 # After state:
261 # ------------
262 #
263 # sonic# show running-configuration link state tracking
264 # !
265 # link state track lst2
266 # timeout 130
267 # description xyz
268 # downstream all-evpn-es
269 # threshold type percentage up 50 down 30
270 # sonic# show running-configuration interface Ethernet 20
271 # !
272 # interface Ethernet20
273 # link state track lst2 downstream
274 # sonic# show running-configuration interface Ethernet 24
275 # !
276 # interface Ethernet24
277 # (No link state configuration present for interface Ethernet24)
278
279
280 # Using "deleted" state
281 #
282 # Before state:
283 # -------------
284 #
285 # sonic# show running-configuration link state tracking
286 # !
287 # link state track lst2
288 # timeout 130
289 # description xyz
290 # downstream all-evpn-es
291 # threshold type percentage up 50 down 30
292 # sonic# show running-configuration interface Ethernet 20
293 # !
294 # interface Ethernet20
295 # link state track lst2 downstream
296 # sonic# show running-configuration interface Ethernet 24
297 # !
298 # interface Ethernet24
299 # link state track lst2 upstream
300
301 - name: Delete LST configuration
302 dellemc.enterprise_sonic.sonic_lst:
303 config:
304 lst_groups:
305 - name: lst2
306 all_evpn_es_downstream: true
307 group_description: xyz
308 threshold_down: 30
309 threshold_type: percentage
310 threshold_up: 50
311 timeout: 130
312 interfaces:
313 - name: Ethernet20
314 downstream_group: lst2
315 - name: Ethernet24
316 upstream_groups:
317 - group_name: lst2
318 state: deleted
319
320 # After state:
321 # ------------
322 #
323 # sonic# show running-configuration link state tracking
324 # !
325 # link state track lst2
326 # sonic# show running-configuration interface Ethernet 20
327 # !
328 # interface Ethernet20
329 # (No link state configuration present for interface Ethernet20)
330 # sonic# show running-configuration interface Ethernet 24
331 # !
332 # interface Ethernet24
333 # (No link state configuration present for interface Ethernet24)
334
335
336 # Using "deleted" state
337 #
338 # Before state:
339 # -------------
340 #
341 # sonic# show running-configuration link state tracking
342 # !
343 # link state track lst
344 # timeout 120
345 # description abc
346 # downstream all-evpn-es
347 # threshold type percentage up 40 down 20
348 # sonic# show running-configuration interface Ethernet 20
349 # !
350 # interface Ethernet20
351 # link state track lst downstream
352 # sonic# show running-configuration interface Ethernet 24
353 # !
354 # interface Ethernet24
355 # link state track lst upstream
356
357 - name: Delete LST configuration
358 dellemc.enterprise_sonic.sonic_lst:
359 config: {}
360 state: deleted
361
362 # After state:
363 # ------------
364 #
365 # sonic# show running-configuration link state tracking
366 # (No link state tracking configuration present)
367 # sonic# show running-configuration interface Ethernet 20
368 # !
369 # interface Ethernet20
370 # (No link state tracking configuration present for interface Ethernet20)
371 # sonic# show running-configuration interface Ethernet 24
372 # !
373 # interface Ethernet24
374 # (No link state tracking configuration present for interface Ethernet24)
375 """
376
377 RETURN = """
378 before:
379 description: The configuration prior to the module invocation.
380 returned: always
381 type: dict
382 sample: >
383 The configuration returned will always be in the same format
384 as the parameters above.
385 after:
386 description: The resulting configuration from module invocation.
387 returned: when changed
388 type: dict
389 sample: >
390 The configuration returned will always be in the same format
391 as the parameters above.
392 after_generated:
393 description: The generated configuration from module invocation.
394 returned: when C(check_mode)
395 type: dict
396 sample: >
397 The configuration returned will always be in the same format
398 as the parameters above.
399 commands:
400 description: The set of commands pushed to the remote device.
401 returned: always
402 type: list
403 sample: ['command 1', 'command 2', 'command 3']
404 """
405
406
407 from ansible.module_utils.basic import AnsibleModule
408 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.lst.lst import LstArgs
409 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.lst.lst import Lst
410
411
412 def main():
413 """
414 Main entry point for module execution
415
416 :returns: the result form module invocation
417 """
418 module = AnsibleModule(argument_spec=LstArgs.argument_spec,
419 supports_check_mode=True)
420
421 result = Lst(module).execute_module()
422 module.exit_json(**result)
423
424
425 if __name__ == '__main__':
426 main()