From 55bc5c5b3c37699ceae03713f0f7ddf033a68ad5 Mon Sep 17 00:00:00 2001 From: Pradchaya Phucharoen Date: Tue, 17 Mar 2020 14:20:28 +0700 Subject: [PATCH] [platform/broadcom] Remove unused tools --- .../tools/bmc_wdt/bmc_wdt.py | 118 ---- .../tools/bmc_wdt/bmc_wdt.service | 10 - .../tools/bmcutil/bmc-exec | 45 -- .../tools/bmcutil/bmcpwd | 1 - .../tools/bmcutil/bmcutil.py | 296 -------- .../tools/platformutil.py | 642 ------------------ .../tools/power_utils/power | 86 --- .../tools/read_optic_temp.py | 189 ------ .../tools/sync_bmc/bmc_vlan.service | 12 - .../tools/sync_bmc/bmc_vlan.sh | 7 - .../tools/sync_bmc/sync_bmc.py | 203 ------ .../tools/sync_bmc/sync_bmc.service | 10 - .../tools/sync_bmc/sync_bmc.timer | 10 - 13 files changed, 1629 deletions(-) delete mode 100644 platform/broadcom/sonic-platform-modules-cel/tools/bmc_wdt/bmc_wdt.py delete mode 100755 platform/broadcom/sonic-platform-modules-cel/tools/bmc_wdt/bmc_wdt.service delete mode 100755 platform/broadcom/sonic-platform-modules-cel/tools/bmcutil/bmc-exec delete mode 100644 platform/broadcom/sonic-platform-modules-cel/tools/bmcutil/bmcpwd delete mode 100644 platform/broadcom/sonic-platform-modules-cel/tools/bmcutil/bmcutil.py delete mode 100644 platform/broadcom/sonic-platform-modules-cel/tools/platformutil.py delete mode 100755 platform/broadcom/sonic-platform-modules-cel/tools/power_utils/power delete mode 100644 platform/broadcom/sonic-platform-modules-cel/tools/read_optic_temp.py delete mode 100644 platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/bmc_vlan.service delete mode 100644 platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/bmc_vlan.sh delete mode 100644 platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/sync_bmc.py delete mode 100644 platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/sync_bmc.service delete mode 100644 platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/sync_bmc.timer diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/bmc_wdt/bmc_wdt.py b/platform/broadcom/sonic-platform-modules-cel/tools/bmc_wdt/bmc_wdt.py deleted file mode 100644 index e22d96326b76..000000000000 --- a/platform/broadcom/sonic-platform-modules-cel/tools/bmc_wdt/bmc_wdt.py +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/env python - -############################################################################# -# # -# Service to control CPU watchdog # -# # -############################################################################# - -import os -import time -import logging -import logging.handlers -import requests -import argparse -import subprocess - -HEARTBEAT_TIME = 20 -MAX_FILE_COUNT = 3 -WDT_TIMEOUT = 60 -MAX_LOG_BYTES = 20 * 1000000 -HOSTNAME = "240.1.1.1" -WDT_URL = "http://240.1.1.1:8080/api/sys/watchdog" -BMC_WDT_LOG = '/var/log/bmc_feed_watchdog.log' - - -lh = logging.handlers.RotatingFileHandler( - filename=BMC_WDT_LOG, maxBytes=MAX_LOG_BYTES, backupCount=MAX_FILE_COUNT) -formatter = logging.Formatter( - fmt='%(asctime)s - %(name)s - %(levelname)s - %(message)s', datefmt='%b %d %H:%M:%S') -lh.setFormatter(formatter) -logger = logging.getLogger('bmc_feed_watchdog') -logger.addHandler(lh) -logger.setLevel(logging.INFO) - - -def set_wdt_timeout(timeout): - data = dict() - data["wdt"] = str(timeout) - status_code = -1 - message = None - try: - res = requests.post(WDT_URL, json=data, timeout=5) - status_code = res.status_code - message = res.json().get('result') - except: - message = "Unable set watchdog timeout" - - return status_code, message - - -def ping(): - try: - response = subprocess.check_output( - ['ping', '-c', '3', HOSTNAME], - stderr=subprocess.STDOUT, - universal_newlines=True - ) - except subprocess.CalledProcessError: - response = None - return response != None - - -def start(): - logger.info("Started CPU watchdog") - error_flag = 1 - status_code = -1 - while True: - status_code, message = set_wdt_timeout(WDT_TIMEOUT) - - # Error checking - if status_code == 200 and message != 'success': - logger.error(message) - error_flag = 1 - elif status_code != 200 and not ping(): - logger.error("Unable to connect to BMC") - error_flag = 1 - elif status_code != 200 and ping(): - if not error_flag: - logger.error(message) - time.sleep(1) - error_flag = 1 - continue - - # Pass error - if error_flag and status_code == 200 and message == 'success': - error_flag = 0 - logger.info("BMC connection successful") - - time.sleep(HEARTBEAT_TIME) - - -def stop(): - logger.info("Stopping CPU watchdog") - status_code = -1 - while status_code != 200: - status_code, message = set_wdt_timeout(0) - if status_code == 200 and message != 'success': - logger.error(message) - elif status_code != 200 and not ping(): - logger.error("Unable to connect to BMC") - elif ping(): - time.sleep(1) - continue - - logger.info("Stopped CPU watchdog") - - -def main(): - parser = argparse.ArgumentParser(description='') - parser.add_argument('option', choices=["start", "stop"]) - args = parser.parse_args() - if args.option == "start": - start() - stop() - - -if __name__ == "__main__": - main() diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/bmc_wdt/bmc_wdt.service b/platform/broadcom/sonic-platform-modules-cel/tools/bmc_wdt/bmc_wdt.service deleted file mode 100755 index 88c3b5ceb44b..000000000000 --- a/platform/broadcom/sonic-platform-modules-cel/tools/bmc_wdt/bmc_wdt.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Service for enable BMC watchdog. -After=bmc_vlan.service - -[Service] -ExecStart=/usr/bin/python /usr/local/etc/bmc_wdt.py start -ExecStop=/usr/bin/python /usr/local/etc/bmc_wdt.py stop - -[Install] -WantedBy=multi-user.target diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/bmcutil/bmc-exec b/platform/broadcom/sonic-platform-modules-cel/tools/bmcutil/bmc-exec deleted file mode 100755 index 14435e857ff9..000000000000 --- a/platform/broadcom/sonic-platform-modules-cel/tools/bmcutil/bmc-exec +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash -# -# Copyright 2019-present Celestica. All Rights Reserved. -# -# This program file is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the -# Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# for more details. -# -# - -PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin - -command="$@" - -usage() { - echo "Usage: bmc-exec " - echo -} - -run_cmd() { - echo "Run command: "$command - echo - ret=$(curl -m 5 --silent --header "Content-Type:application/json" -d "{\"data\": \"${command}\"}" http://240.1.1.1:8080/api/sys/raw) - if [ -z "$ret" ]; - then - echo "Failed to connect on BMC" - else - echo $ret | python -c "import sys, json; k = json.load(sys.stdin)['result']; print k if type(k) is not list else '\n'.join(k);" - fi - return 0 -} - -if [ $# -lt 1 ]; then - usage - exit -1 -else - run_cmd -fi - -exit $? diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/bmcutil/bmcpwd b/platform/broadcom/sonic-platform-modules-cel/tools/bmcutil/bmcpwd deleted file mode 100644 index 3e24c6b13536..000000000000 --- a/platform/broadcom/sonic-platform-modules-cel/tools/bmcutil/bmcpwd +++ /dev/null @@ -1 +0,0 @@ -kt3I0K_QxQ== \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/bmcutil/bmcutil.py b/platform/broadcom/sonic-platform-modules-cel/tools/bmcutil/bmcutil.py deleted file mode 100644 index 7edc55ac8862..000000000000 --- a/platform/broadcom/sonic-platform-modules-cel/tools/bmcutil/bmcutil.py +++ /dev/null @@ -1,296 +0,0 @@ -#!/usr/bin/python - -""" -bmcutil.py -BMC utility, implements management functions provided by BMC RESTful APIs. -""" - -import requests -import re -import hashlib -import binascii -import os -import base64 - - -# Base class of BmcUtil -class BmcUtilBase(object): - def __init__(self): - self.bmc_info_url = "http://240.1.1.1:8080/api/sys/bmc" - self.bmc_eth_info_url = "http://240.1.1.1:8080/api/sys/eth" - self.bmc_raw_command_url = "http://240.1.1.1:8080/api/sys/raw" - self.bmc_pwd_url = "http://240.1.1.1:8080/api/sys/userpassword" - self.bmc_pwd_path = "/usr/local/etc/bmcpwd" - self.bmc_syslog_url = "http://240.1.1.1:8080/api/sys/syslog" - - def request_data(self, url): - # Reqest data from BMC if not exist. - data_req = requests.get(url) - data_json = data_req.json() - data_list = data_json.get('Information') - return data_list - - def save_bmc_password(self, clear_pwd): - enc = [] - key = "bmc" - for i in range(len(clear_pwd)): - key_c = key[i % len(key)] - enc_c = chr((ord(clear_pwd[i]) + ord(key_c)) % 256) - enc.append(enc_c) - enc_pwd = base64.urlsafe_b64encode("".join(enc)) - - with open(self.bmc_pwd_path, 'w') as file: - file.write(enc_pwd) - - def get_bmc_pass(self): - with open(self.bmc_pwd_path) as file: - data = file.read() - - key = "bmc" - dec = [] - enc = base64.urlsafe_b64decode(data) - for i in range(len(enc)): - key_c = key[i % len(key)] - dec_c = chr((256 + ord(enc[i]) - ord(key_c)) % 256) - dec.append(dec_c) - return "".join(dec) - - def version(self): - """ - Return version information string - @return version string of BMC OS - """ - bmc_version = None - - bmc_version_key = "OpenBMC Version" - bmc_info = self.request_data(self.bmc_info_url) - bmc_version = bmc_info.get(bmc_version_key) - - return str(bmc_version) - - def set_eth0_addr(self, ip_addr, mask): - """ - Set eth0 IPv4 address - @ip_addr MANDATORY, IPv4 ip address string - @mask MANDATORY, IPv4 network mask string - """ - - json_data = dict() - json_data["data"] = "ifconfig eth0 %s netmask %s up" % (ip_addr, mask) - r = requests.post(self.bmc_raw_command_url, json=json_data) - if r.status_code != 200: - return False - return True - - def get_eth0_addr_list(self): - """ - Get eth0 IPv4 address - @return a list of (IPv4 ip address/mask string) - """ - ipv4_adress = [] - eth_data_list = self.request_data(self.bmc_eth_info_url) - - for eth_data in eth_data_list: - if 'inet addr' in eth_data: - ipv4_list = re.findall(r'[0-9]+(?:\.[0-9]+){3}', eth_data) - if len(ipv4_list) == 3: - ipv4 = ipv4_list[0] + "/" + ipv4_list[2] - ipv4_adress.append(ipv4) - - return str(ipv4_adress) - - def set_gateway_ip(self, gw_ip): - """ - Set gateway IPv4 address string - @gw_ip MANATORY, IPv4 address of gateway - """ - - json_data = dict() - json_data["data"] = "route del default" - - r = requests.post(self.bmc_raw_command_url, json=json_data) - if r.status_code != 200: - return False - - json_data["data"] = "route add default gw %s" % gw_ip - r = requests.post(self.bmc_raw_command_url, json=json_data) - if r.status_code != 200: - return False - - return True - - def get_gateway_ip(self): - """ - Get gateway IPv4 address string - @return IPv4 address of gateway - """ - - default_gw = None - - json_data = dict() - json_data["data"] = "route" - - r = requests.post(self.bmc_raw_command_url, json=json_data) - if r.status_code == 200: - data_list = r.json().get('result') - for raw_data in data_list: - if 'default' in raw_data: - route_data = raw_data.split() - default_gw = route_data[1] if len(route_data) > 0 else None - - return str(default_gw) - - def set_user_and_passwd(self, user_name, password): - """ - Set BMC user name and password - @user_name MANDATORY, BMC user - @password MANDATORY, BMC user's password - """ - json_data = dict() - json_data["user"] = str(user_name) - json_data["oldpassword"] = self.get_bmc_pass() - json_data["newpassword"] = password - r = requests.post(self.bmc_pwd_url, json=json_data) - return_data = r.json() - - if r.status_code != 200 or 'success' not in return_data.get('result'): - return False - - self.save_bmc_password(password) - return True - - def add_syslog_server(self, svr_ip, svr_port): - """ - Add syslog server for BMC - @svr_ip MANDATORY, syslog server IP string - @svr_port MANDATORY, syslog server destination port - """ - json_data = dict() - json_data["addr"] = str(svr_ip) - json_data["port"] = str(svr_port) - r = requests.post(self.bmc_syslog_url, json=json_data) - if r.status_code != 200 or 'success' not in r.json().get('result'): - return False - return True - - def get_syslog_server_list(self): - """ - # Get syslog server list of BMC - # @return a list of syslog server ip and destination port pair - """ - syslog_ip = None - syslog_port = None - - json_data = dict() - json_data["data"] = "tail -n 1 /etc/rsyslog.conf" - r = requests.post(self.bmc_raw_command_url, json=json_data) - if r.status_code != 200: - return False - - return_data = r.json() - result = return_data.get("result") - ip = re.findall(r'[0-9]+(?:\.[0-9]+){3}', result[0]) - port = str(result[0]).split(":") - syslog_ip = ip[0] if len(ip) > 0 else None - syslog_port = port[1] if len(port) > 1 else None - - return [syslog_ip, syslog_port] - - def del_syslog_server(self, svr_ip, svr_port): - """ - Delete syslog server for BMC - @svr_ip MANDATORY, syslog server IP string - @svr_port MANDATORY, syslog server destination port - """ - json_data = dict() - json_data["addr"] = "127.0.0.1" - json_data["port"] = str(svr_port) - r = requests.post(self.bmc_syslog_url, json=json_data) - if r.status_code != 200 or 'success' not in r.json().get('result'): - return False - return True - - def get_bmc_system_state(self): - """ - Get BMC system state, includes CPU, memory, storage - MUST contains status of: CPU, memory, disk - dict object: - { - "CPU": { - "StateOutputs": "output of command 'top -bn 1'" - "Usage": "10.0" - }, - "MEMORY": { - "StateOutputs": "output of command 'free -m'" - "Usage": "15.0" # caculate: "free -t | grep \"buffers/cache\" | awk '{ printf \"mem usage : %.1f%%\\n\",$3/($3+$4) * 100}'" - }, - "DISK": { - "StateOutput": "output of command 'df -h'" - "Usage": "12.5" - } - } - """ - - state_data = dict() - bmc_info = self.request_data(self.bmc_info_url) - - cpu_key = "CPU Usage" - cpu_data_raw = bmc_info.get(cpu_key) - cpu_usage = cpu_data_raw.split()[1].strip('%') - cpu_data = dict() - cpu_data["StateOutputs"] = "output of command 'top -bn 1'" - cpu_data["Usage"] = "{:.1f}".format(float(cpu_usage)) - state_data["CPU"] = cpu_data - - disk_key = "Disk Usage" - disk_data_raw = bmc_info.get(disk_key) - disk_usage = disk_data_raw.split()[7].strip('%') - disk_data = dict() - disk_data["StateOutputs"] = "output of command 'df -h'" - disk_data["Usage"] = "{:.1f}".format(float(disk_usage)) - state_data["DISK"] = disk_data - - json_data = dict() - json_data["data"] = "free -t" - mem_usage = "None" - r = requests.post(self.bmc_raw_command_url, json=json_data) - if r.status_code == 200: - mem_data_raw = r.json().get('result')[2] - mem_u = float(mem_data_raw.split()[2]) - mem_f = float(mem_data_raw.split()[3]) - mem_usage = (mem_u/(mem_u+mem_f)) * 100 - mem_data = dict() - mem_data["StateOutputs"] = "output of command 'free -t'" - mem_data["Usage"] = "{:.1f}".format(mem_usage) - state_data["MEMORY"] = mem_data - - return state_data - - def reboot_bmc(self): - """ - Reboot BMC - """ - json_data = dict() - json_data["data"] = "reboot" - r = requests.post(self.bmc_raw_command_url, json=json_data) - if r.status_code != 200: - return False - - return True - - def set_location_led(self, admin_state): - """ - Enable/disable location LED - @admin_state MANDATORY, should be string "on" or "off" - """ - - json_data = dict() - if str(admin_state).lower() not in ["on", "off"]: - return False - - json_data["data"] = "led_location.sh %s" % admin_state - r = requests.post(self.bmc_raw_command_url, json=json_data) - if r.status_code != 200: - return False - - return True diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/platformutil.py b/platform/broadcom/sonic-platform-modules-cel/tools/platformutil.py deleted file mode 100644 index 5c73dd9870f3..000000000000 --- a/platform/broadcom/sonic-platform-modules-cel/tools/platformutil.py +++ /dev/null @@ -1,642 +0,0 @@ -#!/usr/bin/env python -# -# platformutil/main.py -# -# Command-line utility for interacting with PSU in SONiC -# -# example output -# platformutil psu status -# PSU Presence Status PN SN -# PSU 1 PRESENT OK CSU550AP-3-300 M623TW004ZAAL -# PSU 2 NOT_PRESENT N/A N/A N/A -# -# platformutil fan status -# FAN Status Speed Low_thd High_thd PN SN -# FAN 1 OK 10169 RPM 300 RPM 16000 RPM M6510-FAN-F 1000000000014 -# FAN 2 NOT_OK 20000 RPM 300 RPM 16000 RPM M6510-FAN-F 1000000000014 -# -# platformutil sensor status -#Sensor InputName State Value Low_thd High_thd -#----------------- ------------------- ------- -------- --------- ---------- -#syscpld-i2c-0-0d CPU temp NOT_OK 41.0 C 0 C 0.0 C -#syscpld-i2c-0-0d Optical temp NOT_OK 26.0 C 0 C 0.0 C -#syscpld-i2c-0-0d Switch temp NOT_OK 35.0 C 0 C 0.0 C -# -# should implenmet the below classes in the specified plugin -# -# class PsuUtil: -# int get_num_psus(); //get the number of power supply units -# bool get_psu_presence(int index) //get the power status of the psu, index:1,2 -# bool get_psu_status(int index) //get the running status of the psu,index:1,2 -# str get_psu_sn(int index) //get the serial number of the psu, return value example: "M623TW004ZAAL" -# str get_psu_pn(int index) //get the product name of the psu, return value example: "CSU550AP-3-300" -# -# // Get all information of PSUs, returns JSON objects in python 'DICT'. -# // return value of get_all(): -# // Number: mandatory, max number of PSU, integer -# // PSU1, PSU2, ...: mandatory, PSU name, string -# // Present: mandatory for each PSU, present status, boolean, True for present, False for NOT present -# // PowerStatus: conditional, if PRESENT is True, power status of PSU, -# // boolean, True for powered, False for NOT powered -# // PN, conditional, if PRESENT is True, PN of the PSU, string -# // SN, conditional, if PRESENT is True, SN of the PSU, string -# // example: -# // { -# // "Number": 2, -# // "PSU1": { -# // "Present": True, -# // "PowerStatus": True, -# // "PN": "PN-EXAMPLE-123", -# // "SN": "SN-EXAMPLE-123", -# // "InputStatus": True, -# // "OutputStatus": True, -# // "InputType": "DC" -# // "AirFlow": "BTOF" -# // }, -# // "PSU2": { -# // "Present": False -# // } -# // } -# dict get_all() - -# class FanUtil: -# int get_fans_name_list(); //get the names of all the fans(FAN1-1,FAN1-2,FAN2-1,FAN2-2...) -# int get_fan_speed(int index); //get the current speed of the fan, the unit is "RPM" -# int get_fan_low_threshold(int index); //get the low speed threshold of the fan, if the current speed < low speed threshold, the status of the fan is ok. -# int get_fan_high_threshold(int index); //get the hight speed threshold of the fan, if the current speed > high speed threshold, the status of the fan is not ok -# str get_fan_pn(int index);//get the product name of the fan -# str get_fan_sn(int index);//get the serial number of the fan -# // Get all information of system FANs, returns JSON objects in python 'DICT'. -# // Number, mandatory, max number of FAN, integer -# // FAN1_1, FAN1_2, ... mandatory, FAN name, string -# // Present, mandatory for each FAN, present status, boolean, True for present, False for NOT present, read directly from h/w -# // Running, conditional, if PRESENT is True, running status of the FAN, True for running, False for stopped, read directly from h/w -# // Speed, conditional, if PRESENT is True, real FAN speed, float, read directly from h/w -# // LowThd, conditional, if PRESENT is True, lower bound of FAN speed, float, read from h/w -# // HighThd, conditional, if PRESENT is True, upper bound of FAN speed, float, read from h/w -# // PN, conditional, if PRESENT is True, PN of the FAN, string -# // SN, conditional, if PRESENT is True, SN of the FAN, string -# // Return value python 'dict' object example: -# // { -# // "Number": 3, -# // "FAN1_1": { -# // "Present": True, -# // "Running": True, -# // "Speed": 2000.0, -# // "LowThd": 1000.0, -# // "HighThd": 15000.0, -# // "PN": "PN-EXAMPLE-123", -# // "SN": "SN-EXAMPLE-123" -# // "Status": True, -# // "AirFlow": "FTOB" -# // }, -# // "FAN1_2": { -# // "Present": True, -# // "Running": True, -# // "Speed": 2500.0, -# // "LowThd": 1000.0, -# // "HighThd": 15000.0, -# // "PN": "PN-EXAMPLE-456", -# // "SN": "SN-EXAMPLE-456" -# // "Status": True, -# // "AirFlow": "BTOF" -# // }, -# // "FAN2_1": { -# // "Present": True, -# // "Running": False -# // }, -# // "FAN2_2": { -# // "Present": True, -# // "Running": False -# // }, -# // "FAN3_1": { -# // "Present": False -# // }, -# // "FAN3_2": { -# // "Present": False -# // } -# // } -# dict get_all() -# -# class SensorUtil: -# int get_num_sensors(); //get the number of sensors -# int get_sensor_input_num(int index); //get the number of the input items of the specified sensor -# str get_sensor_name(int index);// get the device name of the specified sensor.for example "coretemp-isa-0000" -# str get_sensor_input_name(int sensor_index, int input_index); //get the input item name of the specified input item of the specified sensor index, for example "Physical id 0" -# str get_sensor_input_type(int sensor_index, int input_index); //get the item type of the specified input item of the specified sensor index, the return value should -# //among "voltage","temperature"... -# float get_sensor_input_value(int sensor_index, int input_index);//get the current value of the input item, the unit is "V" or "C"... -# float get_sensor_input_low_threshold(int sensor_index, int input_index); //get the low threshold of the value, the status of this item is not ok if the current -# //value high_threshold -# // Get all information of system sensors, returns JSON objects in python 'DICT'. -# // SensorName1, SensorName2, ... optional, string -# // SensorInput1, SensorInput2, ... optional, string -# // Type, mandatory in SensorInput$INDEX, should be on of { "temperature", "voltage", "power", "amp", "RPM" } -# // Value, mandatory in SensorInput$INDEX, float , real value -# // LowThd, mandatory in SensorInput$INDEX, float , lower bound of value -# // HighThd, mandatory in SensorInput$INDEX, float , upper bound of value -# // Return python 'dict' objects, example: -# // { -# // "SensorName1": { -# // "CPU_TEMP": -# // "Type": "temperature", -# // "Value": 37.3, -# // "LowThd": 0.0, -# // "HighThd": 110.0 -# // }, -# // "SWITCH_TEMP": { -# // "Type": "temperature", -# // "Value": 45.2, -# // "LowThd": 0.0, -# // "HighThd": 108.0 -# // }, -# // "INLET_TEMP": { -# // "Type": "temperature", -# // "Value": 22.0, -# // "LowThd": 0.0, -# // "HighThd": 70.0 -# // }, -# // "Sys_AirFlow": "BTOF", -# // "Switch_VDDCore_0.8v": { -# // "Type": "voltage", -# // "Value": 0.75, -# // "LowThd": 0.7, -# // "HighThd": 0.85 -# // }, -# // "Cpu_VDDCore_0.8v": { -# // "Type": "voltage", -# // "Value": 0.75, -# // "LowThd": 0.7, -# // "HighThd": 0.85 -# // }, -# // "SensorInput1": { -# // "Type": "temperature", -# // "Value": 30.0, -# // "LowThd": 0.0, -# // "HighThd": 100.0" -# // }, -# // "SensorInput2": { -# // "Type": "voltage", -# // "Value": 0.5, -# // "LowThd": 0.0, -# // "HighThd": 1.5 -# // }, -# // "SensorInput3": { -# // "Type": "power", -# // "Value": 2.5, -# // "LowThd": 0.0, -# // "HighThd": 5.0 -# // } -# // }, -# // "SensorName2": { -# // "SensorInput1": { -# // "Type": "RPM", -# // "Value": 2000.0, -# // "LowThd": 1000.0, -# // "HighThd": 15000.0 -# // }, -# // "SensorInputName2": { -# // "Type": "amp", -# // "Value": 0.1, -# // "LowThd": 0.0, -# // "HighThd": 0.3 -# // } -# // } -# // } - -try: - import sys - import os - import subprocess - import click - import imp - import syslog - import types - import traceback - from tabulate import tabulate -except ImportError as e: - raise ImportError("%s - required module not found" % str(e)) - -VERSION = '1.2' - -SYSLOG_IDENTIFIER = "platformutil" -PLATFORM_PSU_MODULE_NAME = "psuutil" -PLATFORM_PSU_CLASS_NAME = "PsuUtil" - -#gongjian add -PLATFORM_SENSOR_MODULE_NAME = "sensorutil" -PLATFORM_SENSOR_CLASS_NAME = "SensorUtil" - -PLATFORM_FAN_MODULE_NAME = "fanutil" -PLATFORM_FAN_CLASS_NAME = "FanUtil" -#end gongjian add - -PLATFORM_ROOT_PATH = '/usr/share/sonic/device' -PLATFORM_ROOT_PATH_DOCKER = '/usr/share/sonic/platform' -SONIC_CFGGEN_PATH = '/usr/local/bin/sonic-cfggen' -MINIGRAPH_PATH = '/etc/sonic/minigraph.xml' -HWSKU_KEY = "DEVICE_METADATA['localhost']['hwsku']" -PLATFORM_KEY = "DEVICE_METADATA['localhost']['platform']" - -# Global platform-specific psuutil class instance -platform_psuutil = None - -#gongjian add -platform_sensorutil = None -Platform_fanutil = None -#end gongjian add - -# ========================== Syslog wrappers ========================== - - -def log_info(msg, also_print_to_console=False): - syslog.openlog(SYSLOG_IDENTIFIER) - syslog.syslog(syslog.LOG_INFO, msg) - syslog.closelog() - - if also_print_to_console: - click.echo(msg) - - -def log_warning(msg, also_print_to_console=False): - syslog.openlog(SYSLOG_IDENTIFIER) - syslog.syslog(syslog.LOG_WARNING, msg) - syslog.closelog() - - if also_print_to_console: - click.echo(msg) - - -def log_error(msg, also_print_to_console=False): - syslog.openlog(SYSLOG_IDENTIFIER) - syslog.syslog(syslog.LOG_ERR, msg) - syslog.closelog() - - if also_print_to_console: - click.echo(msg) - - -# ==================== Methods for initialization ==================== - -# Returns platform and HW SKU -def get_platform_and_hwsku(): - try: - proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-H', '-v', PLATFORM_KEY], - stdout=subprocess.PIPE, - shell=False, - stderr=subprocess.STDOUT) - stdout = proc.communicate()[0] - proc.wait() - platform = stdout.rstrip('\n') - - proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-d', '-v', HWSKU_KEY], - stdout=subprocess.PIPE, - shell=False, - stderr=subprocess.STDOUT) - stdout = proc.communicate()[0] - proc.wait() - hwsku = stdout.rstrip('\n') - except OSError, e: - raise OSError("Cannot detect platform") - - return (platform, hwsku) - - -# Loads platform specific psuutil module from source -def load_platform_util(): - global platform_psuutil - #gongjian add - global platform_sensorutil - global platform_fanutil - - # Get platform and hwsku - (platform, hwsku) = get_platform_and_hwsku() - - # Load platform module from source - platform_path = '' - if len(platform) != 0: - platform_path = "/".join([PLATFORM_ROOT_PATH, platform]) - else: - platform_path = PLATFORM_ROOT_PATH_DOCKER - hwsku_path = "/".join([platform_path, hwsku]) - - try: - module_file_psu = "/".join([platform_path, "plugins", PLATFORM_PSU_MODULE_NAME + ".py"]) - module_psu = imp.load_source(PLATFORM_PSU_MODULE_NAME, module_file_psu) - except IOError, e: - log_error("Failed to load platform module '%s': %s" % (PLATFORM_PSU_MODULE_NAME, str(e)), True) - return -1 - - try: - platform_psuutil_class = getattr(module_psu, PLATFORM_PSU_CLASS_NAME) - platform_psuutil = platform_psuutil_class() - except AttributeError, e: - log_error("Failed to instantiate '%s' class: %s" % (PLATFORM_PSU_CLASS_NAME, str(e)), True) - return -2 - - - #gongjian add - try: - module_file_sensor = "/".join([platform_path, "plugins", PLATFORM_SENSOR_MODULE_NAME + ".py"]) - module_sensor = imp.load_source(PLATFORM_SENSOR_MODULE_NAME, module_file_sensor) - except IOError, e: - log_error("Failed to load platform module '%s': %s" % (PLATFORM_SENSOR_MODULE_NAME, str(e)), True) - return -1 - - try: - platform_sensorutil_class = getattr(module_sensor, PLATFORM_SENSOR_CLASS_NAME) - platform_sensorutil = platform_sensorutil_class() - except AttributeError, e: - log_error("Failed to instantiate '%s' class: %s" % (PLATFORM_SENSOR_CLASS_NAME, str(e)), True) - return -2 - - try: - module_file_fan = "/".join([platform_path, "plugins", PLATFORM_FAN_MODULE_NAME + ".py"]) - module_fan = imp.load_source(PLATFORM_FAN_MODULE_NAME, module_file_fan) - except IOError, e: - log_error("Failed to load platform module '%s': %s" % (PLATFORM_FAN_MODULE_NAME, str(e)), True) - return -1 - - try: - platform_fanutil_class = getattr(module_fan, PLATFORM_FAN_CLASS_NAME) - platform_fanutil = platform_fanutil_class() - except AttributeError, e: - log_error("Failed to instantiate '%s' class: %s" % (PLATFORM_FAN_CLASS_NAME, str(e)), True) - return -2 - #end gongjian add - return 0 - - -# ==================== CLI commands and groups ==================== - - -# This is our main entrypoint - the main 'psuutil' command -@click.group() -def cli(): - """platformutil - Command line utility for providing platform status""" - - if os.geteuid() != 0: - click.echo("Root privileges are required for this operation") - sys.exit(1) - - # Load platform-specific psuutil, fanutil and sensorutil class - err = load_platform_util() - if err != 0: - sys.exit(2) - -#'fan' subcommand -@cli.group() -@click.pass_context -def fan(ctx): - """fan state""" - ctx.obj = "fan" - -# 'sensor' subcommand -@cli.group() -@click.pass_context -def sensor(ctx): - """sensor state""" - ctx.obj = "sensor" - -# 'psu' subcommand -@cli.group() -@click.pass_context -def psu(ctx): - """psu state""" - ctx.obj = "psu" - -# 'version' subcommand -@cli.command() -def version(): - """Display version info""" - click.echo("platformutil version {0}".format(VERSION)) - - -# 'num' subcommand -@click.command() -@click.pass_context -def num(ctx): - """Display number of supported sensor/fan/psu device""" - if ctx.obj == "psu": - click.echo(str(platform_psuutil.get_num_psus())) - if ctx.obj == "fan": - click.echo(str(len(platform_fanutil.get_fans_name_list()))) - if ctx.obj == "sensor": - click.echo(str(platform_sensorutil.get_num_sensors())) - -psu.add_command(num) -sensor.add_command(num) -fan.add_command(num) - -# 'status' subcommand -#all API should return "N/A" or float("-intf") if not supported -@click.command() -@click.pass_context -def status(ctx): - if ctx.obj == 'psu': - psu_dict = platform_psuutil.get_all() - if psu_dict == None: - print 'Error: psuutil.get_all() failed' - return - - psu_nr = psu_dict.get('Number') - if psu_nr == None: - print 'Error: PSU get all format invalid, prop "Number" missing.' - return - - psu_names = [ k for k in psu_dict.keys() if cmp('Number', k) != 0 ] - psu_names.sort() - header = ['PSU', 'Presence', 'InputStatus', 'InputType', 'OutputStatus', 'PN', 'SN', 'AirFlow'] - status_table = [] - for psu_name in psu_names: - psu = psu_dict[psu_name] - presence = psu.get('Present') - pn = psu.get('PN') - sn = psu.get('SN') - in_status = psu.get('InputStatus') - out_status = psu.get('OutputStatus') - in_type = psu.get('InputType') - airflow = psu.get('AirFlow') - - if presence == None: - print 'Error: PSU get all format invaid, prop "Present" is missing.' - continue - elif presence == False: - presence = 'NOT_PRESENT' - in_status = 'N/A' - out_status = 'N/A' - in_type = 'N/A' - pn = 'N/A' - pn = 'N/A' - else: - presence = 'PRESENT' - if in_status == None: - in_status = 'N/A' - elif in_status == True: - in_status = 'OK' - else: - in_status = 'NOT_OK' - - if in_type == None: - in_type = 'N/A' - - if out_status == None: - out_status = 'N/A' - elif out_status == True: - out_status = 'OK' - else: - out_status = 'NOT_OK' - - if pn == None: - pn = 'N/A' - if sn == None: - sn = 'N/A' - if airflow == None: - airflow = 'N/A' - status_table.append([psu_name, presence, in_status, in_type, out_status, pn, sn, airflow]) - - if len(status_table) != psu_nr: - print 'Error: PSU get all missing some PSU information.' - - if len(status_table) > 0: - click.echo(tabulate(status_table, header, tablefmt='simple')) - - if ctx.obj == 'fan': - fan_dict = platform_fanutil.get_all() - if fan_dict == None: - print 'Error: fanutil.get_all() failed' - return - - fan_nr = fan_dict.get('Number') - if fan_nr == None: - print 'Error: FAN get all format invalid, prop "Number" missing.' - return - - header = [ 'FAN', 'Presence', 'Status', 'Speed', 'LowThd', 'HighThd', 'PN', 'SN', 'AirFlow' ] - status_table = [] - fan_names = [ k for k in fan_dict.keys() if cmp('Number', k) != 0 ] - fan_names.sort() - for fan_name in fan_names: - fan = fan_dict[fan_name] - presence = fan.get('Present') - speed = fan.get('Speed') - low = fan.get('LowThd') - high = fan.get('HighThd') - pn = fan.get('PN') - sn = fan.get('SN') - status = fan.get('Status') - airflow = fan.get('AirFlow') - - if presence == None: - print 'Error: FAN get all format invaid, prop "Present" missing.' - continue - elif presence == False: - presence = 'NOT_PRESENT' - status = 'N/A' - speed = 'N/A' - low = 'N/A' - high = 'N/A' - pn = 'N/A' - sn = 'N/A' - airflow = 'N/A' - else: - presence = 'PRESENT' - if status == None: - status = 'N/A' - elif status == True: - status = 'OK' - else: - status = 'NOT_OK' - if airflow == None: - airflow = 'N/A' - if speed == None: - speed = 'N/A' - if low == None: - low = 'N/A' - if high == None: - high = 'N/A' - if pn == None: - pn = 'N/A' - if sn == None: - sn = 'N/A' - - status_table.append([fan_name, presence, status, speed, low, high, pn, sn, airflow]) - - if len(status_table) != fan_nr: - print 'Error: FAN get all missing some FAN information.' - - if len(status_table) > 0: - click.echo(tabulate(status_table, header, tablefmt='simple')) - - if ctx.obj == 'sensor': - sensor_dict = platform_sensorutil.get_all() - if sensor_dict == None: - print 'Error: sensors.get_all() failed' - return - - header = [ 'Sensor', 'InputName', 'State', 'Value', 'LowThd', 'HighThd' ] - status_table = [] - type2unit = { 'temperature' : ' C', 'voltage' : ' V', 'RPM' : ' RPM', 'amp' : ' A', 'power' : ' W'} - type_keys = type2unit.keys() - for sensor_name, sensor_obj in sensor_dict.items(): - if cmp(sensor_name, 'Number') == 0: - continue - - si_names = [ k for k in sensor_obj.keys() ] - si_names.sort() - for si_name in si_names: - si = sensor_obj[si_name] - if si_name == "Sys_AirFlow": - status = 'OK' - airflow = si - status_table.append([sensor_name, si_name, status, airflow, airflow, airflow]) - continue - - stype = si.get('Type') - sval = si.get('Value') - slow = si.get('LowThd') - shigh = si.get('HighThd') - sunit = ' ' - fault = False - if stype != None: - sunit = type2unit.get(stype) - if sunit == None: - sunit = ' ' - try: - sval = float(sval) - except: - sval = 0.0 - fault = True - - try: - slow = float(slow) - except: - slow = 0.0 - fault = True - - try: - shigh = float(shigh) - except: - shigh = 0.0 - fault = True - - status = 'NOT_OK' - if fault == False and sval > slow and sval < shigh: - status = 'OK' - - status_table.append([sensor_name, si_name, status, (str(sval)+sunit), (str(slow)+sunit), (str(shigh)+sunit)]) - - if len(status_table) > 0: - click.echo(tabulate(status_table, header, tablefmt="simple")) - - return - -psu.add_command(status) -sensor.add_command(status) -fan.add_command(status) - - -if __name__ == '__main__': - cli() diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/power_utils/power b/platform/broadcom/sonic-platform-modules-cel/tools/power_utils/power deleted file mode 100755 index e3d42d5c0353..000000000000 --- a/platform/broadcom/sonic-platform-modules-cel/tools/power_utils/power +++ /dev/null @@ -1,86 +0,0 @@ -#!/bin/bash -# -# Copyright 2019-present Celestica. All Rights Reserved. -# -# This program file is free software; you can redistribute it and/or modify it -# under the terms of the GNU General Public License as published by the -# Free Software Foundation; version 2 of the License. -# -# This program is distributed in the hope that it will be useful, but WITHOUT -# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -# for more details. -# -# - -PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin - -prog="$0" - -if [[ $EUID -ne 0 ]]; then - echo "This script must be run as root" - exit 1 -fi - -usage() { - echo "Usage: power " - echo - echo "Commands:" - echo - echo " cycle cpu: To power cycle the CPU" - echo - echo " cycle system : To reboot the whole system" - echo -} - -cpu_cycle() { - echo "Power cycling CPU..." - curl -m 5 -d '{"data":"/usr/local/bin/wedge_power.sh off;/usr/local/bin/wedge_power.sh on"}' http://240.1.1.1:8080/api/sys/raw - ret=$? - if [ $ret -ne 0 ]; then - echo "Failed to power cycle the CPU" - fi - return 0 -} - -system_cycle() { - echo "Power cycling system..." - curl -m 5 -d '{"data":"/usr/local/bin/wedge_power.sh off;/usr/local/bin/wedge_power.sh on;reboot"}' http://240.1.1.1:8080/api/sys/raw - ret=$? - if [ $ret -ne 0 ]; then - echo "Failed to power cycle the system" - fi - return 0 -} - -if [ $# -lt 1 ]; then - usage - exit -1 -fi - -command="$1" -component="$2" -shift - -case "$command" in -cycle) - case "$component" in - cpu) - cpu_cycle - ;; - system) - system_cycle - ;; - *) - usage - exit -1 - ;; - esac - ;; -*) - usage - exit -1 - ;; -esac - -exit $? diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/read_optic_temp.py b/platform/broadcom/sonic-platform-modules-cel/tools/read_optic_temp.py deleted file mode 100644 index 97e4641066ba..000000000000 --- a/platform/broadcom/sonic-platform-modules-cel/tools/read_optic_temp.py +++ /dev/null @@ -1,189 +0,0 @@ -#!/usr/bin/env python -# -# read_optic_temp.py -# -# Command-line utility for read the temperature of optic modules. -# - -try: - import sys - import os - import subprocess - import click - import imp - import multiprocessing.pool - import threading -except ImportError as e: - raise ImportError("%s - required module not found" % str(e)) - - -PLATFORM_ROOT_PATH = '/usr/share/sonic/device' -SONIC_CFGGEN_PATH = '/usr/local/bin/sonic-cfggen' -HWSKU_KEY = 'DEVICE_METADATA.localhost.hwsku' -PLATFORM_KEY = 'DEVICE_METADATA.localhost.platform' - -PLATFORM_SPECIFIC_SFP_MODULE_NAME = "sfputil" -PLATFORM_SPECIFIC_SFP_CLASS_NAME = "SfpUtil" - -PLATFORM_SPECIFIC_OPTICTEMP_MODULE_NAME = "optictemputil" -PLATFORM_SPECIFIC_OPTICTEMP_CLASS_NAME = "OpticTempUtil" - -# Global platform-specific psuutil class instance -platform_optictemputil = None -platform_sfputil = None - - -# ==================== Methods for initialization ==================== - -# Returns platform and HW SKU -def get_platform_and_hwsku(): - try: - proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-H', '-v', PLATFORM_KEY], - stdout=subprocess.PIPE, - shell=False, - stderr=subprocess.STDOUT) - stdout = proc.communicate()[0] - proc.wait() - platform = stdout.rstrip('\n') - - proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-d', '-v', HWSKU_KEY], - stdout=subprocess.PIPE, - shell=False, - stderr=subprocess.STDOUT) - stdout = proc.communicate()[0] - proc.wait() - hwsku = stdout.rstrip('\n') - except OSError, e: - raise OSError("Cannot detect platform") - - return (platform, hwsku) - - -# Returns path to port config file -def get_path_to_port_config_file(): - # Get platform and hwsku - (platform, hwsku) = get_platform_and_hwsku() - - # Load platform module from source - platform_path = "/".join([PLATFORM_ROOT_PATH, platform]) - hwsku_path = "/".join([platform_path, hwsku]) - - # First check for the presence of the new 'port_config.ini' file - port_config_file_path = "/".join([hwsku_path, "port_config.ini"]) - if not os.path.isfile(port_config_file_path): - # port_config.ini doesn't exist. Try loading the legacy 'portmap.ini' file - port_config_file_path = "/".join([hwsku_path, "portmap.ini"]) - - return port_config_file_path - - -def load_platform_util(module_name, class_name): - - # Get platform and hwsku - (platform, hwsku) = get_platform_and_hwsku() - - # Load platform module from source - platform_path = "/".join([PLATFORM_ROOT_PATH, platform]) - hwsku_path = "/".join([platform_path, hwsku]) - - try: - module_file = "/".join([platform_path, "plugins", module_name + ".py"]) - module = imp.load_source(module_name, module_file) - except IOError, e: - print("Failed to load platform module '%s': %s" % (module_name, str(e))) - sys.exit(1) - - try: - platform_util_class = getattr(module, class_name) - platform_util = platform_util_class() - except AttributeError, e: - print("Failed to instantiate '%s' class: %s" % (class_name, str(e))) - sys.exit(1) - - return platform_util - - -def get_optic_temp(port_list): - temp_list = [] - for idx, port_num in enumerate(port_list[0]): - temp = platform_optictemputil.get_optic_temp( - port_num, port_list[1][idx]) - temp_list.append(round(float(temp), 2)) - return temp_list - - -# ========================= CLI commands ========================= - -# This is our main entrypoint - the main 'opticutil' command -@click.command() -@click.option('--port_num', '-p', type=int, help='Specific port number') -def cli(port_num): - """optictemputil - Command line utility for providing platform status""" - - # Check root privileges - if os.geteuid() != 0: - click.echo("Root privileges are required for this operation") - sys.exit(1) - - global platform_optictemputil - global platform_sfputil - - # Load platform-specific class - platform_sfputil = load_platform_util( - PLATFORM_SPECIFIC_SFP_MODULE_NAME, PLATFORM_SPECIFIC_SFP_CLASS_NAME) - platform_optictemputil = load_platform_util( - PLATFORM_SPECIFIC_OPTICTEMP_MODULE_NAME, PLATFORM_SPECIFIC_OPTICTEMP_CLASS_NAME) - - # Load port config - port_config_file_path = get_path_to_port_config_file() - platform_sfputil.read_porttab_mappings(port_config_file_path) - port_list = platform_sfputil.port_to_i2cbus_mapping - port_eeprom_list = platform_sfputil.port_to_eeprom_mapping - qsfp_port_list = platform_sfputil.qsfp_ports - - port_dict = {} - temp_list = [0] - i2c_block_size = 32 - concurrent = 10 - - port_data_list = [] - port_bus_list = [] - port_type_list = [] - - # Read port temperature - if port_num: - if port_num not in port_list: - click.echo("Invalid port") - sys.exit(1) - port_list = {port_num: port_list.get(port_num)} - - for port_num, bus_num in port_list.items(): - port_type = "QSFP" if port_num in qsfp_port_list else "SFP" - port_bus_list.append(port_eeprom_list[port_num]) - port_type_list.append(port_type) - if len(port_bus_list) >= i2c_block_size: - port_tub = (port_bus_list, port_type_list) - port_data_list.append(port_tub) - port_bus_list = [] - port_type_list = [] - - if port_bus_list != []: - port_tub = (port_bus_list, port_type_list) - port_data_list.append(port_tub) - - pool = multiprocessing.pool.ThreadPool(processes=concurrent) - temp_list = pool.map(get_optic_temp, port_data_list, chunksize=1) - pool.close() - - flat_list = [item for sublist in temp_list for item in sublist] - click.echo("| PORT_NO\t| PORT_TYPE\t| TEMPERATURE\t|") - for port_num, bus_num in port_list.items(): - port_type = "QSFP" if port_num in qsfp_port_list else "SFP" - temp_idx = port_list.keys().index(port_num) - temp = flat_list[temp_idx] - click.echo('| {}\t\t| {}\t\t| {}\t\t|'.format( - port_num, port_type, temp)) - - -if __name__ == '__main__': - cli() diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/bmc_vlan.service b/platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/bmc_vlan.service deleted file mode 100644 index 9aeeead72394..000000000000 --- a/platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/bmc_vlan.service +++ /dev/null @@ -1,12 +0,0 @@ -[Unit] -Description="Service for add vlan for rsyslog" -After=network.target -Before=rsyslog-config.service -Before=ntp.service - -[Service] -Type=forking -ExecStart=/bin/sh /usr/local/etc/bmc_vlan.sh - -[Install] -WantedBy=rsyslog.service \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/bmc_vlan.sh b/platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/bmc_vlan.sh deleted file mode 100644 index 1d439915efb0..000000000000 --- a/platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/bmc_vlan.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -# Add vlan -ip link add link eth0 name eth0.4088 type vlan id 4088 -ip addr add 240.1.1.2/30 dev eth0.4088 -ip link set eth0.4088 up -exit 0 \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/sync_bmc.py b/platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/sync_bmc.py deleted file mode 100644 index 3065e8a21ebf..000000000000 --- a/platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/sync_bmc.py +++ /dev/null @@ -1,203 +0,0 @@ -#!/usr/bin/env python - -############################################################################# -# # -# Platform and model specific service for send data to BMC # -# # -# # -############################################################################# - -import subprocess -import requests -import os -import imp -import multiprocessing.pool -import threading - - -PLATFORM_ROOT_PATH = '/usr/share/sonic/device' -SONIC_CFGGEN_PATH = '/usr/local/bin/sonic-cfggen' -HWSKU_KEY = 'DEVICE_METADATA.localhost.hwsku' -PLATFORM_KEY = 'DEVICE_METADATA.localhost.platform' -TEMP_URL = 'http://240.1.1.1:8080/api/sys/temp' - -PLATFORM_SPECIFIC_SFP_MODULE_NAME = "sfputil" -PLATFORM_SPECIFIC_SFP_CLASS_NAME = "SfpUtil" - -PLATFORM_SPECIFIC_OPTICTEMP_MODULE_NAME = "optictemputil" -PLATFORM_SPECIFIC_OPTICTEMP_CLASS_NAME = "OpticTempUtil" - -PLATFORM_SPECIFIC_CPUTEMP_MODULE_NAME = "cputemputil" -PLATFORM_SPECIFIC_CPUTEMP_CLASS_NAME = "CpuTempUtil" - -platform_sfputil = None -platform_optictemputil = None -platform_cputemputil = None - - -# Returns platform and HW SKU -def get_platform_and_hwsku(): - try: - proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-H', '-v', PLATFORM_KEY], - stdout=subprocess.PIPE, - shell=False, - stderr=subprocess.STDOUT) - stdout = proc.communicate()[0] - proc.wait() - platform = stdout.rstrip('\n') - - proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-d', '-v', HWSKU_KEY], - stdout=subprocess.PIPE, - shell=False, - stderr=subprocess.STDOUT) - stdout = proc.communicate()[0] - proc.wait() - hwsku = stdout.rstrip('\n') - except OSError, e: - raise OSError("Cannot detect platform") - - return (platform, hwsku) - - -# Returns path to port config file -def get_path_to_port_config_file(): - # Get platform and hwsku - (platform, hwsku) = get_platform_and_hwsku() - - # Load platform module from source - platform_path = "/".join([PLATFORM_ROOT_PATH, platform]) - hwsku_path = "/".join([platform_path, hwsku]) - - # First check for the presence of the new 'port_config.ini' file - port_config_file_path = "/".join([hwsku_path, "port_config.ini"]) - if not os.path.isfile(port_config_file_path): - # port_config.ini doesn't exist. Try loading the legacy 'portmap.ini' file - port_config_file_path = "/".join([hwsku_path, "portmap.ini"]) - - return port_config_file_path - - -def load_platform_util(module_name, class_name): - - # Get platform and hwsku - (platform, hwsku) = get_platform_and_hwsku() - - # Load platform module from source - platform_path = "/".join([PLATFORM_ROOT_PATH, platform]) - hwsku_path = "/".join([platform_path, hwsku]) - - try: - module_file = "/".join([platform_path, "plugins", module_name + ".py"]) - module = imp.load_source(module_name, module_file) - except IOError, e: - print("Failed to load platform module '%s': %s" % ( - module_name, str(e)), True) - return -1 - - try: - platform_util_class = getattr(module, class_name) - platform_util = platform_util_class() - except AttributeError, e: - print("Failed to instantiate '%s' class: %s" % - (class_name, str(e)), True) - return -2 - - return platform_util - - -def get_optic_temp(port_list): - temp_list = [] - for idx, port_eeprom in enumerate(port_list[0]): - temp = platform_optictemputil.get_optic_temp( - port_eeprom, port_list[1][idx]) if port_list[2][idx] else 0 - temp_list.append(round(float(temp), 2)) - return max(temp_list) - - -def get_max_optic_temp(): - port_config_file_path = get_path_to_port_config_file() - platform_sfputil.read_porttab_mappings(port_config_file_path) - port_list = platform_sfputil.port_to_i2cbus_mapping - port_eeprom_list = platform_sfputil.port_to_eeprom_mapping - qsfp_port_list = platform_sfputil.qsfp_ports - - port_data_list = [] - temp_list = [0] - i2c_block_size = 32 - concurrent = 10 - - port_bus_list = [] - port_type_list = [] - port_presence_list = [] - - for port_num, bus_num in port_list.items(): - port_type = "QSFP" if port_num in qsfp_port_list else "SFP" - port_bus_list.append(port_eeprom_list[port_num]) - port_type_list.append(port_type) - status = platform_sfputil.get_presence(port_num) - port_presence_list.append(status) - if len(port_bus_list) >= i2c_block_size: - port_tub = (port_bus_list, port_type_list, port_presence_list) - port_data_list.append(port_tub) - port_bus_list = [] - port_type_list = [] - port_presence_list = [] - - if port_bus_list != []: - port_tub = (port_bus_list, port_type_list, port_presence_list) - port_data_list.append(port_tub) - - pool = multiprocessing.pool.ThreadPool(processes=concurrent) - temp_list = pool.map(get_optic_temp, port_data_list, chunksize=1) - pool.close() - return max(temp_list) - - -# Send CPU temperature to BMC. -def send_cpu_temp(): - max_cpu_tmp = platform_cputemputil.get_max_cpu_tmp() - json_input = { - "chip": "cpu", - "option": "input", - "value": str(int(max_cpu_tmp)) - } - print "send ", json_input - requests.post(TEMP_URL, json=json_input) - - -# Send maximum optic module temperature to BMC. -def send_optic_temp(): - max_optic_temp = get_max_optic_temp() - json_input = { - "chip": "optical", - "option": "input", - "value": str(int(max_optic_temp)) - } - print "send ", json_input - requests.post(TEMP_URL, json=json_input) - - -def main(): - global platform_sfputil - global platform_cputemputil - global platform_optictemputil - - try: - platform_sfputil = load_platform_util( - PLATFORM_SPECIFIC_SFP_MODULE_NAME, PLATFORM_SPECIFIC_SFP_CLASS_NAME) - platform_cputemputil = load_platform_util( - PLATFORM_SPECIFIC_CPUTEMP_MODULE_NAME, PLATFORM_SPECIFIC_CPUTEMP_CLASS_NAME) - platform_optictemputil = load_platform_util( - PLATFORM_SPECIFIC_OPTICTEMP_MODULE_NAME, PLATFORM_SPECIFIC_OPTICTEMP_CLASS_NAME) - - t1 = threading.Thread(target=send_cpu_temp) - t2 = threading.Thread(target=send_optic_temp) - t1.start() - t2.start() - except Exception, e: - print e - pass - - -if __name__ == "__main__": - main() diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/sync_bmc.service b/platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/sync_bmc.service deleted file mode 100644 index 334485342510..000000000000 --- a/platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/sync_bmc.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Service for send sensor data value to BMC. -After=multi-user.target - -[Service] -Type=idle -ExecStart=/usr/bin/python /usr/local/etc/sync_bmc.py - -[Install] -WantedBy=multi-user.target \ No newline at end of file diff --git a/platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/sync_bmc.timer b/platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/sync_bmc.timer deleted file mode 100644 index 71666cc99887..000000000000 --- a/platform/broadcom/sonic-platform-modules-cel/tools/sync_bmc/sync_bmc.timer +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Timer send sensor data value to BMC. - -[Timer] -OnUnitActiveSec=5s -OnBootSec=5s -AccuracySec=1us - -[Install] -WantedBy=timers.target \ No newline at end of file