#!/usr/bin/python

#
# Copyright 2020 Cumulus Networks,  Inc.  All rights reserved.
#
# Record ssh_health output; used by cl-support
#
# The SSD health utility was provided to us by Mellanox.  So we
# only run it on Mellanox switches when cl-support is invoked.
#


import subprocess


#
# Global variables and "constants"
#

ssd_health_path  = '/usr/cumulus/bin/ssd_health_cumulus/ssd_health.sh'


def is_mlnx():
    mlnx = False

    cmd = ['platform-detect']
    try:
        output = subprocess.check_output(cmd)
    except subprocess.CalledProcessError:
        return mlnx

    switch_vendor = ''
    for row in output.split('\n'):
        fields = row.split(',')
        if len(fields) >= 1:
            switch_vendor = fields[0]
        if (switch_vendor == 'mlnx') or (switch_vendor == 'mlx'):
            mlnx = True

    return mlnx


if is_mlnx():
    cmd = [ssd_health_path,'--mode','manual']
    subprocess.call(cmd)
