@@ -45,16 +45,44 @@ PSUUTIL_LOAD_ERROR = 1
4545
4646logger = Logger (SYSLOG_IDENTIFIER )
4747
48+ platform_psuutil = None
49+ platform_chassis = None
50+
51+ # temporary wrappers that are compliable with both new platform api and old-style plugin mode
52+ def _wrapper_get_num_psus ():
53+ if platform_chassis is not None :
54+ try :
55+ return platform_chassis .get_num_psus ()
56+ except NotImplementedError :
57+ pass
58+ return platform_psuutil .get_num_psus ()
59+
60+ def _wrapper_get_psus_presence (psu_index ):
61+ if platform_chassis is not None :
62+ try :
63+ return platform_chassis .get_psu (psu_index - 1 ).get_presence ()
64+ except NotImplementedError :
65+ pass
66+ return platform_psuutil .get_psu_presence (psu_index )
67+
68+ def _wrapper_get_psus_status (psu_index ):
69+ if platform_chassis is not None :
70+ try :
71+ return platform_chassis .get_psu (psu_index - 1 ).get_powergood_status ()
72+ except NotImplementedError :
73+ pass
74+ return platform_psuutil .get_psu_status (psu_index )
75+
4876#
4977# Helper functions =============================================================
5078#
5179
52- def psu_db_update (psuutil , psu_tbl , psu_num ):
80+ def psu_db_update (psu_tbl , psu_num ):
5381 for psu_index in range (1 , psu_num + 1 ):
5482 fvs = swsscommon .FieldValuePairs ([(PSU_INFO_PRESENCE_FIELD ,
55- 'true' if psuutil . get_psu_presence (psu_index ) else 'false' ),
83+ 'true' if _wrapper_get_psus_presence (psu_index ) else 'false' ),
5684 (PSU_INFO_STATUS_FIELD ,
57- 'true' if psuutil . get_psu_status (psu_index ) else 'false' )])
85+ 'true' if _wrapper_get_psus_status (psu_index ) else 'false' )])
5886 psu_tbl .set (PSU_INFO_KEY_TEMPLATE .format (psu_index ), fvs )
5987
6088#
@@ -82,30 +110,41 @@ class DaemonPsud(DaemonBase):
82110
83111 # Run daemon
84112 def run (self ):
113+ global platform_psuutil
114+ global platform_chassis
115+
85116 logger .log_info ("Starting up..." )
86117
87- # Load platform-specific psuutil class
118+ # Load new platform api class
88119 try :
89- platform_psuutil = self .load_platform_util (PLATFORM_SPECIFIC_MODULE_NAME , PLATFORM_SPECIFIC_CLASS_NAME )
120+ import sonic_platform .platform
121+ platform_chassis = sonic_platform .platform .Platform ().get_chassis ()
90122 except Exception as e :
91- logger .log_error ("Failed to load psuutil: %s" % (str (e )), True )
92- sys .exit (PSUUTIL_LOAD_ERROR )
123+ logger .log_warning ("Failed to load chassis due to {}" .format (repr (e )))
124+
125+ # Load platform-specific psuutil class
126+ if platform_chassis is None :
127+ try :
128+ platform_psuutil = self .load_platform_util (PLATFORM_SPECIFIC_MODULE_NAME , PLATFORM_SPECIFIC_CLASS_NAME )
129+ except Exception as e :
130+ logger .log_error ("Failed to load psuutil: %s" % (str (e )), True )
131+ sys .exit (PSUUTIL_LOAD_ERROR )
93132
94133 # Connect to STATE_DB and create psu/chassis info tables
95134 state_db = daemon_base .db_connect (swsscommon .STATE_DB )
96135 chassis_tbl = swsscommon .Table (state_db , CHASSIS_INFO_TABLE )
97136 psu_tbl = swsscommon .Table (state_db , PSU_INFO_TABLE )
98137
99138 # Post psu number info to STATE_DB
100- psu_num = platform_psuutil . get_num_psus ()
139+ psu_num = _wrapper_get_num_psus ()
101140 fvs = swsscommon .FieldValuePairs ([(CHASSIS_INFO_PSU_NUM_FIELD , str (psu_num ))])
102141 chassis_tbl .set (CHASSIS_INFO_KEY_TEMPLATE .format (1 ), fvs )
103142
104143 # Start main loop
105144 logger .log_info ("Start daemon main loop" )
106145
107146 while not self .stop .wait (PSU_INFO_UPDATE_PERIOD_SECS ):
108- psu_db_update (platform_psuutil , psu_tbl , psu_num )
147+ psu_db_update (psu_tbl , psu_num )
109148
110149 logger .log_info ("Stop daemon main loop" )
111150
0 commit comments