コード例 #1
0
    def get_cpu_info(self):
        try:
            out, _e = utils.execute(
                "dmidecode --type processor | grep 'Processor Information'",
                shell=True)
        except (processutils.ProcessExecutionError, OSError) as e:
            LOG.warning("Cannot get cpu count info: %s", e)
            cpu_count = 0
        else:
            cpu_count = len(out.strip().split('\n'))

        version = ''
        out, _e = utils.try_execute(
            "dmidecode --type processor | grep Version", shell=True)
        if out:
            try:
                for line in out.strip().split('\n'):
                    line = line.strip()
                    version = line.split('Version: ', 1)[1]
                    if not version:
                        LOG.debug('One cpu version is empty')
                    else:
                        break

            except (IndexError, ValueError):
                LOG.warning('Malformed CPU version information: %s', out)
        else:
            LOG.warning('Failed to get CPU version')

        core_count = 0
        thread_count = 0
        out, _e = utils.try_execute(
            "dmidecode --type processor | grep 'Count'", shell=True)
        if out:
            try:
                for line in out.strip().split('\n'):
                    line = line.strip()
                    if core_count and thread_count:
                        break

                    if 'Core Count' in line:
                        value = line.split('Core Count: ', 1)[1]
                        core_count = int(value)

                    if 'Thread Count' in line:
                        value = line.split('Thread Count: ', 1)[1]
                        thread_count = int(value)

            except (IndexError, ValueError):
                LOG.warning(
                    'Malformed CPU core count and thread count information: %s',
                    out)
        else:
            LOG.warning('Failed to get CPU core count and thread count')

        return CPUInfo(version=version,
                       cpu_count=cpu_count,
                       core_count=core_count,
                       thread_count=thread_count)
コード例 #2
0
    def get_cpus(self):
        lines = utils.execute('lscpu')[0]
        cpu_info = {
            k.strip().lower(): v.strip()
            for k, v in (line.split(':', 1) for line in lines.split('\n')
                         if line.strip())
        }
        # Current CPU frequency can be different from maximum one on modern
        # processors
        freq = cpu_info.get('cpu max mhz', cpu_info.get('cpu mhz'))

        flags = []
        out = utils.try_execute('grep', '-Em1', '^flags', '/proc/cpuinfo')
        if out:
            try:
                # Example output (much longer for a real system):
                # flags           : fpu vme de pse
                flags = out[0].strip().split(':', 1)[1].strip().split()
            except (IndexError, ValueError):
                LOG.warning('Malformed CPU flags information: %s', out)
        else:
            LOG.warning('Failed to get CPU flags')

        return CPU(
            model_name=cpu_info.get('model name'),
            frequency=freq,
            # this includes hyperthreading cores
            count=int(cpu_info.get('cpu(s)')),
            architecture=cpu_info.get('architecture'),
            flags=flags)
コード例 #3
0
    def get_cpus(self):
        lines = utils.execute('lscpu')[0]
        cpu_info = {k.strip().lower(): v.strip() for k, v in
                    (line.split(':', 1)
                     for line in lines.split('\n')
                     if line.strip())}
        # Current CPU frequency can be different from maximum one on modern
        # processors
        freq = cpu_info.get('cpu max mhz', cpu_info.get('cpu mhz'))

        flags = []
        out = utils.try_execute('grep', '-Em1', '^flags', '/proc/cpuinfo')
        if out:
            try:
                # Example output (much longer for a real system):
                # flags           : fpu vme de pse
                flags = out[0].strip().split(':', 1)[1].strip().split()
            except (IndexError, ValueError):
                LOG.warning('Malformed CPU flags information: %s', out)
        else:
            LOG.warning('Failed to get CPU flags')

        return CPU(model_name=cpu_info.get('model name'),
                   frequency=freq,
                   # this includes hyperthreading cores
                   count=int(cpu_info.get('cpu(s)')),
                   architecture=cpu_info.get('architecture'),
                   flags=flags)
コード例 #4
0
    def get_bmc_address(self):
        # These modules are rarely loaded automatically
        utils.try_execute('modprobe', 'ipmi_msghandler')
        utils.try_execute('modprobe', 'ipmi_devintf')
        utils.try_execute('modprobe', 'ipmi_si')

        try:
            out, _e = utils.execute(
                "ipmitool lan print | grep -e 'IP Address [^S]' "
                "| awk '{ print $4 }'",
                shell=True)
            if out.strip() and out.strip() != '0.0.0.0':
                return out.strip()

        except (processutils.ProcessExecutionError, OSError) as e:
            # Not error, because it's normal in virtual environment
            LOG.warning("Cannot get BMC address: %s", e)

        for channel_id in range(1, 10):
            try:
                out, _e = utils.execute("ipmitool lan print " +
                                        str(channel_id) +
                                        "| grep -e 'IP Address [^S]' "
                                        "| awk '{ print $4 }'",
                                        shell=True)
                if out.strip() and out.strip() != '0.0.0.0':
                    return out.strip()

            except (processutils.ProcessExecutionError, OSError) as e:
                # Not error, because it's normal in virtual environment
                LOG.warning("Cannot get BMC address: %s, channel_id: %d" %
                            (e, channel_id))

        return None
