示例#1
0
def get_sensors():
    result = []
    proc = subprocess.Popen(['sensors'],
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    try:
        data, err = bmc_command.timed_communicate(proc)
    except bmc_command.TimeoutError as ex:
        data = ex.output
        err = ex.error

    data = re.sub(r'\(.+?\)', '', data)
    for edata in data.split('\n\n'):
        adata = edata.split('\n', 1)
        sresult = {}
        if (len(adata) < 2):
            break
        sresult['name'] = adata[0]
        for sdata in adata[1].split('\n'):
            tdata = sdata.split(':')
            if (len(tdata) < 2):
                continue
            sresult[tdata[0].strip()] = tdata[1].strip()
        result.append(sresult)

    fresult = {
        "Information": result,
        "Actions": [],
        "Resources": [],
    }
    return fresult
示例#2
0
def get_eeprom_data(util):
    proc = subprocess.Popen([util],
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    data, err = bmc_command.timed_communicate(proc)
    data = data.decode()
    return _parse_eeprom_data(data)
示例#3
0
def get_fruid(cmd=['weutil']):
    result = {}
    proc = subprocess.Popen(cmd,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    try:
        data, err = bmc_command.timed_communicate(proc)
        data = data.decode()
    except bmc_command.TimeoutError as ex:
        data = ex.output
        err = ex.error

    # need to remove the first info line from weutil
    adata = data.split('\n', 1)
    for sdata in adata[1].split('\n'):
        tdata = sdata.split(':', 1)
        if (len(tdata) < 2):
            continue
        result[tdata[0].strip()] = tdata[1].strip()
    fresult = {
                "Information": result,
                "Actions": [],
                "Resources": [],
              }
    return fresult
示例#4
0
def get_platform():
    sresult = {}
    proc = subprocess.Popen(['/usr/local/bin/id-eeprom-show'],
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    try:
        data, err = bmc_command.timed_communicate(proc)
        data = data.decode()
    except bmc_command.TimeoutError as ex:
        data = ex.output
        err = ex.error

    data = re.sub(r'\(.+?\)', '', data)
    for adata in data.split('\n'):
        if (len(adata) < 2):
            break

        sdata = adata.split(':', 1)

        if (len(sdata) < 2):
            continue
        sresult[sdata[0].strip()] = sdata[1].strip()
    result = [sresult]
    fresult = {"PlatformState": result}
    return fresult
示例#5
0
def get_sensors():
    result = []
    proc = subprocess.Popen(['sensors'],
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    try:
        data, err = bmc_command.timed_communicate(proc)
    except bmc_command.TimeoutError as ex:
        data = ex.output
        err = ex.error

    data = re.sub(r'\(.+?\)', '', data)
    for edata in data.split('\n\n'):
        adata = edata.split('\n', 1)
        sresult = {}
        if (len(adata) < 2):
            break;
        sresult['name'] = adata[0]
        for sdata in adata[1].split('\n'):
            tdata = sdata.split(':')
            if (len(tdata) < 2):
                continue
            sresult[tdata[0].strip()] = tdata[1].strip()
        result.append(sresult)

    fresult = {
                "Information": result,
                "Actions": [],
                "Resources": [],
              }
    return fresult
def _get_qsfp_cpld_info():
    ver, sub_ver = 0, 0
    proc = subprocess.Popen(['/usr/local/bin/qsfp_cpld_ver.sh'],
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    try:
        data, err = bmc_command.timed_communicate(proc)
        data = data.decode()
        ver, sub_ver = data.split(',')
    except Exception as e:
        syslog.syslog(syslog.LOG_ERR,
                      'Error getting QSFP CPLD versions : {}'.format(e))

    return _firmware_json(ver, sub_ver)
示例#7
0
def get_fruid():
    result = {}
    proc = subprocess.Popen(['weutil'],
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    try:
        data, err = bmc_command.timed_communicate(proc)
    except bmc_command.TimeoutError as ex:
        data = ex.output
        err = ex.error

    # need to remove the first info line from weutil
    adata = data.split('\n', 1)
    for sdata in adata[1].split('\n'):
        tdata = sdata.split(':', 1)
        if (len(tdata) < 2):
            continue
        result[tdata[0].strip()] = tdata[1].strip()
    fresult = {
                "Information": result,
                "Actions": [],
                "Resources": [],
              }
    return fresult
示例#8
0
def get_mTerm_status():
    result = []
    proc = subprocess.Popen(['ps | grep mTerm'],
                            shell=True,
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    try:
        data, err = bmc_command.timed_communicate(proc)
    except bmc_command.TimeoutError as ex:
        data = ex.output
        err = ex.error

    is_running = 'Not Running'
    if b'mTerm_server' in data:
        is_running = 'Running'

    result = {
                "Information": {
                    "mTerm Server Status": is_running,
                },
                "Actions": [],
                "Resources": [],
             }
    return result
示例#9
0
def get_sensors_full():
    proc = subprocess.Popen(['sensors', '-u'],
                            stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    try:
        data, err = bmc_command.timed_communicate(proc)
    except bmc_command.TimeoutError as ex:
        data = ex.output
        err = ex.error

    # The output of sensors -u is a series of sections separated
    # by blank lines.  Each section looks like this:
    #   coretemp-isa-0000
    #   Adapter: ISA adapter
    #   Core 0:
    #     temp2_input: 40.000
    #     temp2_max: 110.000
    #     temp2_crit: 110.000
    #     temp2_crit_alarm: 0.000
    #   Core 1:
    #     temp3_input: 39.000
    #     temp3_max: 110.000
    #     temp3_crit: 110.000
    #     temp3_crit_alarm: 0.000
    #   ...
    #
    # We skip over malformed data silently.

    result = []
    pos = 0
    while pos < len(data):
        if data[pos] == '\n':
            pos += 1
            continue

        sresult = {}

        # match the first two lines of a section
        m = name_adapter_re.match(data, pos)
        if not m:
            # bad input, skip a line and try again
            pos = skipline_re.match(data, pos).end()
            continue
        sresult['name'] = m.group(1)
        sresult['adapter'] = m.group(2)
        pos = m.end()

        # match the sensors
        while True:
            # each starts with a label line
            m = label_re.match(data, pos)
            if not m:
                break
            label = m.group(1)
            pos = m.end()

            # the following lines are name-value pairs
            values = {}
            while True:
                m = value_re.match(data, pos)
                if not m:
                    break
                values[m.group(1)] = m.group(2)
                pos = m.end()

            if len(values) > 0:
                sresult[label] = values

        result.append(sresult)

    fresult = {
        "Information": result,
        "Actions": [],
        "Resources": [],
    }
    return fresult