예제 #1
0
파일: osinfo.py 프로젝트: vjuranek/vdsm
def nested_virtualization():
    if cpuarch.is_ppc(cpuarch.real()):
        return NestedVirtualization(False, None)

    if cpuarch.is_s390(cpuarch.real()):
        kvm_modules = ("kvm", )
    else:
        kvm_modules = ("kvm_intel", "kvm_amd")

    for kvm_module in kvm_modules:
        kvm_module_path = "/sys/module/%s/parameters/nested" % kvm_module
        try:
            with open(kvm_module_path) as f:
                if f.readline().strip() in ("Y", "1"):
                    return NestedVirtualization(True, kvm_module)
        except IOError as e:
            if e.errno != errno.ENOENT:
                logging.exception('Error checking %s nested virtualization',
                                  kvm_module)
            else:
                logging.debug('%s nested virtualization not detected',
                              kvm_module)

    logging.debug('Could not determine status of nested ' 'virtualization')
    return NestedVirtualization(False, None)
예제 #2
0
파일: osinfo.py 프로젝트: nirs/vdsm
def nested_virtualization():
    if cpuarch.is_ppc(cpuarch.real()):
        return NestedVirtualization(False, None)

    if cpuarch.is_s390(cpuarch.real()):
        kvm_modules = ("kvm",)
    else:
        kvm_modules = ("kvm_intel", "kvm_amd")

    for kvm_module in kvm_modules:
        kvm_module_path = "/sys/module/%s/parameters/nested" % kvm_module
        try:
            with open(kvm_module_path) as f:
                if f.readline().strip() in ("Y", "1"):
                    return NestedVirtualization(True, kvm_module)
        except IOError:
            logging.debug('%s nested virtualization '
                          'not detected' % kvm_module, exc_info=True)

    logging.debug('Could not determine status of nested '
                  'virtualization')
    return NestedVirtualization(False, None)
예제 #3
0
파일: cpuinfo.py 프로젝트: nirs/vdsm
def _cpuinfo():
    '''
    Parse cpuinfo-like file, keeping the values in module's runtime variables.

    Arguments:

    source      Optional. Accepts a string indicating path to the cpuinfo-like
                file. If not supplied, default path (/proc/cpuinfo) is used.
    '''
    fields = {}

    if cpuarch.is_ppc(cpuarch.real()):
        fields['flags'] = ['powernv']
    if cpuarch.is_x86(cpuarch.real()):
        fields['platform'] = 'unavailable'
        fields['machine'] = 'unavailable'
        fields['ppcmodel'] = 'unavailable'
    if cpuarch.is_arm(cpuarch.real()):
        fields['platform'] = 'unavailable'
        fields['machine'] = 'unavailable'
        fields['ppcmodel'] = 'unavailable'
    if cpuarch.is_s390(cpuarch.real()):
        fields['platform'] = 'unavailable'
        fields['machine'] = 'unavailable'
        fields['ppcmodel'] = 'unavailable'

    with open(_PATH) as info:
        for line in info:
            if not line.strip():
                continue

            key, value = [part.strip() for part in line.split(':', 1)]

            if key == 'flags':  # x86_64
                fields['flags'] = value.split()
            elif key == 'Features':  # aarch64
                fields['flags'] = value.split()
            elif key == 'features':  # s390
                fields['flags'] = value.split()
            elif key == 'cpu MHz':  # x86_64
                fields['frequency'] = value
            elif key == 'BogoMIPS':  # aarch64
                fields['frequency'] = value
            elif key == 'clock':  # ppc64, ppc64le
                fields['frequency'] = value[:-3]
            elif key == 'cpu MHz dynamic':  # s390
                # s390 reports both static and dynamic frequencies with
                # dynamic <= stat (nominal), so dynamic matches the
                # x86_64 frequency semantics.
                fields['frequency'] = value
            elif key == 'model name':  # x86_64
                fields['model'] = value
            elif key == 'CPU part':  # aarch64
                fields['model'] = value
            elif re.match(r'processor \d+', key):  # s390
                match = re.search(r'\bmachine\s*=\s*(\w+)', value)
                if match:
                    fields['model'] = match.group(1)
            elif key == 'model':  # ppc64le
                fields['ppcmodel'] = value
            elif key == 'cpu':  # ppc64, ppc64le
                fields['model'] = value
            elif key == 'platform':  # ppc64, ppc64le
                fields['platform'] = value
            elif key == 'machine':  # ppc64, ppc64le
                fields['machine'] = value

            if len(fields) == 6:
                break

        # Older s390 machine versions don't report frequency.
        if 'frequency' not in fields:
            fields['frequency'] = 'unavailable'

        return CpuInfo(**fields)
예제 #4
0
def _cpuinfo():
    '''
    Parse cpuinfo-like file, keeping the values in module's runtime variables.

    Arguments:

    source      Optional. Accepts a string indicating path to the cpuinfo-like
                file. If not supplied, default path (/proc/cpuinfo) is used.
    '''
    fields = {}

    if cpuarch.is_ppc(cpuarch.real()):
        fields['flags'] = ['powernv']
    if cpuarch.is_x86(cpuarch.real()):
        fields['platform'] = 'unavailable'
        fields['machine'] = 'unavailable'
        fields['ppcmodel'] = 'unavailable'
    if cpuarch.is_arm(cpuarch.real()):
        fields['platform'] = 'unavailable'
        fields['machine'] = 'unavailable'
        fields['ppcmodel'] = 'unavailable'
    if cpuarch.is_s390(cpuarch.real()):
        fields['platform'] = 'unavailable'
        fields['machine'] = 'unavailable'
        fields['ppcmodel'] = 'unavailable'

    with open(_PATH) as info:
        for line in info:
            if not line.strip():
                continue

            key, value = [part.strip() for part in line.split(':', 1)]

            if key == 'flags':  # x86_64
                fields['flags'] = value.split()
            elif key == 'Features':  # aarch64
                fields['flags'] = value.split()
            elif key == 'features':  # s390
                fields['flags'] = value.split()
            elif key == 'cpu MHz':  # x86_64
                fields['frequency'] = value
            elif key == 'BogoMIPS':  # aarch64
                fields['frequency'] = value
            elif key == 'clock':  # ppc64, ppc64le
                fields['frequency'] = value[:-3]
            elif key == 'cpu MHz dynamic':  # s390
                # s390 reports both static and dynamic frequencies with
                # dynamic <= stat (nominal), so dynamic matches the
                # x86_64 frequency semantics.
                fields['frequency'] = value
            elif key == 'model name':  # x86_64
                fields['model'] = value
            elif key == 'CPU part':  # aarch64
                fields['model'] = value
            elif re.match(r'processor \d+', key):  # s390
                match = re.search(r'\bmachine\s*=\s*(\w+)', value)
                if match:
                    fields['model'] = match.group(1)
            elif key == 'model':  # ppc64le
                fields['ppcmodel'] = value
            elif key == 'cpu':  # ppc64, ppc64le
                fields['model'] = value
            elif key == 'platform':  # ppc64, ppc64le
                fields['platform'] = value
            elif key == 'machine':  # ppc64, ppc64le
                fields['machine'] = value

            if len(fields) == 6:
                break

        # Older s390 machine versions don't report frequency.
        if 'frequency' not in fields:
            fields['frequency'] = 'unavailable'

        return CpuInfo(**fields)