2019-09-06 09:52:45 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
#
|
|
|
|
# Name: chassis.py, version: 1.0
|
|
|
|
#
|
|
|
|
# Description: Module contains the definitions of SONiC platform APIs
|
|
|
|
# which provide the chassis specific details
|
|
|
|
#
|
2020-04-21 04:25:51 -05:00
|
|
|
# Copyright (c) 2020, Juniper Networks, Inc.
|
2019-09-06 09:52:45 -05:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# Notice and Disclaimer: This code is licensed to you under the GNU General
|
|
|
|
# Public License as published by the Free Software Foundation, version 3 or
|
|
|
|
# any later version. This code is not an official Juniper product. You can
|
|
|
|
# obtain a copy of the License at <https://www.gnu.org/licenses/>
|
|
|
|
#
|
|
|
|
# OSS License:
|
|
|
|
#
|
|
|
|
# This program 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, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
# Third-Party Code: This code may depend on other components under separate
|
|
|
|
# copyright notice and license terms. Your use of the source code for those
|
|
|
|
# components is subject to the terms and conditions of the respective license
|
|
|
|
# as noted in the Third-Party source code file.
|
|
|
|
#
|
|
|
|
|
|
|
|
try:
|
|
|
|
import os
|
|
|
|
import commands
|
|
|
|
import sys
|
|
|
|
import time
|
2020-04-21 04:25:51 -05:00
|
|
|
import syslog
|
2019-09-06 09:52:45 -05:00
|
|
|
from sonic_platform_base.chassis_base import ChassisBase
|
|
|
|
except ImportError as e:
|
|
|
|
raise ImportError(str(e) + "- required module not found")
|
|
|
|
|
2020-04-21 04:25:51 -05:00
|
|
|
SYSLOG_IDENTIFIER = "Juniper-Chassis"
|
2019-09-06 09:52:45 -05:00
|
|
|
|
2020-04-21 04:25:51 -05:00
|
|
|
def log_info(msg):
|
|
|
|
syslog.openlog(SYSLOG_IDENTIFIER)
|
|
|
|
syslog.syslog(syslog.LOG_INFO, msg)
|
|
|
|
syslog.closelog()
|
2019-09-06 09:52:45 -05:00
|
|
|
|
2020-04-21 04:25:51 -05:00
|
|
|
class Chassis(ChassisBase):
|
2019-09-06 09:52:45 -05:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
ChassisBase.__init__(self)
|
|
|
|
|
2020-04-21 04:25:51 -05:00
|
|
|
def get_parameter_value(self,parameter_name):
|
2019-09-06 09:52:45 -05:00
|
|
|
try:
|
2019-10-19 22:46:32 -05:00
|
|
|
with open("/var/run/eeprom", "r") as file:
|
2019-09-06 09:52:45 -05:00
|
|
|
for item in file:
|
|
|
|
content = item.split('=')
|
|
|
|
if content[0] == parameter_name:
|
|
|
|
return content[1:]
|
|
|
|
return "False"
|
|
|
|
except IOError:
|
|
|
|
print "Error: File not found"
|
|
|
|
return "False"
|
|
|
|
|
|
|
|
def get_product_name(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
product_name_list = self.get_parameter_value('Product Name')
|
2019-09-06 09:52:45 -05:00
|
|
|
if product_name_list:
|
|
|
|
product_name = ''.join(product_name_list)
|
|
|
|
return product_name
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2019-10-19 22:46:32 -05:00
|
|
|
|
2019-09-06 09:52:45 -05:00
|
|
|
def get_part_number(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
part_number_list = self.get_parameter_value('Part Number')
|
2019-09-06 09:52:45 -05:00
|
|
|
if part_number_list:
|
|
|
|
part_number = ''.join(part_number_list)
|
|
|
|
return part_number
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2019-10-19 22:46:32 -05:00
|
|
|
|
2020-10-18 00:00:14 -05:00
|
|
|
def get_serial(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
serial_number_list = self.get_parameter_value('Serial Number')
|
2019-09-06 09:52:45 -05:00
|
|
|
if serial_number_list:
|
|
|
|
serial_number = ''.join(serial_number_list)
|
|
|
|
return serial_number
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2019-10-19 22:46:32 -05:00
|
|
|
|
2019-09-06 09:52:45 -05:00
|
|
|
def get_base_mac(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
mac_list = self.get_parameter_value('MAC')
|
2019-09-06 09:52:45 -05:00
|
|
|
if mac_list:
|
|
|
|
mac = ''.join(mac_list)
|
|
|
|
return mac
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2019-10-19 22:46:32 -05:00
|
|
|
|
|
|
|
def get_mfg_date(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
mfgdate_list = self.get_parameter_value('Manufacture Date')
|
2019-10-19 22:46:32 -05:00
|
|
|
if mfgdate_list:
|
|
|
|
mfgdate = ''.join(mfgdate_list)
|
|
|
|
return mfgdate
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_deviceversion_name(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
device_version_list = self.get_parameter_value('Device Version')
|
2019-10-19 22:46:32 -05:00
|
|
|
if device_version_list:
|
|
|
|
deviceversion_name = ''.join(device_version_list)
|
|
|
|
return deviceversion_name
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2019-09-06 09:52:45 -05:00
|
|
|
def get_platform_name(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
platform_name_list = self.get_parameter_value('Platform Name')
|
2019-09-06 09:52:45 -05:00
|
|
|
if platform_name_list:
|
|
|
|
platform_name = ''.join(platform_name_list)
|
|
|
|
return platform_name
|
|
|
|
else:
|
|
|
|
return False
|
2019-10-19 22:46:32 -05:00
|
|
|
|
|
|
|
def get_MACnumber_name(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
MACnumber_name_list = self.get_parameter_value('Number of MAC Addresses')
|
2019-10-19 22:46:32 -05:00
|
|
|
if MACnumber_name_list:
|
|
|
|
MACnumber_name = ''.join(MACnumber_name_list)
|
|
|
|
return MACnumber_name
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_vendor_name(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
vendor_name_list = self.get_parameter_value('Vendor Name')
|
2019-10-19 22:46:32 -05:00
|
|
|
if vendor_name_list:
|
|
|
|
vendor_name = ''.join(vendor_name_list)
|
|
|
|
return vendor_name
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_mfg_name(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
mfg_name_list = self.get_parameter_value('Manufacture Name')
|
2019-10-19 22:46:32 -05:00
|
|
|
if mfg_name_list:
|
|
|
|
mfg_name = ''.join(mfg_name_list)
|
|
|
|
return mfg_name
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_vendorext_name(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
vendorext_list = self.get_parameter_value('Vendor Extension')
|
2019-10-19 22:46:32 -05:00
|
|
|
if vendorext_list:
|
|
|
|
vendorext = ''.join(vendorext_list)
|
|
|
|
return vendorext
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_vendorextIANA_name(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
vendorext_list = self.get_parameter_value('IANA')
|
2019-10-19 22:46:32 -05:00
|
|
|
if vendorext_list:
|
|
|
|
vendorext = ''.join(vendorext_list)
|
|
|
|
return vendorext
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_vendorextASMREV_name(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
vendorext_list = self.get_parameter_value('Assembly Part Number Rev')
|
2019-10-19 22:46:32 -05:00
|
|
|
if vendorext_list:
|
|
|
|
vendorext = ''.join(vendorext_list)
|
|
|
|
return vendorext
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_vendorextASMPartNum_name(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
vendorext_list = self.get_parameter_value('Assembly Part Number')
|
2019-10-19 22:46:32 -05:00
|
|
|
if vendorext_list:
|
|
|
|
vendorext = ''.join(vendorext_list)
|
|
|
|
return vendorext
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_vendorextASMID_name(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
vendorext_list = self.get_parameter_value('Assembly ID')
|
2019-10-19 22:46:32 -05:00
|
|
|
if vendorext_list:
|
|
|
|
vendorext = ''.join(vendorext_list)
|
|
|
|
return vendorext
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_vendorextASMMajNum_name(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
vendorext_list = self.get_parameter_value('Assembly Major Revision')
|
2019-10-19 22:46:32 -05:00
|
|
|
if vendorext_list:
|
|
|
|
vendorext = ''.join(vendorext_list)
|
|
|
|
return vendorext
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_vendorextASMMinNum_name(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
vendorext_list = self.get_parameter_value('Assembly Minor Revision')
|
2019-10-19 22:46:32 -05:00
|
|
|
if vendorext_list:
|
|
|
|
vendorext = ''.join(vendorext_list)
|
|
|
|
return vendorext
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_vendorextCLEI_name(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
vendorext_list = self.get_parameter_value('CLEI code')
|
2019-10-19 22:46:32 -05:00
|
|
|
if vendorext_list:
|
|
|
|
vendorext = ''.join(vendorext_list)
|
|
|
|
return vendorext
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_onieversion_name(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
onieversion_name_list = self.get_parameter_value('ONIE Version')
|
2019-10-19 22:46:32 -05:00
|
|
|
if onieversion_name_list:
|
|
|
|
onieversion_name = ''.join(onieversion_name_list)
|
|
|
|
return onieversion_name
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
|
|
|
def get_crc_name(self):
|
2020-04-21 04:25:51 -05:00
|
|
|
crc_list = self.get_parameter_value('CRC')
|
2019-10-19 22:46:32 -05:00
|
|
|
if crc_list:
|
|
|
|
crc_name = ''.join(crc_list)
|
|
|
|
return crc_name
|
|
|
|
else:
|
|
|
|
return False
|
2019-09-06 09:52:45 -05:00
|
|
|
|
|
|
|
def get_reboot_cause(self):
|
|
|
|
"""
|
|
|
|
Retrieves the cause of the previous reboot
|
|
|
|
"""
|
2020-04-21 04:25:51 -05:00
|
|
|
platform_name = self.get_platform_name()
|
|
|
|
platform_name = platform_name.replace("\r","")
|
|
|
|
platform_name = platform_name.replace("\n","")
|
|
|
|
log_info("Juniper Platform name: {} and {}".format(self.get_platform_name(), platform_name))
|
|
|
|
if str(platform_name) == "x86_64-juniper_networks_qfx5210-r0":
|
|
|
|
log_info("Juniper Platform QFX5210 ")
|
|
|
|
status, last_reboot_reason = commands.getstatusoutput("i2cget -f -y 0 0x65 0x24")
|
|
|
|
if (status == 0):
|
|
|
|
if last_reboot_reason == "0x80":
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_NON_HARDWARE, None)
|
|
|
|
elif last_reboot_reason == "0x40" or last_reboot_reason == "0x08":
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_WATCHDOG, None)
|
|
|
|
elif last_reboot_reason == "0x20":
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_POWER_LOSS, None)
|
|
|
|
elif last_reboot_reason == "0x10":
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Swizzle Reset")
|
|
|
|
else:
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Unknown reason")
|
2019-09-06 09:52:45 -05:00
|
|
|
else:
|
2020-04-21 04:25:51 -05:00
|
|
|
time.sleep(3)
|
|
|
|
status, last_reboot_reason = commands.getstatusoutput("i2cget -f -y 0 0x65 0x24")
|
|
|
|
if last_reboot_reason == "0x80":
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_NON_HARDWARE, None)
|
|
|
|
elif last_reboot_reason == "0x40" or last_reboot_reason == "0x08":
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_WATCHDOG, None)
|
|
|
|
elif last_reboot_reason == "0x20":
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_POWER_LOSS, None)
|
|
|
|
elif last_reboot_reason == "0x10":
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Swizzle Reset")
|
|
|
|
else:
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Unknown reason")
|
|
|
|
|
|
|
|
elif str(platform_name) == "x86_64-juniper_networks_qfx5200-r0" :
|
|
|
|
log_info("Juniper Platform QFX5200 ")
|
|
|
|
status, last_reboot_reason = commands.getstatusoutput("busybox devmem 0xFED50004 8")
|
|
|
|
if (status == 0):
|
|
|
|
if last_reboot_reason == "0x80":
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_NON_HARDWARE, None)
|
|
|
|
elif last_reboot_reason == "0x40" or last_reboot_reason == "0x08":
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_WATCHDOG, None)
|
|
|
|
elif last_reboot_reason == "0x20":
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_POWER_LOSS, None)
|
|
|
|
elif last_reboot_reason == "0x10":
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Swizzle Reset")
|
|
|
|
else:
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Unknown reason")
|
|
|
|
else:
|
|
|
|
time.sleep(3)
|
|
|
|
status, last_reboot_reason = commands.getstatusoutput("busybox devmem 0xFED50004 8")
|
|
|
|
if last_reboot_reason == "0x80":
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_NON_HARDWARE, None)
|
|
|
|
elif last_reboot_reason == "0x40" or last_reboot_reason == "0x08":
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_WATCHDOG, None)
|
|
|
|
elif last_reboot_reason == "0x20":
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_POWER_LOSS, None)
|
|
|
|
elif last_reboot_reason == "0x10":
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Swizzle Reset")
|
|
|
|
else:
|
|
|
|
return (ChassisBase.REBOOT_CAUSE_HARDWARE_OTHER, "Unknown reason")
|
2019-09-06 09:52:45 -05:00
|
|
|
else:
|
2020-04-21 04:25:51 -05:00
|
|
|
log_info("Juniper QFX5200 and QFX5210 platforms are supported")
|