forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add command line support for thermal control (sonic-net#777)
Add a "show platform fanstatus" command to allow user fetch FAN status data. Add a "show platform temperature" command to allow user fetch thermal status data.
- Loading branch information
1 parent
377881d
commit c139a23
Showing
4 changed files
with
149 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#!/usr/bin/python | ||
""" | ||
Script to show fan status. | ||
""" | ||
from __future__ import print_function | ||
|
||
import argparse | ||
|
||
from tabulate import tabulate | ||
from swsssdk import SonicV2Connector | ||
|
||
|
||
header = ['FAN', 'Speed', 'Direction', 'Presence', 'Status', 'Timestamp'] | ||
|
||
FAN_TABLE_NAME = 'FAN_INFO' | ||
SPEED_FIELD_NAME = 'speed' | ||
DIRECTION_FIELD_NAME = 'direction' | ||
PRESENCE_FIELD_NAME = 'presence' | ||
STATUS_FIELD_NAME = 'status' | ||
TIMESTAMP_FIELD_NAME = 'timestamp' | ||
|
||
|
||
class FanShow(object): | ||
def __init__(self): | ||
self.db = SonicV2Connector(host="127.0.0.1") | ||
self.db.connect(self.db.STATE_DB) | ||
|
||
def show(self): | ||
keys = self.db.keys(self.db.STATE_DB, FAN_TABLE_NAME + '*') | ||
if not keys: | ||
print('Fan Not detected\n') | ||
return | ||
|
||
table = [] | ||
for key in keys: | ||
key_list = key.split('|') | ||
if len(key_list) != 2: # error data in DB, log it and ignore | ||
print('Warn: Invalid key in table FAN_INFO: {}'.format(key)) | ||
continue | ||
|
||
name = key_list[1] | ||
data_dict = self.db.get_all(self.db.STATE_DB, key) | ||
try: | ||
speed = float(data_dict[SPEED_FIELD_NAME]) | ||
if speed > 100: | ||
speed = '{}RPM'.format(int(speed)) | ||
else: | ||
speed = '{}%'.format(data_dict[SPEED_FIELD_NAME]) | ||
except ValueError as e: | ||
print('Warn: cannot convert speed value from {}'.format(data_dict[SPEED_FIELD_NAME])) | ||
speed = data_dict[SPEED_FIELD_NAME] | ||
|
||
presence = data_dict[PRESENCE_FIELD_NAME].lower() | ||
presence = 'Present' if presence == 'true' else 'Not Present' | ||
status = data_dict[STATUS_FIELD_NAME].lower() | ||
status = 'OK' if status == 'true' else 'Not OK' | ||
|
||
table.append((name, speed, data_dict[DIRECTION_FIELD_NAME], presence, status, data_dict[TIMESTAMP_FIELD_NAME])) | ||
|
||
if table: | ||
table.sort() | ||
print(tabulate(table, header, tablefmt='simple', stralign='right')) | ||
else: | ||
print('No fan status data available\n') | ||
|
||
|
||
if __name__ == "__main__": | ||
fanShow = FanShow() | ||
fanShow.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#!/usr/bin/python | ||
""" | ||
Script to show fan status. | ||
""" | ||
from __future__ import print_function | ||
|
||
import argparse | ||
|
||
from tabulate import tabulate | ||
from swsssdk import SonicV2Connector | ||
|
||
|
||
header = ['NAME', 'Temperature', 'High Threshold', 'Low Threshold', 'Critical High Threshold', 'Critical Low Threshold', 'Warning Status', 'Timestamp'] | ||
|
||
TEMPER_TABLE_NAME = 'TEMPERATURE_INFO' | ||
TEMPER_FIELD_NAME = 'temperature' | ||
TIMESTAMP_FIELD_NAME = 'timestamp' | ||
HIGH_THRESH_FIELD_NAME = 'high_threshold' | ||
LOW_THRESH_FIELD_NAME = 'low_threshold' | ||
CRIT_HIGH_THRESH_FIELD_NAME = 'critical_high_threshold' | ||
CRIT_LOW_THRESH_FIELD_NAME = 'critical_low_threshold' | ||
WARNING_STATUS_FIELD_NAME = 'warning_status' | ||
|
||
|
||
class TemperShow(object): | ||
def __init__(self): | ||
self.db = SonicV2Connector(host="127.0.0.1") | ||
self.db.connect(self.db.STATE_DB) | ||
|
||
def show(self): | ||
keys = self.db.keys(self.db.STATE_DB, TEMPER_TABLE_NAME + '*') | ||
if not keys: | ||
print('Thermal Not detected\n') | ||
return | ||
|
||
table = [] | ||
for key in keys: | ||
key_list = key.split('|') | ||
if len(key_list) != 2: # error data in DB, log it and ignore | ||
print('Warn: Invalid key in table {}: {}'.format(TEMPER_TABLE_NAME, key)) | ||
continue | ||
|
||
name = key_list[1] | ||
data_dict = self.db.get_all(self.db.STATE_DB, key) | ||
table.append((name, | ||
data_dict[TEMPER_FIELD_NAME], | ||
data_dict[HIGH_THRESH_FIELD_NAME], | ||
data_dict[LOW_THRESH_FIELD_NAME], | ||
data_dict[CRIT_HIGH_THRESH_FIELD_NAME], | ||
data_dict[CRIT_LOW_THRESH_FIELD_NAME], | ||
data_dict[WARNING_STATUS_FIELD_NAME], | ||
data_dict[TIMESTAMP_FIELD_NAME] | ||
)) | ||
|
||
if table: | ||
table.sort() | ||
print(tabulate(table, header, tablefmt='simple', stralign='right')) | ||
else: | ||
print('No tempeature data available\n') | ||
|
||
|
||
if __name__ == "__main__": | ||
temperShow = TemperShow() | ||
temperShow.show() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters