Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_system.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_system
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14 DOCUMENTATION = """
15 ---
16 module: sonic_system
17 version_added: 1.0.0
18 notes:
19 - Tested against Enterprise SONiC Distribution by Dell Technologies.
20 - Supports C(check_mode).
21 author: Abirami N (@abirami-n)
22 short_description: Configure system parameters
23 description:
24 - This module is used for configuration management of global system parameters on devices running Enterprise SONiC.
25 options:
26 config:
27 description:
28 - Specifies the system related configurations
29 type: dict
30 suboptions:
31 hostname:
32 description:
33 - Specifies the hostname of the SONiC device
34 type: str
35 interface_naming:
36 description:
37 - Specifies the type of interface-naming in device
38 type: str
39 choices:
40 - standard
41 - standard_extended
42 - native
43 anycast_address:
44 description:
45 - Specifies different types of anycast address that can be configured on the device
46 type: dict
47 suboptions:
48 ipv4:
49 description:
50 - Enable or disable ipv4 anycast-address
51 type: bool
52 ipv6:
53 description:
54 - Enable or disable ipv6 anycast-address
55 type: bool
56 mac_address:
57 description:
58 - Specifies the mac anycast-address
59 type: str
60 auto_breakout:
61 description:
62 - Specifies auto-breakout status in the device
63 version_added: 2.5.0
64 type: str
65 choices:
66 - ENABLE
67 - DISABLE
68 load_share_hash_algo:
69 description:
70 - Specifies different types of ECMP Load share hash algorithm
71 version_added: 2.5.0
72 type: str
73 choices:
74 - CRC
75 - XOR
76 - CRC_32LO
77 - CRC_32HI
78 - CRC_CCITT
79 - CRC_XOR
80 - JENKINS_HASH_LO
81 - JENKINS_HASH_HI
82 audit_rules:
83 description:
84 - Specifies audit rule profile type.
85 - Can be used on SONiC release versions 4.4.0 and above.
86 version_added: 2.5.0
87 type: str
88 choices:
89 - BASIC
90 - DETAIL
91 - CUSTOM
92 - NONE
93 switching_mode:
94 description:
95 - Specifies switching mode in the device.
96 - Operational default value is STORE_AND_FORWARD.
97 version_added: 3.1.0
98 type: str
99 choices:
100 - CUT_THROUGH
101 - STORE_AND_FORWARD
102 adjust_txrx_clock_freq:
103 description:
104 - Adjust TX/RX clock frequency to platform specific value.
105 - Operational default value is C(false).
106 version_added: 3.1.0
107 type: bool
108 concurrent_session_limit:
109 version_added: 3.1.0
110 description:
111 - Specifies limit on number of concurrent sessions
112 - Range 1-12
113 type: int
114 password_complexity:
115 description:
116 - The set of login password attribute configurations
117 type: dict
118 suboptions:
119 min_length:
120 description:
121 - Minimum number of required alphanumeric characters
122 - The range is from 6 to 32
123 - Default is 8
124 type: int
125 min_upper_case:
126 description:
127 - Minimum number of uppercase characters required
128 - The range is from 0 to 31
129 type: int
130 min_lower_case:
131 description:
132 - Minimum number of lowercase characters required
133 - The range is from 0 to 31
134 type: int
135 min_numerals:
136 description:
137 - Minimum number of numeric characters required
138 - The range is from 0 to 31
139 type: int
140 min_spl_char:
141 description:
142 - Minimum number of special characters required
143 - The range is from 0 to 31
144 type: int
145 login_exec_timeout:
146 description:
147 - CLI session timeout value.
148 - The range is from 0 to 3600
149 - Default is 600
150 version_added: 4.0.0
151 type: int
152 banner:
153 description:
154 - The set of banner attribute configurations
155 version_added: 4.0.0
156 type: dict
157 suboptions:
158 login:
159 description:
160 - Banner message to display before login.
161 - Format is 'c\\r\\n{banner text}\\r\\nc', where 'c' is a delimiting character
162 type: str
163 motd:
164 description:
165 - Banner message to display after login.
166 - Format is 'c\\r\\n{banner text}\\r\\nc', where 'c' is a delimiting character
167 type: str
168 login_banner_disable:
169 description:
170 - Disable login banner.
171 type: bool
172 motd_banner_disable:
173 description:
174 - Disable motd banner.
175 type: bool
176 state:
177 description:
178 - Specifies the operation to be performed on the system parameters configured on the device.
179 - In case of merged, the input configuration will be merged with the existing system configuration on the device.
180 - In case of deleted the existing system configuration will be removed from the device.
181 default: merged
182 choices: ['merged', 'replaced', 'overridden', 'deleted']
183 type: str
184 """
185
186 EXAMPLES = """
187 # Using "deleted" state
188 #
189 # Before state:
190 # -------------
191 # !
192 # SONIC(config)#do show running-configuration
193 # !
194 # banner login @
195 # banner - Welcome to DELL SONiC
196 # @
197 # banner motd @
198 # banner - Enjoy the DELL OS
199 # @
200 # banner motd disable
201 # ip anycast-mac-address aa:bb:cc:dd:ee:ff
202 # ip anycast-address enable
203 # ipv6 anycast-address enable
204 # interface-naming standard
205 # ip load-share hash algorithm JENKINS_HASH_HI
206 # login concurrent-session limit 4
207 # system adjust-txrx-clock-freq
208 # login password-attribute character-restriction lower 2
209
210 - name: Delete System configuration
211 dellemc.enterprise_sonic.sonic_system:
212 config:
213 hostname: SONIC
214 interface_naming: standard
215 anycast_address:
216 ipv6: true
217 load_share_hash_algo: JENKINS_HASH_HI
218 concurrent_session_limit: 4
219 adjust_txrx_clock_freq: true
220 password_complexity:
221 min_lower_case: 2
222 banner:
223 login: "@\r\nbanner_login_message\r\n@"
224 motd: "@\r\nbanner_motd_message\r\n@"
225 state: deleted
226
227 # After state:
228 # ------------
229 # !
230 # sonic(config)#do show running-configuration
231 # !
232 # ip anycast-mac-address aa:bb:cc:dd:ee:ff
233 # ip anycast-address enable
234
235
236 # Using "deleted" state
237 #
238 # Before state:
239 # -------------
240 # !
241 # SONIC(config)#do show running-configuration
242 # !
243 # ip anycast-mac-address aa:bb:cc:dd:ee:ff
244 # ip anycast-address enable
245 # ipv6 anycast-address enable
246 # interface-naming standard
247 # ip load-share hash algorithm JENKINS_HASH_HI
248 # login concurrent-session limit 4
249
250 - name: Delete all system related configs in device configuration
251 dellemc.enterprise_sonic.sonic_system:
252 config:
253 state: deleted
254
255 # After state:
256 # ------------
257 # !
258 # sonic(config)#do show running-configuration
259 # !
260
261
262 # Using "merged" state
263 #
264 # Before state:
265 # -------------
266 # !
267 # sonic(config)#do show running-configuration
268 # !
269
270 - name: Merge provided configuration with device configuration
271 dellemc.enterprise_sonic.sonic_system:
272 config:
273 hostname: SONIC
274 interface_naming: standard
275 anycast_address:
276 ipv6: true
277 ipv4: true
278 mac_address: aa:bb:cc:dd:ee:ff
279 load_share_hash_algo: JENKINS_HASH_HI
280 concurrent_session_limit: 4
281 adjust_txrx_clock_freq: true
282 password_complexity:
283 min_upper_case: 2
284 min_spl_char: 2
285 banner:
286 login_banner_disable: true
287 motd: "@\r\nmotd_banner_message\r\n@"
288 state: merged
289
290 # After state:
291 # ------------
292 # !
293 # SONIC(config)#do show running-configuration
294 # !
295 # banner motd @
296 # motd_banner_message
297 # @
298 # banner login disable
299 # hostname SONIC
300 # ip anycast-mac-address aa:bb:cc:dd:ee:ff
301 # ip anycast-address enable
302 # ipv6 anycast-address enable
303 # interface-naming standard
304 # ip load-share hash algorithm JENKINS_HASH_HI
305 # login concurrent-session limit 4
306 # system adjust-txrx-clock-freq
307 # login password-attribute character-restriction upper 2
308 # login password-attribute character-restriction special-char 2
309
310 # Using "replaced" state
311 #
312 # Before state:
313 # -------------
314 # !
315 # sonic(config)#do show running-configuration
316 # !
317 # banner login @
318 # banner_login_message
319 # @
320 # banner motd @
321 # @
322 # banner_motd_message
323 # banner motd disable
324 # ip anycast-mac-address aa:bb:cc:dd:ee:ff
325 # ip anycast-address enable
326 # ipv6 anycast-address enable
327 # interface-naming standard
328 # login concurrent-session limit 4
329 # login password-attribute character-restriction upper 2
330 # login password-attribute character-restriction special-char 2
331
332 - name: Replace system configuration.
333 sonic_system:
334 config:
335 hostname: SONIC
336 anycast_address:
337 ipv6: true
338 concurrent_session_limit: 5
339 password_complexity:
340 min_lower_case: 2
341 banner:
342 login: "@\r\nlogin_banner_message\r\n@"
343 state: replaced
344
345 # After state:
346 # ------------
347 # !
348 # SONIC(config)#do show running-configuration
349 # !
350 # banner login @
351 # login_banner_message
352 # @
353 # hostname SONIC
354 # ipv6 anycast-address enable
355 # login concurrent-session limit 5
356 # login password-attribute character-restriction lower 2
357
358 # Using "replaced" state
359 #
360 # Before state:
361 # -------------
362 # !
363 # sonic(config)#do show running-configuration
364 # !
365 # banner login @
366 # login_banner_message
367 # @
368 # ip anycast-mac-address aa:bb:cc:dd:ee:ff
369 # interface-naming standard
370 # login concurrent-session limit 5
371 # login password-attribute character-restriction lower 2
372
373 - name: Replace system device configuration.
374 sonic_system:
375 config:
376 hostname: sonic
377 interface_naming: standard
378 anycast_address:
379 ipv6: true
380 ipv4: true
381 load_share_hash_algo: JENKINS_HASH_HI
382 password_complexity:
383 min_numerals: 2
384 state: replaced
385
386 # After state:
387 # ------------
388 # !
389 # sonic(config)#do show running-configuration
390 # !
391 # ip anycast-address enable
392 # ipv6 anycast-address enable
393 # interface-naming standard
394 # ip load-share hash algorithm JENKINS_HASH_HI
395 # login password-attribute character-restriction numeric 2
396
397 # Using "overridden" state
398 #
399 # Before state:
400 # -------------
401 # !
402 # sonic(config)#do show running-configuration
403 # !
404 # banner motd @
405 # banner - Enjoy the DELL OS
406 # @
407 # banner login disable
408 # ipv6 anycast-address enable
409 # ip load-share hash algorithm JENKINS_HASH_HI
410 # login concurrent-session limit 5
411 # login password-attribute character-restriction numeric 2
412
413 - name: Override system configuration.
414 sonic_system:
415 config:
416 hostname: SONIC
417 interface_naming: standard
418 anycast_address:
419 ipv4: true
420 mac_address: bb:aa:cc:dd:ee:ff
421 load_share_hash_algo: CRC_XOR
422 concurrent_session_limit: 4
423 password_complexity:
424 min_upper_case: 1
425 banner:
426 motd_banner_disable: true
427 login: "@\r\nbanner_login_message\r\n@"
428 motd: "@\r\nbanner_motd_message\r\n@"
429 login_banner_disable: false
430 state: overridden
431
432 # After state:
433 # ------------
434 # !
435 # SONIC(config)#do show running-configuration
436 # !
437 # banner login @
438 # banner_login_message
439 # @
440 # banner motd @
441 # banner_motd_message
442 # @
443 # banner motd disable
444 # hostname SONIC
445 # ip anycast-mac-address bb:aa:cc:dd:ee:ff
446 # ip anycast-address enable
447 # interface-naming standard
448 # ip load-share hash algorithm CRC_XOR
449 # login concurrent-session limit 4
450 # login password-attribute character-restriction upper 1
451
452 # Using "merged" state
453 #
454 # Before state:
455 # -------------
456 # !
457 # sonic(config)#do show running-configuration
458 # !
459
460 - name: Merge provided configuration with device configuration
461 dellemc.enterprise_sonic.sonic_system:
462 config:
463 hostname: SONIC
464 interface_naming: standard
465 auto_breakout: ENABLE
466 load_share_hash_algo: JENKINS_HASH_HI
467 audit_rules: BASIC
468 exec_timeout: 15
469 state: merged
470
471 # After state:
472 # ------------
473 # !
474 # SONIC(config)#do show running-configuration
475 # !
476 # hostname SONIC
477 # interface-naming standard
478 # auto-breakout
479 # ip load-share hash algorithm JENKINS_HASH_HI
480 # auditd-system rules basic
481 # login exec-timeout 15
482
483 # Using "deleted" state
484 #
485 # Before state:
486 # -------------
487 # !
488 # SONIC(config)#do show running-configuration
489 # !
490 # hostname SONIC
491 # interface-naming standard
492 # auto-breakout
493 # ip load-share hash algorithm JENKINS_HASH_HI
494 # auditd-system rules basic
495 # login exec-timeout 15
496
497 - name: Delete auto-breakout configuration on the device
498 dellemc.enterprise_sonic.sonic_system:
499 config:
500 hostname: SONIC
501 auto_breakout: ENABLE
502 load_share_hash_algo: JENKINS_HASH_HI
503 audit_rules: BASIC
504 login_exec_timeout: 15
505 state: deleted
506
507 # After state:
508 # ------------
509 # !
510 # sonic(config)#do show running-configuration
511 # !
512 # interface-naming standard
513 """
514
515 RETURN = """
516 before:
517 description: The configuration prior to the module invocation.
518 returned: always
519 type: list
520 sample: >
521 The configuration returned will always be in the same format
522 as the parameters above.
523 after:
524 description: The resulting configuration module invocation.
525 returned: when changed
526 type: list
527 sample: >
528 The configuration returned will always be in the same format
529 as the parameters above.
530 commands:
531 description: The set of commands pushed to the remote device.
532 returned: always
533 type: list
534 sample: ['command 1', 'command 2', 'command 3']
535 """
536
537
538 from ansible.module_utils.basic import AnsibleModule
539 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.system.system import SystemArgs
540 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.system.system import System
541
542
543 def main():
544 """
545 Main entry point for module execution
546
547 :returns: the result form module invocation
548 """
549 module = AnsibleModule(argument_spec=SystemArgs.argument_spec,
550 supports_check_mode=True)
551
552 result = System(module).execute_module()
553 module.exit_json(**result)
554
555
556 if __name__ == '__main__':
557 main()