def __init__(self): ChassisBase.__init__(self) if os.path.isdir(CONTAINER_PLATFORM_PATH): platform_path = CONTAINER_PLATFORM_PATH else: platform = device_info.get_platform() if platform is None: raise platform_path = os.path.join(HOST_DEVICE_PATH, platform) port_config_file = "/".join( [platform_path, "V682-48y8c-d", "port_config.ini"]) try: f = open(port_config_file) except: raise for line in f: line.strip() if re.search('^#', line) is not None: Port_cfg = collections.namedtuple('Port_cfg', line.split()[1:]) break f.close() f = open(port_config_file) _port_cfgs = [ Port_cfg(*tuple((line.strip().split()))) for line in f if re.search('^#', line) is None ] f.close() # Initialize SFP for port_cfg in _port_cfgs: sfp = Sfp(int(port_cfg.index)) self._sfp_list.append(sfp)
def version(verbose): """Show version information""" version_info = device_info.get_sonic_version_info() platform = device_info.get_platform() hwsku = device_info.get_hwsku() asic_type = version_info['asic_type'] asic_count = multi_asic.get_num_asics() serial_number_cmd = "sudo decode-syseeprom -s" serial_number = subprocess.Popen(serial_number_cmd, shell=True, text=True, stdout=subprocess.PIPE) sys_uptime_cmd = "uptime" sys_uptime = subprocess.Popen(sys_uptime_cmd, shell=True, text=True, stdout=subprocess.PIPE) click.echo("\nSONiC Software Version: SONiC.{}".format(version_info['build_version'])) click.echo("Distribution: Debian {}".format(version_info['debian_version'])) click.echo("Kernel: {}".format(version_info['kernel_version'])) click.echo("Build commit: {}".format(version_info['commit_id'])) click.echo("Build date: {}".format(version_info['build_date'])) click.echo("Built by: {}".format(version_info['built_by'])) click.echo("\nPlatform: {}".format(platform)) click.echo("HwSKU: {}".format(hwsku)) click.echo("ASIC: {}".format(asic_type)) click.echo("ASIC Count: {}".format(asic_count)) click.echo("Serial Number: {}".format(serial_number.stdout.read().strip())) click.echo("Uptime: {}".format(sys_uptime.stdout.read().strip())) click.echo("\nDocker images:") cmd = 'sudo docker images --format "table {{.Repository}}\\t{{.Tag}}\\t{{.ID}}\\t{{.Size}}"' p = subprocess.Popen(cmd, shell=True, text=True, stdout=subprocess.PIPE) click.echo(p.stdout.read())
def verify_image_platform(self, image_path): if not os.path.isfile(image_path): return False # Get running platform platform = device_info.get_platform() # If .platforms_asic is not existed, unzip will return code 11. # Return True for backward compatibility. # Otherwise, we grep to see if current platform is inside the # supported target platforms list. with open(os.devnull, 'w') as fnull: p1 = subprocess.Popen( ['/usr/bin/unzip', '-qop', image_path, '.platforms_asic'], stdout=subprocess.PIPE, stderr=fnull, preexec_fn=default_sigpipe) p2 = subprocess.Popen(['grep', '-Fxq', '-m 1', platform], stdin=p1.stdout, preexec_fn=default_sigpipe) p1.wait() if p1.returncode == UNZIP_MISSING_FILE: return True # Code 0 is returned by grep as a result of found p2.wait() return p2.returncode == 0
def __init__(self): ChassisBase.__init__(self) self.data = {'valid': 0, 'last': 0} self.sfp_presence = {} if os.path.isdir(CONTAINER_PLATFORM_PATH): platform_path = CONTAINER_PLATFORM_PATH else: platform = device_info.get_platform() if platform is None: raise platform_path = os.path.join(HOST_DEVICE_PATH, platform) port_config_file = "/".join( [platform_path, "V682-48y8c", "port_config.ini"]) try: f = open(port_config_file) except: raise for line in f: line.strip() if re.search('^#', line) is not None: Port_cfg = collections.namedtuple('Port_cfg', line.split()[1:]) break f.close() f = open(port_config_file) _port_cfgs = [ Port_cfg(*tuple((line.strip().split()))) for line in f if re.search('^#', line) is None ] f.close() # Initialize EEPROM self._eeprom = Eeprom() # Initialize FAN for i in range(NUM_FAN_TRAY): fandrawer = FanDrawer(i + 1) self._fan_drawer_list.append(fandrawer) self._fan_list.extend(fandrawer._fan_list) # Initialize PSU for index in range(0, NUM_PSU): psu = Psu(index + 1) self._psu_list.append(psu) # Initialize THERMAL for index in range(0, NUM_THERMAL): thermal = Thermal(index) self._thermal_list.append(thermal) # Initialize SFP for port_cfg in _port_cfgs: sfp = Sfp(int(port_cfg.index), 'SFP' if int(port_cfg.index) < 48 else 'QSFP') self._sfp_list.append(sfp) self.sfp_presence[int(port_cfg.index)] = False
def verify_image_platform(self, image_path): if not os.path.isfile(image_path): return False # Get running platform platform = device_info.get_platform() # Check if platform is inside image's target platforms return self.platform_in_platforms_asic(platform, image_path)
def __get_platform_components_path(self, root_path): if "{}".format(root_path).startswith(FWUPDATE_FWPACKAGE_DIR): self.PLATFORM_COMPONENTS_FILE_PATH = os.path.join( root_path, PLATFORM_COMPONENTS_FILE) else: self.PLATFORM_COMPONENTS_FILE_PATH = self.PLATFORM_COMPONENTS_PATH_TEMPLATE.format( root_path, device_info.get_platform(), PLATFORM_COMPONENTS_FILE) return self.PLATFORM_COMPONENTS_FILE_PATH
def __init__(self, name, path, cpld_root, ro): if os.path.isdir(CONTAINER_PLATFORM_PATH): platform_path = CONTAINER_PLATFORM_PATH else: platform = device_info.get_platform() if platform is None: raise platform_path = os.path.join(HOST_DEVICE_PATH, platform) self.eeprom_path = platform_path + '/eeprom_file' super(board, self).__init__(self.eeprom_path, 0, '', True)
def get_speed_tolerance(self): """ Retrieves the speed tolerance of the fan Returns: An integer, the percentage of variance from target speed which is considered tolerable """ if device_info.get_platform() in [ "x86_64-accton_as9516_32d-r0", "x86_64-accton_as9516bf_32d-r0" ]: return 6 return 3
def fan_drawer_list_get(): platform = device_info.get_platform() if platform in ["x86_64-accton_as9516_32d-r0", "x86_64-accton_as9516bf_32d-r0"]: max_fantray = 1 max_fan = 6 elif platform == "x86_64-accton_wedge100bf_65x-r0": max_fantray = 2 max_fan = 5 else: max_fantray = 1 max_fan = 5 return [FanDrawer(i, max_fan) for i in range(1, max_fantray + 1)]
def __init__(self): PlatformBase.__init__(self) self._chassis = Chassis() self._chassis.initialize_eeprom() platform_name = get_platform() if "simx" not in platform_name: self._chassis.initialize_psu() if utils.is_host(): self._chassis.initialize_components() self._chassis.initizalize_system_led() else: self._chassis.initialize_fan() self._chassis.initialize_thermals()
def get_hw_info_dict(): """ This function is used to get the HW info helper function """ hw_info_dict = {} version_info = device_info.get_sonic_version_info() hw_info_dict['platform'] = device_info.get_platform() hw_info_dict['hwsku'] = device_info.get_hwsku() hw_info_dict['asic_type'] = version_info['asic_type'] hw_info_dict['asic_count'] = multi_asic.get_num_asics() return hw_info_dict
def __init__(self): """ Constructor. Initialize all configuration entry to default value in case there is no configuration file. """ self.platform_name = device_info.get_platform() self._config_file = os.path.join('/usr/share/sonic/device/', self.platform_name, Config.CONFIG_FILE) self._last_mtime = None self.config_data = None self.interval = Config.DEFAULT_INTERVAL self.ignore_services = None self.ignore_devices = None self.user_defined_checkers = None
def __init__(self): if os.path.isdir(CONTAINER_PLATFORM_PATH): platform_path = CONTAINER_PLATFORM_PATH else: platform = device_info.get_platform() if platform is None: raise platform_path = os.path.join(HOST_DEVICE_PATH, platform) self.__eeprom_path = platform_path + '/eeprom_file' super(Eeprom, self).__init__(self.__eeprom_path, 0, '', True) self.__eeprom_tlv_dict = dict() try: self.open_eeprom() self.__eeprom_data = self.read_eeprom() except: self.__eeprom_data = "N/A" raise RuntimeError("Eeprom is not Programmed") else: eeprom = self.__eeprom_data if not self.is_valid_tlvinfo_header(eeprom): return total_length = (eeprom[9] << 8) | eeprom[10] tlv_index = self._TLV_INFO_HDR_LEN tlv_end = self._TLV_INFO_HDR_LEN + total_length while (tlv_index + 2) < len(eeprom) and tlv_index < tlv_end: if not self.is_valid_tlv(eeprom[tlv_index:]): break tlv = eeprom[tlv_index:tlv_index + 2 + eeprom[tlv_index + 1]] code = "0x%02X" % (tlv[0]) if tlv[0] == self._TLV_CODE_VENDOR_EXT: value = str((tlv[2] << 24) | (tlv[3] << 16) | (tlv[4] << 8) | tlv[5]) value += str(tlv[6:6 + tlv[1]]) else: name, value = self.decoder(None, tlv) self.__eeprom_tlv_dict[code] = value if eeprom[tlv_index] == self._TLV_CODE_CRC_32: break tlv_index += eeprom[tlv_index + 1] + 2
def __init__(self): super(Chassis, self).__init__() self.name = "Undefined" self.model = "Undefined" # Initialize Platform name self.platform_name = device_info.get_platform() # move the initialization of each components to their dedicated initializer # which will be called from platform self.sfp_module_initialized = False self.sfp_event_initialized = False self.reboot_cause_initialized = False logger.log_info("Chassis loaded successfully")
def __update_port_info(self): def qsfp_max_port_get(client): return client.pltfm_mgr.pltfm_mgr_qsfp_get_max_port() if self.QSFP_PORT_END == 0: platform = device_info.get_platform() self.QSFP_PORT_END = thrift_try(qsfp_max_port_get) exclude_cpu_port = [ "x86_64-accton_as9516_32d-r0", "x86_64-accton_as9516bf_32d-r0", "x86_64-accton_wedge100bf_32x-r0" ] if platform in exclude_cpu_port: self.QSFP_PORT_END -= 1 self.PORT_END = self.QSFP_PORT_END self.PORTS_IN_BLOCK = self.QSFP_PORT_END
def __init__(self, index): self._index = index if os.path.isdir(CONTAINER_PLATFORM_PATH): platform_path = CONTAINER_PLATFORM_PATH else: platform = device_info.get_platform() if platform is None: return platform_path = os.path.join(HOST_DEVICE_PATH, platform) module_file = "/".join([platform_path, "plugins", "sfputil.py"]) module = imp.load_source("sfputil", module_file) sfp_util_class = getattr(module, "SfpUtil") self._sfputil = sfp_util_class()
def __init__(self): super(Chassis, self).__init__() self.name = "Undefined" self.model = "Undefined" # Initialize Platform name self.platform_name = device_info.get_platform() # Initialize DMI data self.dmi_data = None # move the initialization of each components to their dedicated initializer # which will be called from platform # # Multiple scenarios need to be taken into consideration regarding the SFP modules initialization. # - Platform daemons # - Can access multiple or all SFP modules # - sfputil # - Sometimes can access only one SFP module # - Call get_sfp to get one SFP module object # # We should initialize all SFP modules only if it is necessary because initializing SFP module is time-consuming. # This means, # - If get_sfp is called, # - If the _sfp_list isn't initialized, initialize it first. # - Only the SFP module being required should be initialized. # - If get_all_sfps is called, # - If the _sfp_list isn't initialized, initialize it first. # - All SFP modules need to be initialized. # But the SFP modules that have already been initialized should not be initialized for the second time. # This can caused by get_sfp being called before. # # Due to the complexity of SFP modules initialization, we have to introduce two initialized flags for SFP modules # - sfp_module_partial_initialized: # - False: The _sfp_list is [] (SFP stuff has never been accessed) # - True: The _sfp_list is a list whose length is number of SFP modules supported by the platform # - sfp_module_full_initialized: # - False: All SFP modules have not been created # - True: All SFP modules have been created # self.sfp_module_partial_initialized = False self.sfp_module_full_initialized = False self.sfp_event_initialized = False self.reboot_cause_initialized = False self.sdk_handle = None self.deinitialize_sdk_handle = None logger.log_info("Chassis loaded successfully")
def get_chassis_local_interfaces(): lst = [] platform = device_info.get_platform() chassisdb_conf = os.path.join('/usr/share/sonic/device/', platform, "chassisdb.conf") if os.path.exists(chassisdb_conf): lines = [] with open(chassisdb_conf, 'r') as f: lines = f.readlines() for line in lines: line = line.strip() if "chassis_internal_intfs" in line: data = line.split("=") lst = data[1].split(",") return lst return lst
def __init__(self): super(Chassis, self).__init__() # Initialize SKU name and Platform name self.sku_name = self._get_sku_name() self.platform_name = self._get_platform_name() mi = device_info.get_machine_info() if mi is not None: self.name = mi['onie_platform'] self.platform_name = device_info.get_platform() else: self.name = self.sku_name self.platform_name = self._get_platform_name() # move the initialization of each components to their dedicated initializer # which will be called from platform self.sfp_module_initialized = False self.sfp_event_initialized = False self.reboot_cause_initialized = False logger.log_info("Chassis loaded successfully")
def test_get_platform(self): with mock.patch("sonic_py_common.device_info.get_machine_info") as get_machine_info_mocked: get_machine_info_mocked.return_value = EXPECTED_GET_MACHINE_INFO_RESULT result = device_info.get_platform() assert result == "x86_64-mlnx_msn2700-r0"
def __get_platform_components_path(self, root_path): return self.PLATFORM_COMPONENTS_PATH_TEMPLATE.format( root_path, device_info.get_platform(), self.PLATFORM_COMPONENTS_FILE)
def get_platform_name(cls): return device_info.get_platform()
def get_platform_name(cls): from sonic_py_common import device_info return device_info.get_platform()
def __init__(self): self.platform = device_info.get_platform()
def __init__(self): self.mac_to_led = { 32: 0, 33: 1, 34: 2, 35: 3, 0: 4, 4: 5, 8: 6, 12: 7, 16: 8, 20: 9, 24: 10, 28: 11, 40: 12, 44: 13, 48: 14, 52: 15, 56: 16, 60: 17, 64: 18, 68: 19, 72: 20, 73: 21, 74: 22, 75: 23, 232: 24, 233: 25, 234: 26, 235: 27, 200: 28, 204: 29, 208: 30, 212: 31, 216: 32, 220: 33, 224: 34, 228: 35, 160: 36, 164: 37, 168: 38, 172: 39, 176: 40, 180: 41, 184: 42, 188: 43, 192: 44, 193: 45, 194: 46, 195: 47, 120: 48, 121: -1, 122: -1, 123: -1, 124: 49, 125: -1, 126: -1, 127: -1, 80: 50, 81: -1, 82: -1, 83: -1, 84: 51, 85: -1, 86: -1, 87: -1, 240: 52, 241: -1, 242: -1, 243: -1, 244: 53, 245: -1, 246: -1, 247: -1, 280: 54, 281: -1, 282: -1, 283: -1, 284: 55, 285: -1, 286: -1, 287: -1, } if os.path.isdir(CONTAINER_PLATFORM_PATH): platform_path = CONTAINER_PLATFORM_PATH else: platform = device_info.get_platform() if platform is None: raise platform_path = os.path.join(HOST_DEVICE_PATH, platform) port_config_file = "/".join( [platform_path, "V682-48x8c", "port_config.ini"]) try: f = open(port_config_file) except: raise for line in f: line.strip() if re.search('^#', line) is not None: Port_cfg = collections.namedtuple('Port_cfg', line.split()[1:]) break f.close() f = open(port_config_file) self._port_cfgs = [ Port_cfg(*tuple((line.strip().split()))) for line in f if re.search('^#', line) is None ] f.close() self.LED_MODE_UP = [5, 5] self.LED_MODE_DOWN = [7, 7] self.f_led = "/sys/class/leds/{}/brightness" self._initDefaultConfig()
def __init__(self): self.mac_to_led = { 0: 1, 1: 2, 2: 3, 3: 4, 8: 5, 9: 6, 10: 7, 11: 8, 20: 9, 21: 10, 22: 11, 23: 12, 12: 13, 13: 14, 14: 15, 15: 16, 24: 17, 25: 18, 26: 19, 27: 20, 28: 21, 29: 22, 30: 23, 31: 24, 61: -1, 60: 25, 63: -1, 62: -1, 45: -1, 44: 26, 47: -1, 46: -1, } if os.path.isdir(CONTAINER_PLATFORM_PATH): platform_path = CONTAINER_PLATFORM_PATH else: platform = device_info.get_platform() if platform is None: raise platform_path = os.path.join(HOST_DEVICE_PATH, platform) port_config_file = "/".join( [platform_path, "E530-24x2q", "port_config.ini"]) try: f = open(port_config_file) except: raise for line in f: line.strip() if re.search('^#', line) is not None: Port_cfg = collections.namedtuple('Port_cfg', line.split()[1:]) break f.close() f = open(port_config_file) self._port_cfgs = [ Port_cfg(*tuple((line.strip().split()))) for line in f if re.search('^#', line) is None ] f.close() self.LED_MODE_UP = [11, 11] self.LED_MODE_DOWN = [7, 7] self.f_led = "/sys/class/leds/{}/brightness" self._initDefaultConfig()
def __init__(self): self.mac_to_sfp = { 0: 1, 1: 2, 2: 3, 3: 4, 8: 5, 9: 6, 10: 7, 11: 8, 20: 9, 21: 10, 22: 11, 23: 12, 12: 13, 13: 14, 14: 15, 15: 16, 24: 17, 25: 18, 26: 19, 27: 20, 28: 21, 29: 22, 30: 23, 31: 24, 61: 25, 60: 25, 63: 25, 62: 25, 45: 26, 44: 26, 47: 26, 46: 26, } self.logical = [] self.physical_to_logical = {} self.logical_to_physical = {} self.logical_to_asic = {} self.data = {'valid': 0, 'last': 0} self.f_sfp_present = "/sys/class/sfp/sfp{}/sfp_presence" self.f_sfp_enable = "/sys/class/sfp/sfp{}/sfp_enable" if os.path.isdir(CONTAINER_PLATFORM_PATH): platform_path = CONTAINER_PLATFORM_PATH else: platform = device_info.get_platform() if platform is None: raise platform_path = os.path.join(HOST_DEVICE_PATH, platform) port_config_file = "/".join( [platform_path, "E530-24x2c", "port_config.ini"]) try: f = open(port_config_file) except: raise for line in f: line.strip() if re.search('^#', line) is not None: Port_cfg = collections.namedtuple('Port_cfg', line.split()[1:]) break f.close() f = open(port_config_file) self._port_cfgs = [ Port_cfg(*tuple((line.strip().split()))) for line in f if re.search('^#', line) is None ] f.close() self.PORT_START = 256 self.PORT_END = 0 for port_cfg in self._port_cfgs: if int(port_cfg.index) <= self.PORT_START: self.PORT_START = int(port_cfg.index) elif int(port_cfg.index) >= self.PORT_END: self.PORT_END = int(port_cfg.index) self.eeprom_mapping = {} self.presence = {} for port_cfg in self._port_cfgs: sfp_idx = self.mac_to_sfp[int(port_cfg.lanes.split(',')[0])] if sfp_idx > 0: self.eeprom_mapping[int( port_cfg.index )] = "/sys/class/sfp/sfp{}/sfp_eeprom".format(sfp_idx) self.logical.append(port_cfg.name) else: self.eeprom_mapping[int(port_cfg.index)] = None self.presence[int(port_cfg.index)] = False SfpUtilBase.__init__(self)
try: from sonic_platform_base.sonic_eeprom import eeprom_tlvinfo except ImportError as e: raise ImportError(str(e) + "- required module not found") from .utils import default_return logger = Logger() # # this is mlnx-specific # should this be moved to chass.py or here, which better? # EEPROM_SYMLINK = "/var/run/hw-management/eeprom/vpd_info" platform_name = get_platform() if 'simx' in platform_name: platform_path = get_path_to_platform_dir() if not os.path.exists(EEPROM_SYMLINK): if not os.path.exists(os.path.dirname(EEPROM_SYMLINK)): os.makedirs(os.path.dirname(EEPROM_SYMLINK)) subprocess.check_call( ['/usr/bin/xxd', '-r', '-p', 'syseeprom.hex', EEPROM_SYMLINK], cwd=platform_path) class Eeprom(eeprom_tlvinfo.TlvInfoDecoder): RETRIES = 3