コード例 #1
0
ファイル: cpuinfo.py プロジェクト: srbarrios/uyuni
def _lscpu_count_sockets(feedback):
    '''
    Use lscpu method

    :return:
    '''
    lscpu = _which_bin(['lscpu'])
    if lscpu is not None:
        try:
            log.debug("Trying lscpu to get CPU socket count")
            ret = __salt__['cmd.run_all']('{0} -p'.format(lscpu),
                                          output_loglevel='quiet')
            if ret['retcode'] == 0:
                max_socket_index = -1
                for line in ret['stdout'].strip().splitlines():
                    if line.startswith('#'):
                        continue
                    socket_index = int(line.split(',')[2])
                    if socket_index > max_socket_index:
                        max_socket_index = socket_index
                if max_socket_index > -1:
                    return {'cpusockets': (1 + max_socket_index)}
        except Exception as error:
            feedback.append("lscpu: {0}".format(str(error)))
            log.debug(str(error))
コード例 #2
0
ファイル: cpuinfo.py プロジェクト: srbarrios/uyuni
def cpu_data():
    """
    Returns the cpu model, vendor ID and other data that may not be in the cpuinfo
    """
    lscpu = _which_bin(['lscpu'])
    if lscpu is not None:
        try:
            log.debug("Trying lscpu to get CPU data")
            ret = __salt__['cmd.run_all']('{0} -J'.format(lscpu),
                                          output_loglevel='quiet')
            if ret['retcode'] == 0:
                data = json.loads(ret["stdout"])
                name_map = {
                    "Model name": "cpu_model",
                    "Vendor ID": "cpu_vendor",
                    "NUMA node(s)": "cpu_numanodes",
                    "Stepping": "cpu_stepping",
                    "Core(s) per socket": "cpu_cores",
                }
                values = {}
                for entry in data.get("lscpu"):
                    if entry["field"][:-1] in name_map.keys():
                        values[name_map[entry["field"][:-1]]] = entry["data"]
                log.debug(values)
                return values
            else:
                log.warning("lscpu does not support -J option")
        except (CommandExecutionError, ValueError) as error:
            log.warning("lscpu: {0}".format(str(error)))
コード例 #3
0
ファイル: cpuinfo.py プロジェクト: uyuni-project/uyuni
def cpu_data():
    """
    Returns the cpu model, vendor ID and other data that may not be in the cpuinfo
    """
    lscpu = _which_bin(['lscpu'])
    if lscpu is not None:
        try:
            log.debug("Trying lscpu to get CPU data")
            ret = __salt__['cmd.run_all']('{0}'.format(lscpu),
                                          env={
                                              'LC_ALL': 'C'
                                          },
                                          output_loglevel='quiet')
            if ret['retcode'] == 0:
                lines = ret["stdout"].splitlines()
                name_map = {
                    "Model name": "cpu_model",
                    "Vendor ID": "cpu_vendor",
                    "NUMA node(s)": "cpu_numanodes",
                    "Stepping": "cpu_stepping",
                    "Core(s) per socket": "cpu_cores",
                }
                values = {}
                for line in lines:
                    parts = [l.strip() for l in line.split(":", 1)]
                    if len(parts) == 2 and parts[0] in name_map:
                        values[name_map[parts[0]]] = parts[1]
                log.debug(values)
                return values
            else:
                log.warning("lscpu does not support -J option")
        except (CommandExecutionError, ValueError) as error:
            log.warning("lscpu: {0}".format(str(error)))
コード例 #4
0
ファイル: sumautil.py プロジェクト: vzhestkov/uyuni
def _klp():
    '''
    klp to identify the current kernel live patch

    :return:
    '''
    # get 'kgr' for versions prior to SLE 15
    try:
        from salt.utils.path import which_bin as _which_bin
    except:
        from salt.utils import which_bin as _which_bin

    klp = _which_bin(['klp', 'kgr'])
    patchname = None
    if klp is not None:
        try:
            # loop until patching is finished
            for i in range(10):
                stat = __salt__['cmd.run_all']('{0} status'.format(klp),
                                               output_loglevel='quiet')
                log.debug("klp status: {0}".format(stat['stdout']))
                if stat['stdout'].strip().splitlines()[0] == 'ready':
                    break
                time.sleep(1)
            re_active = re.compile(r"^\s+active:\s*(\d+)$")
            ret = __salt__['cmd.run_all']('{0} -v patches'.format(klp),
                                          output_loglevel='quiet')
            log.debug("klp patches: {0}".format(ret['stdout']))
            if ret['retcode'] == 0:
                for line in ret['stdout'].strip().splitlines():
                    if line.startswith('#'):
                        continue

                    match_active = re_active.match(line)
                    if match_active and int(match_active.group(1)) > 0:
                        return {'mgr_kernel_live_version': patchname}
                    elif line.startswith('kgraft') or line.startswith(
                            'livepatch'):
                        # kgr patches have prefix 'kgraft', whereas klp patches start with 'livepatch'
                        patchname = line.strip()

        except Exception as error:
            log.error("klp: {0}".format(str(error)))
コード例 #5
0
def _dmidecode_count_sockets(feedback):
    '''
    Use dmidecode method.

    :return:
    '''
    dmidecode = _which_bin(['dmidecode'])
    if dmidecode is not None:
        try:
            log.debug("Trying dmidecode to get CPU socket count")
            ret = __salt__['cmd.run_all']("{0} -t processor".format(dmidecode), output_loglevel='quiet')
            if ret['retcode'] == 0:
                count = 0
                for line in ret['stdout'].strip().splitlines():
                    if 'Processor Information' in line:
                        count += 1
                if count:
                    return {'cpusockets': count}
        except Exception as error:
            log.debug(str(error))
            feedback.append("dmidecode: {0}".format(str(error)))
    else:
        feedback.append("dmidecode: executable not found")
コード例 #6
0
def __virtual__():
    '''
    This module is always enabled while 'ssh-agent' is available.
    '''
    return __virtualname__ if _which_bin(
        ['ssh-agent']) else (False, 'ssh-agent is not available')
コード例 #7
0
def __virtual__():
    '''
    Only work when udevadm is installed.
    '''
    return _which_bin(['udevadm']) is not None
コード例 #8
0
def __virtual__():
    return salt.modules.virt.__virtual__() and _which_bin(["libvirtd"
                                                           ]) is not None