Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'sonic_psu',
'sonic_sfp',
'sonic_thermal',
'sonic_sensor'
],
classifiers=[
'Development Status :: 3 - Alpha',
Expand Down
Empty file added sonic_sensor/__init__.py
Empty file.
41 changes: 41 additions & 0 deletions sonic_sensor/sensor_base.py
Original file line number Diff line number Diff line change
@@ -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()