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))
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)))
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)))
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)))
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")
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')
def __virtual__(): ''' Only work when udevadm is installed. ''' return _which_bin(['udevadm']) is not None
def __virtual__(): return salt.modules.virt.__virtual__() and _which_bin(["libvirtd" ]) is not None