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

Update Phalanx platform and device plugin. #3

Merged
merged 10 commits into from Oct 25, 2018
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python

#
# cputemputil.py
#
# Platform-specific CPU temperature Interface for SONiC
#

__author__ = 'Wirut G.<[email protected]>'
__license__ = "GPL"
__version__ = "0.1.0"
__status__ = "Development"

import subprocess
import requests

class CpuTempUtil():
"""Platform-specific CpuTempUtil class"""

def __init__(self):
self.temp_url = "http://[fe80::1:1%eth0.4088]:8080/api/sys/temp"


def get_cpu_temp(self):

# Get list of temperature of CPU cores.
p = subprocess.Popen(['sensors', '-Au', 'coretemp-isa-0000'], stdout=subprocess.PIPE,stderr=subprocess.PIPE)
out, err = p.communicate()
raw_data_list = out.splitlines()
temp_string_list = [i for i, s in enumerate(raw_data_list) if '_input' in s]
tmp_list = [0]

for temp_string in temp_string_list:
tmp_list.append(float(raw_data_list[temp_string].split(":")[1]))

return tmp_list


def get_max_cpu_tmp(self):
# Get maximum temperature from list of temperature of CPU cores.
return max(self.get_cpu_temp())
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python

#############################################################################
# Celestica Phalanx
# Celestica PHALANX
#
# Platform and model specific eeprom subclass, inherits from the base class,
# and provides the followings:
Expand Down
230 changes: 230 additions & 0 deletions device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/fanutil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,230 @@
#!/usr/bin/env python

import re
import requests

class FanUtil():
"""Platform-specific FanUtil class"""

def __init__(self):

self.fan_fru_url = "http://[fe80::1:1%eth0.4088]:8080/api/sys/fruid/fan"
self.sensor_url = "http://[fe80::1:1%eth0.4088]:8080/api/sys/sensors"
self.fru_data_list = None
self.sensor_data_list = None


def request_data(self):
# Reqest data from BMC if not exist.
if self.fru_data_list is None or self.sensor_data_list is None:
fru_data_req = requests.get(self.fan_fru_url)
sensor_data_req = requests.get(self.sensor_url)
fru_json = fru_data_req.json()
sensor_json = sensor_data_req.json()
self.fru_data_list = fru_json.get('Information')
self.sensor_data_list = sensor_json.get('Information')
return self.fru_data_list, self.sensor_data_list


def name_to_index(self, fan_name):
# Get fan index from fan name
match = re.match(r"(FAN)([0-9]+)-(1|2)", fan_name, re.I)
fan_index = None
if match:
i_list = list(match.groups())
fan_index = int(i_list[1])*2 - (int(i_list[2])%2)
return fan_index


def get_num_fans(self):
"""
Get the number of fans
:return: int num_fans
"""
num_fans = 10

return num_fans


def get_fan_speed(self, fan_name):
"""
Get the current speed of the fan, the unit is "RPM"
:return: int fan_speed
"""

try:
# Get real fan index
index = self.name_to_index(fan_name)

# Set key and index.
fan_speed = 0
position_key = "Front" if index % 2 !=0 else "Rear"
index = int(round(float(index)/2))
fan_key = "Fan " + str(index) + " " + position_key

# Request and validate fan information.
self.fru_data_list, self.sensor_data_list = self.request_data()

# Get fan's speed.
for sensor_data in self.sensor_data_list:
sensor_name = sensor_data.get('name')
if "fan" in str(sensor_name):
fan_data = sensor_data.get(fan_key)
fan_sp_list = map(int, re.findall(r'\d+', fan_data))
fan_speed = fan_sp_list[0]

except:
return 0

return fan_speed


def get_fan_low_threshold(self, fan_name):
"""
Get the low speed threshold of the fan.
if the current speed < low speed threshold,
the status of the fan is not ok.
:return: int fan_low_threshold
"""

try:
# Get real fan index
index = self.name_to_index(fan_name)

# Set key and index.
fan_low_threshold = 0
position_key = "Front" if index % 2 !=0 else "Rear"
index = int(round(float(index)/2))
fan_key = "Fan " + str(index) + " " + position_key

# Request and validate fan information.
self.fru_data_list, self.sensor_data_list = self.request_data()

# Get fan's threshold.
for sensor_data in self.sensor_data_list:
sensor_name = sensor_data.get('name')
if "fan" in str(sensor_name):
fan_data = sensor_data.get(fan_key)
fan_sp_list = map(int, re.findall(r'\d+', fan_data))
fan_low_threshold = fan_sp_list[1]

except:
return "N/A"

return fan_low_threshold


def get_fan_high_threshold(self, fan_name):
"""
Get the hight speed threshold of the fan,
if the current speed > high speed threshold,
the status of the fan is not ok
:return: int fan_high_threshold
"""

try:
# Get real fan index
index = self.name_to_index(fan_name)

# Set key and index.
fan_high_threshold = 0
position_key = "Front" if index % 2 !=0 else "Rear"
index = int(round(float(index)/2))
fan_key = "Fan " + str(index) + " " + position_key

# Request and validate fan information.
self.fru_data_list, self.sensor_data_list = self.request_data()

# Get fan's threshold.
for sensor_data in self.sensor_data_list:
sensor_name = sensor_data.get('name')
if "fan" in str(sensor_name):
fan_data = sensor_data.get(fan_key)
fan_sp_list = map(int, re.findall(r'\d+', fan_data))
fan_high_threshold = fan_sp_list[2]