コード例 #5
0
    def get_bmc_address(self):
        """Attempt to detect BMC IP address

        :return: IP address of lan channel or 0.0.0.0 in case none of them is
                 configured properly
        """
        # These modules are rarely loaded automatically
        utils.try_execute('modprobe', 'ipmi_msghandler')
        utils.try_execute('modprobe', 'ipmi_devintf')
        utils.try_execute('modprobe', 'ipmi_si')

        try:
            # From all the channels 0-15, only 1-7 can be assigned to different
            # types of communication media and protocols and effectively used
            for channel in range(1, 8):
                out, e = utils.execute(
                    "ipmitool lan print {} | awk '/IP Address[[:space:]]*:/"
                    " {{print $4}}'".format(channel),
                    shell=True)
                # Invalid channel cannot be followed by a valid one, so we can
                # safely break here
                if e.startswith("Invalid channel"):
                    break
                # In case we get empty IP or 0.0.0.0 on a valid channel,
                # we need to keep querying
                if out.strip() not in ('', '0.0.0.0'):
                    return out.strip()

        except (processutils.ProcessExecutionError, OSError) as e:
            # Not error, because it's normal in virtual environment
            LOG.warning("Cannot get BMC address: %s", e)
            return

        return '0.0.0.0'
コード例 #6
0
    def get_ipmi_info(self):
        # These modules are rarely loaded automatically
        utils.try_execute('modprobe', 'ipmi_msghandler')
        utils.try_execute('modprobe', 'ipmi_devintf')
        utils.try_execute('modprobe', 'ipmi_si')

        try:
            out, _e = utils.execute(
                "ipmitool lan print", shell=True, attempts=2)
        except (processutils.ProcessExecutionError, OSError) as e:
            # Not error, because it's normal in virtual environment
            LOG.warning("Cannot get BMC info: %s", e)
            return {}

        info = {}
        for line in out.split('\n'):
            spl = line.find(':')
            if spl == -1:
                continue
            else:
                key = line[0:spl].strip()
                if key == '':
                    continue
                info[line[0:spl].strip()] = line[spl+1:].strip()
        return info
コード例 #7
0
    def get_bmc_address(self):
        # These modules are rarely loaded automatically
        utils.try_execute('modprobe', 'ipmi_msghandler')
        utils.try_execute('modprobe', 'ipmi_devintf')
        utils.try_execute('modprobe', 'ipmi_si')

        try:
            out, _e = utils.execute(
                "ipmitool lan print | grep -e 'IP Address [^S]' "
                "| awk '{ print $4 }'", shell=True)
        except (processutils.ProcessExecutionError, OSError) as e:
            # Not error, because it's normal in virtual environment
            LOG.warning("Cannot get BMC address: %s", e)
            return

        return out.strip()
コード例 #8
0
    def get_bmc_address(self):
        # These modules are rarely loaded automatically
        utils.try_execute('modprobe', 'ipmi_msghandler')
        utils.try_execute('modprobe', 'ipmi_devintf')
        utils.try_execute('modprobe', 'ipmi_si')

        try:
            out, _e = utils.execute(
                "ipmitool lan print | grep -e 'IP Address [^S]' "
                "| awk '{ print $4 }'", shell=True)
        except (processutils.ProcessExecutionError, OSError) as e:
            # Not error, because it's normal in virtual environment
            LOG.warning("Cannot get BMC address: %s", e)
            return

        return out.strip()
コード例 #9
0
    def get_bmc_address(self):
        """Attempt to detect BMC IP address

        :return: IP address of lan channel or 0.0.0.0 in case none of them is
                 configured properly
        """
        # These modules are rarely loaded automatically
        utils.try_execute('modprobe', 'ipmi_msghandler')
        utils.try_execute('modprobe', 'ipmi_devintf')
        utils.try_execute('modprobe', 'ipmi_si')

        try:
            # From all the channels 0-15, only 1-7 can be assigned to different
            # types of communication media and protocols and effectively used
            for channel in range(1, 8):
                out, e = utils.execute(
                    "ipmitool lan print {} | awk '/IP Address[[:space:]]*:/"
                    " {{print $4}}'".format(channel), shell=True)
                if e.startswith("Invalid channel"):
                    continue
                out = out.strip()

                try:
                    netaddr.IPAddress(out)
                except netaddr.AddrFormatError:
                    LOG.warning('Invalid IP address: %s', out)
                    continue

                # In case we get 0.0.0.0 on a valid channel, we need to keep
                # querying
                if out != '0.0.0.0':
                    return out

        except (processutils.ProcessExecutionError, OSError) as e:
            # Not error, because it's normal in virtual environment
            LOG.warning("Cannot get BMC address: %s", e)
            return

        return '0.0.0.0'