def get_expected_running_containers(self, feature_table): """Get a set of containers that are expected to running on SONiC Args: feature_table (object): FEATURE table in CONFIG_DB Returns: expected_running_containers: A set of container names that are expected running container_feature_dict: A dictionary {<container_name>:<feature_name>} """ expected_running_containers = set() container_feature_dict = {} for feature_name, feature_entry in feature_table.items(): if feature_entry["state"] not in ["disabled", "always_disabled"]: if multi_asic.is_multi_asic(): if feature_entry["has_global_scope"] == "True": expected_running_containers.add(feature_name) container_feature_dict[feature_name] = feature_name if feature_entry["has_per_asic_scope"] == "True": num_asics = multi_asic.get_num_asics() for asic_id in range(num_asics): expected_running_containers.add(feature_name + str(asic_id)) container_feature_dict[feature_name + str(asic_id)] = feature_name else: expected_running_containers.add(feature_name) container_feature_dict[feature_name] = feature_name return expected_running_containers, container_feature_dict
def main(): logger = Logger(SYSLOG_IDENTIFIER) logger.set_min_log_priority_info() if len(sys.argv) != 3: raise Exception('Pass service and valid asic-id as arguments') service = sys.argv[1] args_asic_id = sys.argv[2] # Get num asics num_asics = multi_asic.get_num_asics() if num_asics == 0: logger.log_error( 'Detected no asics on this platform for service {}'.format( service)) sys.exit(1) # Connect to STATE_DB and subscribe to chassis-module table notifications state_db = daemon_base.db_connect("CHASSIS_STATE_DB") sel = swsscommon.Select() sst = swsscommon.SubscriberStateTable(state_db, CHASSIS_ASIC_INFO_TABLE) sel.addSelectable(sst) while True: (state, c) = sel.select(SELECT_TIMEOUT_MSECS) if state == swsscommon.Select.TIMEOUT: continue if state != swsscommon.Select.OBJECT: continue (asic_key, asic_op, asic_fvp) = sst.pop() asic_id = re.search(r'\d+$', asic_key) global_asic_id = asic_id.group(0) if asic_op == 'SET': asic_fvs = dict(asic_fvp) asic_name = asic_fvs.get('name') if asic_name is None: logger.log_info('Unable to get asic_name for asic{}'.format( global_asic_id)) continue if asic_name.startswith('FABRIC-CARD') is False: logger.log_info( 'Skipping module with asic_name {} for asic{}'.format( asic_name, global_asic_id)) continue if (global_asic_id == args_asic_id): logger.log_info( 'Detected asic{} is online'.format(global_asic_id)) sys.exit(0) elif asic_op == 'DEL': logger.log_info( 'Detected asic{} is offline'.format(global_asic_id)) sys.exit(1) else: continue
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 cli(): """sfputil - Command line utility for managing SFP transceivers""" if os.geteuid() != 0: click.echo("Root privileges are required for this operation") sys.exit(1) # Load platform-specific sfputil class err = load_platform_sfputil() if err != 0: sys.exit(2) # Load port info try: if multi_asic.is_multi_asic(): # For multi ASIC platforms we pass DIR of port_config_file_path and the number of asics (platform_path, hwsku_path) = device_info.get_paths_to_platform_and_hwsku_dirs() # Load platform module from source platform_sfputil.read_all_porttab_mappings( hwsku_path, multi_asic.get_num_asics()) else: # For single ASIC platforms we pass port_config_file_path and the asic_inst as 0 port_config_file_path = device_info.get_path_to_port_config_file() platform_sfputil.read_porttab_mappings(port_config_file_path, 0) except Exception as e: log.log_error("Error reading port info (%s)" % str(e), True) sys.exit(3)
def platform_sfputil_read_porttab_mappings(): global platform_porttab_mapping_read if platform_porttab_mapping_read: return 0 try: if multi_asic.is_multi_asic(): # For multi ASIC platforms we pass DIR of port_config_file_path and the number of asics (platform_path, hwsku_path) = device_info.get_paths_to_platform_and_hwsku_dirs() # Load platform module from source platform_sfputil.read_all_porttab_mappings( hwsku_path, multi_asic.get_num_asics()) else: # For single ASIC platforms we pass port_config_file_path and the asic_inst as 0 port_config_file_path = device_info.get_path_to_port_config_file() platform_sfputil.read_porttab_mappings(port_config_file_path, 0) platform_porttab_mapping_read = True except Exception as e: click.echo("Error reading port info (%s)" % str(e)) sys.exit(1) return 0
def __init__(self, log_identifier): super(DaemonYcable, self).__init__(log_identifier) self.timeout = YCABLE_MAIN_THREAD_SLEEP_SECS self.num_asics = multi_asic.get_num_asics() self.stop_event = threading.Event() self.sfp_error_event = threading.Event() self.y_cable_presence = [False]
def main(): module = AnsibleModule(argument_spec=dict(hwsku=dict(required=True, type='str'), num_asic=dict(type='int', required=False)), supports_check_mode=True) m_args = module.params try: aliases = [] portmap = {} aliasmap = {} portspeed = {} allmap = SonicPortAliasMap(m_args['hwsku']) # ASIC interface names of front panel interfaces front_panel_asic_ifnames = [] # { asic_name: [ asic interfaces] } asic_if_names = {} # When this script is invoked on sonic-mgmt docker, num_asic # parameter is passed. if m_args['num_asic'] is not None: num_asic = m_args['num_asic'] else: # When this script is run on the device, num_asic parameter # is not passed. try: num_asic = multi_asic.get_num_asics() except Exception, e: num_asic = 1 for asic_id in range(num_asic): if num_asic == 1: asic_id = None (aliases_asic, portmap_asic, aliasmap_asic, portspeed_asic, front_panel_asic, asicifnames_asic) = allmap.get_portmap(asic_id) if aliases_asic is not None: aliases.extend(aliases_asic) if portmap_asic is not None: portmap.update(portmap_asic) if aliasmap_asic is not None: aliasmap.update(aliasmap_asic) if portspeed_asic is not None: portspeed.update(portspeed_asic) if front_panel_asic is not None: front_panel_asic_ifnames.extend(front_panel_asic) if asicifnames_asic is not None: asic = 'ASIC' + str(asic_id) asic_if_names[asic] = asicifnames_asic module.exit_json( ansible_facts={ 'port_alias': aliases, 'port_name_map': portmap, 'port_alias_map': aliasmap, 'port_speed': portspeed, 'front_panel_asic_ifnames': front_panel_asic_ifnames, 'asic_if_names': asic_if_names })
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 load_port_config(): try: if multi_asic.is_multi_asic(): # For multi ASIC platforms we pass DIR of port_config_file_path and the number of asics (platform_path, hwsku_path) = device_info.get_paths_to_platform_and_hwsku_dirs() # Load platform module from source platform_sfputil.read_all_porttab_mappings(hwsku_path, multi_asic.get_num_asics()) else: # For single ASIC platforms we pass port_config_file_path and the asic_inst as 0 port_config_file_path = device_info.get_path_to_port_config_file() platform_sfputil.read_porttab_mappings(port_config_file_path, 0) except Exception as e: log.log_error("Error reading port info ({})".format(str(e)), True) return False return True
def main(): module = AnsibleModule(argument_spec=dict(hwsku=dict(required=True, type='str'), num_asic=dict(type='int', required=False), include_internal=dict( required=False, type='bool', default=False), card_type=dict(type='str', required=False), hostname=dict(type='str', required=False), switchids=dict(type='list', required=False), slotid=dict(type='str', required=False)), supports_check_mode=True) m_args = module.params try: aliases = [] portmap = {} aliasmap = {} portspeed = {} sysports = [] # Map of ASIC interface names to front panel interfaces front_panel_asic_ifnames = {} # { asic_name: [ asic interfaces] } asic_if_names = {} if 'card_type' in m_args and m_args['card_type'] == 'supervisor': module.exit_json( ansible_facts={ 'port_alias': aliases, 'port_name_map': portmap, 'port_alias_map': aliasmap, 'port_speed': portspeed, 'front_panel_asic_ifnames': [], 'asic_if_names': asic_if_names, 'sysports': sysports }) return allmap = SonicPortAliasMap(m_args['hwsku']) switchids = None slotid = None if 'switchids' in m_args and m_args['switchids'] != None and len( m_args['switchids']): switchids = m_args['switchids'] if 'slotid' in m_args and m_args['slotid'] != None: slotid = m_args['slotid'] # When this script is invoked on sonic-mgmt docker, num_asic # parameter is passed. if m_args['num_asic'] is not None: num_asic = m_args['num_asic'] else: # When this script is run on the device, num_asic parameter # is not passed. try: num_asic = multi_asic.get_num_asics() except Exception as e: num_asic = 1 # Modify KVM platform string based on num_asic global KVM_PLATFORM if num_asic == 4: KVM_PLATFORM = "x86_64-kvm_x86_64_4_asic-r0" if num_asic == 6: KVM_PLATFORM = "x86_64-kvm_x86_64_6_asic-r0" switchid = 0 include_internal = False if 'include_internal' in m_args: include_internal = m_args['include_internal'] hostname = "" if 'hostname' in m_args: hostname = m_args['hostname'] for asic_id in range(num_asic): if switchids and asic_id is not None: switchid = switchids[asic_id] if num_asic == 1: asic_id = None (aliases_asic, portmap_asic, aliasmap_asic, portspeed_asic, front_panel_asic, asicifnames_asic, sysport_asic) = allmap.get_portmap(asic_id, include_internal, hostname, switchid, slotid) if aliases_asic is not None: aliases.extend(aliases_asic) if portmap_asic is not None: portmap.update(portmap_asic) if aliasmap_asic is not None: aliasmap.update(aliasmap_asic) if portspeed_asic is not None: portspeed.update(portspeed_asic) if front_panel_asic is not None: front_panel_asic_ifnames.update(front_panel_asic) if asicifnames_asic is not None: asic = 'ASIC' + str(asic_id) asic_if_names[asic] = asicifnames_asic if sysport_asic is not None: sysports.extend(sysport_asic) # Sort the Interface Name needed in multi-asic aliases.sort(key=lambda x: int(x[1])) # Get ASIC interface names list based on sorted aliases front_panel_asic_ifnames_list = [] for k in aliases: if k[0] in front_panel_asic_ifnames: front_panel_asic_ifnames_list.append( front_panel_asic_ifnames[k[0]]) module.exit_json( ansible_facts={ 'port_alias': [k[0] for k in aliases], 'port_name_map': portmap, 'port_alias_map': aliasmap, 'port_speed': portspeed, 'front_panel_asic_ifnames': front_panel_asic_ifnames_list, 'asic_if_names': asic_if_names, 'sysports': sysports }) except (IOError, OSError) as e: fail_msg = "IO error" + str(e) module.fail_json(msg=fail_msg) except Exception as e: fail_msg = "failed to find the correct port config for " + m_args[ 'hwsku'] + str(e) module.fail_json(msg=fail_msg)
def main(): module = AnsibleModule(argument_spec=dict( hwsku=dict(required=True, type='str'), num_asic=dict(type='int', required=False), include_internal=dict(required=False, type='bool', default=False), card_type=dict(type='str', required=False), hostname=dict(type='str', required=False), start_switchid=dict(type='int', required=False)), supports_check_mode=True) m_args = module.params try: aliases = [] portmap = {} aliasmap = {} portspeed = {} sysports = [] # ASIC interface names of front panel interfaces front_panel_asic_ifnames = [] # { asic_name: [ asic interfaces] } asic_if_names = {} if 'card_type' in m_args and m_args['card_type'] == 'supervisor': module.exit_json( ansible_facts={ 'port_alias': aliases, 'port_name_map': portmap, 'port_alias_map': aliasmap, 'port_speed': portspeed, 'front_panel_asic_ifnames': front_panel_asic_ifnames, 'asic_if_names': asic_if_names, 'sysports': sysports }) return allmap = SonicPortAliasMap(m_args['hwsku']) start_switchid = 0 if 'start_switchid' in m_args and m_args['start_switchid'] != None: start_switchid = int(m_args['start_switchid']) # When this script is invoked on sonic-mgmt docker, num_asic # parameter is passed. if m_args['num_asic'] is not None: num_asic = m_args['num_asic'] else: # When this script is run on the device, num_asic parameter # is not passed. try: num_asic = multi_asic.get_num_asics() except Exception, e: num_asic = 1 switchid = 0 include_internal = False if 'include_internal' in m_args: include_internal = m_args['include_internal'] hostname = "" if 'hostname' in m_args: hostname = m_args['hostname'] for asic_id in range(num_asic): if asic_id is not None: switchid = start_switchid + asic_id if num_asic == 1: asic_id = None (aliases_asic, portmap_asic, aliasmap_asic, portspeed_asic, front_panel_asic, asicifnames_asic, sysport_asic) = allmap.get_portmap(asic_id, include_internal, hostname, switchid) if aliases_asic is not None: aliases.extend(aliases_asic) if portmap_asic is not None: portmap.update(portmap_asic) if aliasmap_asic is not None: aliasmap.update(aliasmap_asic) if portspeed_asic is not None: portspeed.update(portspeed_asic) if front_panel_asic is not None: front_panel_asic_ifnames.extend(front_panel_asic) if asicifnames_asic is not None: asic = 'ASIC' + str(asic_id) asic_if_names[asic] = asicifnames_asic if sysport_asic is not None: sysports.extend(sysport_asic) module.exit_json( ansible_facts={ 'port_alias': aliases, 'port_name_map': portmap, 'port_alias_map': aliasmap, 'port_speed': portspeed, 'front_panel_asic_ifnames': front_panel_asic_ifnames, 'asic_if_names': asic_if_names, 'sysports': sysports })
'--asic_index', type=str, help='the asic instance', default=None) args = parser.parse_args() if args.asic_index: asic_id = args.asic_index platform_sfputil = sonic_platform_base.sonic_sfp.sfputilhelper.SfpUtilHelper() if multi_asic.is_multi_asic(): # load and parse the port configuration file on DUT (platform_path, hwsku_path) = device_info.get_paths_to_platform_and_hwsku_dirs() # handle case where asic_id input is "all" or a valid asic index. if asic_id == "all": platform_sfputil.read_all_porttab_mappings(hwsku_path, multi_asic.get_num_asics()) else: port_config_path = os.path.join(hwsku_path, asic_id, PORT_CONFIG_FILE) platform_sfputil.read_porttab_mappings(port_config_path) else: port_config_path = device_info.get_path_to_port_config_file() platform_sfputil.read_porttab_mappings(port_config_path) # print the mapping to stdout in json format print json.dumps(platform_sfputil.logical_to_physical) # json will be loaded by sonic-mgmt