except:
return 0

return fan_high_threshold


def get_fan_pn(self, fan_name):
"""
Get the product name of the fan
:return: str fan_pn
"""

try:
# Get real fan index
index = self.name_to_index(fan_name)

# Set key and index.
fan_pn = "N/A"
index = int(round(float(index)/2))
fan_fru_key = "Fantray" + str(index)

# Request and validate fan information.
self.fru_data_list, self.sensor_data_list = self.request_data()

# Get fan's fru.
for fan_fru in self.fru_data_list:
matching_fan = [s for s in fan_fru if fan_fru_key in s]
if matching_fan:
pn = [s for s in fan_fru if "Part" in s]
fan_pn = pn[0].split()[4]

except:
return "N/A"

return fan_pn


def get_fan_sn(self, fan_name):
"""
Get the serial number of the fan
:return: str fan_sn
"""
try:
# Get real fan index
index = self.name_to_index(fan_name)

# Set key and index.
fan_sn = "N/A"
index = int(round(float(index)/2))
fan_fru_key = "Fantray" + str(index)

# Request and validate fan information.
self.fru_data_list, self.sensor_data_list = self.request_data()

# Get fan's fru.
for fan_fru in self.fru_data_list:
matching_fan = [s for s in fan_fru if fan_fru_key in s]
if matching_fan:
serial = [s for s in fan_fru if "Serial" in s]
fan_sn = serial[0].split()[3]

except:
return "N/A"

return fan_sn

def get_fans_name_list(self):
"""
Get list of fan name.
:return: list fan_names
"""
fan_names = []

# Get the number of fans
n_fan = self.get_num_fans()

# Set fan name and add to the list.
for x in range(1, n_fan + 1):
f_index = int(round(float(x)/2))
pos = 1 if x%2 else 2
fan_name = 'FAN{}-{}'.format(f_index, pos)
fan_names.append(fan_name)

return fan_names

108 changes: 108 additions & 0 deletions device/alibaba/x86_64-alibaba_as23-128h-cl-r0/plugins/optictemputil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/usr/bin/env python

#
# optictemputil.py
#
# Platform-specific Optic module temperature Interface for SONiC
#

__author__ = 'Pradchaya P.<[email protected]>'
__author__ = 'Wirut G.<[email protected]>'
__license__ = "GPL"
__version__ = "0.1.0"
__status__ = "Development"

import os
import sys
import binascii
import subprocess

class OpticTempUtil():
"""Platform-specific OpticTempUtil class"""

def __init__(self):
pass

def read_eeprom_specific_bytes(self, bus_num, dev_addr, offset, num_bytes):
eeprom_raw = []
for i in range(0, num_bytes):
eeprom_raw.append(0x00)

try:
for i in range(0, num_bytes):
p = subprocess.Popen(['i2cget', '-f', '-y', str(bus_num), str(dev_addr), str(offset+i)],stdout=subprocess.PIPE,stderr=subprocess.PIPE)
raw, err = p.communicate()
if p.returncode != 0 or err != '':
raise IOError
eeprom_raw[i] = raw.strip()
except IOError:
return None

return eeprom_raw


def twos_comp(self, num, bits):
try:
if ((num & (1 << (bits - 1))) != 0):
num = num - (1 << bits)
return num
except:
return 0


def calc_temperature(self, cal_type, eeprom_data, offset, size):

msb = int(eeprom_data[offset], 16)
lsb = int(eeprom_data[offset + 1], 16)

result = (msb << 8) | (lsb & 0xff)
result = self.twos_comp(result, 16)

if cal_type == 1:
# Internal calibration
result = float(result / 256.0)
retval = '%.4f' %result

# TODO: Should support external calibration in future.
else:
retval = 0

return retval

def get_optic_temp(self, bus_num, port_type):

EEPROM_ADDR = 0x50
DOM_ADDR = 0x51
EEPROM_OFFSET = 0
DOM_OFFSET = 0

SFP_DMT_ADDR = 92
SFP_DMT_WIDTH = 1
SFP_TEMP_DATA_ADDR = 96
SFP_TEMP_DATA_WIDTH = 2

QSFP_TEMP_DATA_ADDR = 22
QSFP_TEMP_DATA_WIDTH = 2
temperature_raw = None

if port_type == 'QSFP':

# QSFP only have internal calibration mode.
cal_type = 1
# read temperature raw value
temperature_raw = self.read_eeprom_specific_bytes(bus_num,EEPROM_ADDR,(EEPROM_OFFSET+QSFP_TEMP_DATA_ADDR),QSFP_TEMP_DATA_WIDTH)
else:
# read calibration type at bit 5
cal_type = self.read_eeprom_specific_bytes(bus_num,EEPROM_ADDR,EEPROM_OFFSET+SFP_DMT_ADDR,SFP_DMT_WIDTH)
if cal_type is None:
cal_type = 0
else:
cal_type = (int(cal_type[0],16) >> 5 ) & 1
# read temperature raw value
temperature_raw = self.read_eeprom_specific_bytes(bus_num,DOM_ADDR,(DOM_OFFSET+SFP_TEMP_DATA_ADDR),SFP_TEMP_DATA_WIDTH)

#calculate temperature
if temperature_raw is not None:
return self.calc_temperature(cal_type, temperature_raw, 0, 2)
else:
return 0
Loading