diff --git a/setup.py b/setup.py index 21ee9eeb8..10085bf62 100644 --- a/setup.py +++ b/setup.py @@ -22,6 +22,7 @@ 'sonic_psu', 'sonic_sfp', 'sonic_thermal', + 'sonic_sensor' ], classifiers=[ 'Development Status :: 3 - Alpha', diff --git a/sonic_sensor/__init__.py b/sonic_sensor/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/sonic_sensor/sensor_base.py b/sonic_sensor/sensor_base.py new file mode 100644 index 000000000..d2bceeeae --- /dev/null +++ b/sonic_sensor/sensor_base.py @@ -0,0 +1,41 @@ +#!/usr/bin/python + +######################################################################### +# # +# sensor_base.py # +# # +# Abstract base class for implementing a platform-specific class # +# to interact with sensors available from different sources in SONiC # +######################################################################### + +import subprocess +import sys + +class SensorBase(object): + """ + Abstract base class for interfacing with a sensor + """ + def __init__(self): + self.ssh_connection = None + + def get_local_data(self): + """ + Retrieves output derived from inbuilt sensors detected in SONiC CPU + Returns: + string: voltages, fans and temps output derived from inbuilt sensors detected in SONiC CPU + """ + sensor_cmd = "sensors" + p = subprocess.Popen(sensor_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = p.communicate() + ## Wait for end of command. Get return returncode ## + returncode = p.returncode + ## if no error, get the sensor result ## + if returncode == 0: + print("*************** SONiC CPU OUTPUT ***********") + print(stdout.rstrip("\n")) + else: + print('exit code: {}. Error -> {}'.format(returncode, stderr)) + sys.stderr.write(stderr) + + def get_data_api(self): + self.get_local_data()