Example #1
0
def main():

    module = AnsibleModule(argument_spec=dict(), supports_check_mode=False)

    results = {}

    try:
        results['platform'], results[
            'hwsku'] = device_info.get_platform_and_hwsku()
        results['is_multi_asic'] = device_info.is_multi_npu()
        results['num_asic'] = device_info.get_num_npus()
        results.update(device_info.get_sonic_version_info())

        # In case a image does not have /etc/sonic/sonic_release, guess release from 'build_version'
        if 'release' not in results or not results['release'] or results[
                'release'] == 'none':
            if 'build_version' in results:
                if '201811' in results['build_version']:
                    results['release'] = '201811'
                elif '201911' in results['build_version']:
                    results['release'] = '201911'
                elif 'master' in results['build_version']:
                    results['release'] = 'master'
                else:
                    results['release'] = 'unknown'

        module.exit_json(ansible_facts={'dut_basic_facts': results})
    except Exception as e:
        module.fail_json(
            msg='Gather DUT facts failed, exception: {}'.format(repr(e)))
Example #2
0
def get_path_to_device():
    # Get platform and hwsku
    (platform, hwsku) = device_info.get_platform_and_hwsku()

    # Load platform module from source
    platform_path = "/".join([PLATFORM_ROOT_PATH, platform])

    return platform_path
Example #3
0
    def __init__(self):
        ChassisBase.__init__(self)
        self.config_data = {}
        (self.platform, self.hwsku) = device_info.get_platform_and_hwsku()

        self.__initialize_fan()
        self.__initialize_psu()
        self.__initialize_thermals()
        self.__initialize_components()
        self.__initialize_sfp()
        self.__initialize_eeprom()
Example #4
0
    def __init__(self):
        if not os.path.exists("/usr/share/sonic/platform"):
            self.platform, self.hwsku = device_info.get_platform_and_hwsku()
            os.symlink("/usr/share/sonic/device/" + self.platform,
                       "/usr/share/sonic/platform")

        try:
            with open('/usr/share/sonic/platform/pddf/pddf-device.json') as f:
                self.data = json.load(f)
        except IOError:
            if os.path.exists('/usr/share/sonic/platform'):
                os.unlink("/usr/share/sonic/platform")

        self.data_sysfs_obj = {}
        self.sysfs_obj = {}
Example #5
0
 def __init__(self):
     (self.platform, self.hwsku) = device_info.get_platform_and_hwsku()
    def read_porttab_mappings(self, porttabfile, asic_inst=0):
        logical = []
        logical_to_physical = {}
        physical_to_logical = {}
        last_fp_port_index = 0
        last_portname = ""
        first = 1
        port_pos_in_file = 0
        parse_fmt_port_config_ini = False
        parse_fmt_platform_json = False

        parse_fmt_port_config_ini = (
            os.path.basename(porttabfile) == PORT_CONFIG_INI)
        parse_fmt_platform_json = (
            os.path.basename(porttabfile) == PLATFORM_JSON)

        (platform, hwsku) = device_info.get_platform_and_hwsku()
        if (parse_fmt_platform_json):
            ports, _, _ = get_port_config(hwsku, platform)
            if not ports:
                print('Failed to get port config', file=sys.stderr)
                sys.exit(1)
            else:
                logical_list = []
                for intf in ports.keys():
                    logical_list.append(intf)

                logical = natsorted(logical_list, key=lambda y: y.lower())
                logical_to_physical, physical_to_logical = OrderedDict(
                ), OrderedDict()

                for intf_name in logical:
                    bcm_port = str(port_pos_in_file)

                    if 'index' in ports[intf_name].keys():
                        fp_port_index = int(ports[intf_name]['index'])
                        logical_to_physical[intf_name] = [fp_port_index]

                    if physical_to_logical.get(fp_port_index) is None:
                        physical_to_logical[fp_port_index] = [intf_name]
                    else:
                        physical_to_logical[fp_port_index].append(intf_name)

                    # Mapping of logical port names available on a system to ASIC instance
                    self.logical_to_asic[intf_name] = asic_inst
                    port_pos_in_file += 1

                self.logical = logical
                self.logical_to_physical = logical_to_physical
                self.physical_to_logical = physical_to_logical
                """
                print("logical: {}".format(self.logical))
                print("logical to physical: {}".format(self.logical_to_physical))
                print("physical to logical: {}".format( self.physical_to_logical))
                """
                return None

        try:
            f = open(porttabfile)
        except:
            raise

        # Read the porttab file and generate dicts
        # with mapping for future reference.
        #
        # TODO: Refactor this to use the portconfig.py module that now
        # exists as part of the sonic-config-engine package.
        title = []
        for line in f:
            line.strip()
            if re.search("^#", line) is not None:
                # The current format is: # name lanes alias index speed
                # Where the ordering of the columns can vary
                title = line.split()[1:]
                continue

            # Parsing logic for 'port_config.ini' file
            if (parse_fmt_port_config_ini):
                # bcm_port is not explicitly listed in port_config.ini format
                # Currently we assume ports are listed in numerical order according to bcm_port
                # so we use the port's position in the file (zero-based) as bcm_port
                portname = line.split()[0]

                # Ignore if this is an internal backplane interface
                if portname.startswith(backplane_prefix()):
                    continue

                bcm_port = str(port_pos_in_file)

                if "index" in title:
                    fp_port_index = int(line.split()[title.index("index")])
                # Leave the old code for backward compatibility
                elif "asic_port_name" not in title and len(line.split()) >= 4:
                    fp_port_index = int(line.split()[3])
                else:
                    fp_port_index = portname.split("Ethernet").pop()
                    fp_port_index = int(fp_port_index.split("s").pop(0)) / 4
            else:  # Parsing logic for older 'portmap.ini' file
                (portname, bcm_port) = line.split("=")[1].split(",")[:2]

                fp_port_index = portname.split("Ethernet").pop()
                fp_port_index = int(fp_port_index.split("s").pop(0)) / 4

            if ((len(self.sfp_ports) > 0)
                    and (fp_port_index not in self.sfp_ports)):
                continue

            if first == 1:
                # Initialize last_[physical|logical]_port
                # to the first valid port
                last_fp_port_index = fp_port_index
                last_portname = portname
                first = 0

            logical.append(portname)

            # Mapping of logical port names available on a system to ASIC instance
            self.logical_to_asic[portname] = asic_inst

            logical_to_physical[portname] = [fp_port_index]
            if physical_to_logical.get(fp_port_index) is None:
                physical_to_logical[fp_port_index] = [portname]
            else:
                physical_to_logical[fp_port_index].append(portname)

            last_fp_port_index = fp_port_index
            last_portname = portname

            port_pos_in_file += 1

        self.logical.extend(logical)
        self.logical_to_physical.update(logical_to_physical)
        self.physical_to_logical.update(physical_to_logical)
        """
Example #7
0
 def __init__(self, conf=None):
     self._main_conf = conf
     (self.platform, self.hwsku) = device_info.get_platform_and_hwsku()