Exemple #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)))
Exemple #2
0
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's ASIC
        try:
            version_info = device_info.get_sonic_version_info()
            if version_info:
                asic_type = version_info['asic_type']
            else:
                asic_type = None
        except (KeyError, TypeError) as e:
            click.echo("Caught an exception: " + str(e))

        # Get installing image's ASIC
        p1 = subprocess.Popen(["sed", "-e", "1,/^exit_marker$/d", image_path], stdout=subprocess.PIPE, preexec_fn=default_sigpipe)
        p2 = subprocess.Popen(["tar", "xf", "-", MACHINE_CONF, "-O"], stdin=p1.stdout, stdout=subprocess.PIPE, preexec_fn=default_sigpipe)
        p3 = subprocess.Popen(["sed", "-n", r"s/^machine=\(.*\)/\1/p"], stdin=p2.stdout, stdout=subprocess.PIPE, preexec_fn=default_sigpipe, text=True)

        stdout = p3.communicate()[0]
        image_asic = stdout.rstrip('\n')

        # Return false if machine is not found or unexpected issue occur
        if not image_asic:
            return False

        if asic_type == image_asic:
            return True
        return False
 def version_1_0_2(self):
     """
     Version 1_0_2.
     """
     log.log_info('Handling version_1_0_2')
     # Check ASIC type, if Mellanox platform then need DB migration
     version_info = device_info.get_sonic_version_info()
     if version_info['asic_type'] == "mellanox":
         if self.mlnx_migrate_buffer_pool_size():
             self.set_version('version_1_0_3')
     else:
         self.set_version('version_1_0_3')
     return None
Exemple #5
0
    def __init__(self, namespace, socket=None):
        """
        Version string format:
           version_<major>_<minor>_<build>
              major: starting from 1, sequentially incrementing in master
                     branch.
              minor: in github branches, minor version stays in 0. This minor
                     version creates space for private branches derived from
                     github public branches. These private branches shall use
                     none-zero values.
              build: sequentially increase within a minor version domain.
        """
        self.CURRENT_VERSION = 'version_2_0_5'

        self.TABLE_NAME = 'VERSIONS'
        self.TABLE_KEY = 'DATABASE'
        self.TABLE_FIELD = 'VERSION'

        db_kwargs = {}
        if socket:
            db_kwargs['unix_socket_path'] = socket

        if namespace is None:
            self.configDB = ConfigDBConnector(**db_kwargs)
        else:
            self.configDB = ConfigDBConnector(use_unix_socket_path=True,
                                              namespace=namespace,
                                              **db_kwargs)
        self.configDB.db_connect('CONFIG_DB')

        if namespace is None:
            self.appDB = ConfigDBConnector(**db_kwargs)
        else:
            self.appDB = ConfigDBConnector(use_unix_socket_path=True,
                                           namespace=namespace,
                                           **db_kwargs)
        self.appDB.db_connect('APPL_DB')

        self.stateDB = SonicV2Connector(host='127.0.0.1')
        if self.stateDB is not None:
            self.stateDB.connect(self.stateDB.STATE_DB)

        version_info = device_info.get_sonic_version_info()
        asic_type = version_info.get('asic_type')
        self.asic_type = asic_type
        self.hwsku = device_info.get_hwsku()

        if asic_type == "mellanox":
            from mellanox_buffer_migrator import MellanoxBufferMigrator
            self.mellanox_buffer_migrator = MellanoxBufferMigrator(
                self.configDB, self.appDB, self.stateDB)
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
Exemple #7
0
def _get_labels():
    labels = []

    hwsku = device_info.get_hwsku()
    version_info = device_info.get_sonic_version_info()

    labels.append("sonic_version={}".format(version_info['build_version']))
    labels.append("hwsku={}".format(hwsku))
    lh = Db().get_data('DEVICE_METADATA', 'localhost')
    labels.append("deployment_type={}".format(
        lh['type'] if lh and 'type' in lh else "Unknown"))
    labels.append("enable_pods=True")

    return labels
Exemple #8
0
def set_node_labels(server):
    labels = {}

    version_info = (device_info.get_sonic_version_info()
                    if not UNIT_TESTING else {
                        "build_version": "20201230.111"
                    })
    dev_data = server.get_db_entry(CONFIG_DB_NAME, 'DEVICE_METADATA',
                                   'localhost')
    dep_type = dev_data['type'] if 'type' in dev_data else "unknown"

    labels["sonic_version"] = version_info['build_version']
    labels["hwsku"] = device_info.get_hwsku() if not UNIT_TESTING else "mock"
    labels["deployment_type"] = dep_type
    server.mod_db_entry(STATE_DB_NAME, KUBE_LABEL_TABLE, KUBE_LABEL_SET_KEY,
                        labels)
Exemple #9
0
def register(cli):
    version_info = device_info.get_sonic_version_info()
    if (version_info and version_info.get('asic_type') == 'mellanox'):
        cli.commands['platform'].add_command(mlnx)
    hw_info_dict['asic_count'] = multi_asic.get_num_asics()

    return hw_info_dict


#
# 'platform' group ("show platform ...")
#

@click.group(cls=clicommon.AliasedGroup)
def platform():
    """Show platform-specific hardware info"""
    pass


version_info = device_info.get_sonic_version_info()
if (version_info and version_info.get('asic_type') == 'mellanox'):
    from . import mlnx
    platform.add_command(mlnx.mlnx)


# 'summary' subcommand ("show platform summary")
@platform.command()
@click.option('--json', is_flag=True, help="JSON output")
def summary(json):
    """Show hardware platform information"""

    hw_info_dict = {}
    hw_info_dict = get_hw_info_dict()

    if json:
Exemple #11
0
def register(cli):
    version_info = device_info.get_sonic_version_info()
    if version_info and version_info.get("asic_type") == "cisco-8000":
        for c in PLATFORM_CLIS:
            cli.commands["platform"].add_command(c)
def register(cli):
    version_info = device_info.get_sonic_version_info()
    if version_info and version_info.get('asic_type') == 'barefoot':
        cli.commands['platform'].add_command(barefoot)
def register(cli):
    version_info = device_info.get_sonic_version_info()
    if (version_info and version_info.get('asic_type') == 'cisco-8000'):
        cli.commands['platform'].add_command(inventory)
        cli.commands['platform'].add_command(idprom)