Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add command line support for thermal control #777

Merged
merged 8 commits into from
Jan 24, 2020
73 changes: 73 additions & 0 deletions scripts/fanshow
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/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 = 'presence'
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()




68 changes: 68 additions & 0 deletions scripts/tempershow
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/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()




Junchao-Mellanox marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
'scripts/dropconfig',
'scripts/dropstat',
'scripts/ecnconfig',
'scripts/fanshow',
'scripts/fast-reboot',
'scripts/fast-reboot-dump.py',
'scripts/fdbclear',
Expand All @@ -86,6 +87,7 @@
'scripts/route_check_test.sh',
'scripts/sfpshow',
'scripts/teamshow',
'scripts/tempershow',
'scripts/warm-reboot',
'scripts/watermarkstat',
'scripts/watermarkcfg'
Expand Down
14 changes: 14 additions & 0 deletions show/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,20 @@ def ssdhealth(device, verbose, vendor):
options += " -e" if vendor else ""
run_command(cmd + options, display_cmd=verbose)

# 'fanstatus' subcommand ("show platform fanstatus")
@platform.command()
def fanstatus():
Junchao-Mellanox marked this conversation as resolved.
Show resolved Hide resolved
"""Show fan status information"""
cmd = 'fanshow'
run_command(cmd)

# 'temperature' subcommand ("show platform temperature")
@platform.command()
def temperature():
"""Show device temperature information"""
cmd = 'tempershow'
run_command(cmd)

#
# 'logging' command ("show logging")
#
Expand Down