1+ #!/usr/bin/env python3
2+
3+ # Name: chassis_module_set_admin_state.py, version: 1.0
4+ # Syntax: chassis_module_set_admin_state.py <module_name> <up/down>
5+ #
6+ import re
7+ import sys
8+ import subprocess
9+ import time
10+
11+ from platform_ndk import nokia_common
12+ from sonic_py_common .logger import Logger
13+
14+ logger = Logger ("chassis_module_set_admin_state.py" )
15+
16+ sfm_asic_dict = {
17+ 0 : [0 ,1 ],
18+ 1 : [2 ,3 ],
19+ 2 : [4 ,5 ],
20+ 3 : [6 ,7 ],
21+ 4 : [8 ,9 ],
22+ 5 : [10 ,11 ],
23+ 6 : [12 ,13 ],
24+ 7 : [14 ,15 ]
25+ }
26+
27+ sfm_hw_slot_mapping = {
28+ 0 : 15 ,
29+ 1 : 16 ,
30+ 2 : 17 ,
31+ 3 : 18 ,
32+ 4 : 19 ,
33+ 5 : 20 ,
34+ 6 : 21 ,
35+ 7 : 22
36+ }
37+
38+ def main ():
39+ argc = len (sys .argv )
40+
41+ if argc != 3 :
42+ logger .log_warning ("Missing parameters!" )
43+ return
44+
45+ module = sys .argv [1 ]
46+ state = sys .argv [2 ]
47+
48+ if not module .startswith ("FABRIC-CARD" ):
49+ logger .log_warning ("Failed to set {} state. Admin state can only be set on Fabric module" .format (module ))
50+ return
51+
52+ num = int (re .search (r"(\d+)$" , module ).group ())
53+ if num not in sfm_hw_slot_mapping :
54+ logger .log_error ("Invalid module name {}" .format (module ))
55+ return
56+
57+ if state == "down" :
58+ logger .log_info ("Shutting down chassis module {}" .format (module ))
59+ asic_list = sfm_asic_dict [num ]
60+ for asic in asic_list :
61+ logger .log_info ("Shut down swss@{} and syncd@{} ..." .format (asic , asic ))
62+ # Process state
63+ process = subprocess .Popen (['sudo' , 'systemctl' , 'stop' , 'swss@{}.service' .format (asic )],
64+ stdout = subprocess .PIPE , stderr = subprocess .PIPE )
65+ stdout , stderr = process .communicate ()
66+ outstr = stdout .decode ('ascii' )
67+ # wait for service is down
68+ time .sleep (2 )
69+
70+ logger .log_info ("Power off {} module ..." .format (module ))
71+ hw_slot = sfm_hw_slot_mapping [num ]
72+ nokia_common ._power_onoff_SFM (hw_slot ,False )
73+ logger .log_info ("Shut down chassis module {} complete" .format (module ))
74+ else :
75+ logger .log_info ("Starting up chassis module {}" .format (module ))
76+ logger .log_info ("Power up {} module ..." .format (module ))
77+ hw_slot = sfm_hw_slot_mapping [num ]
78+ nokia_common ._power_onoff_SFM (hw_slot ,True )
79+ # wait SFM HW init done.
80+ time .sleep (15 )
81+
82+ asic_list = sfm_asic_dict [num ]
83+ for asic in asic_list :
84+ logger .log_info ("Start the swss@{} and syncd@{} ..." .format (asic , asic ))
85+ # Process state
86+ process = subprocess .Popen (['sudo' , 'systemctl' , 'start' , 'swss@{}.service' .format (asic )],
87+ stdout = subprocess .PIPE , stderr = subprocess .PIPE )
88+ stdout , stderr = process .communicate ()
89+ outstr = stdout .decode ('ascii' )
90+ logger .log_info ("Started chassis module {} complete" .format (module ))
91+ return
92+
93+ if __name__ == "__main__" :
94+ main ()
0 commit comments