예제 #1
0
def _fake_caps_arch(caps, arch):
    '''
    Mutate 'caps' to act as an architecture set by fake_kvm_architecture
    configuration option.

    Arguments:

    caps        The host capabilities as returned by hooking.read_json.
    '''
    arch = arch

    caps['kvmEnabled'] = True

    if cpuarch.is_x86(arch):
        caps['emulatedMachines'] = _X86_64_MACHINES
        caps['cpuModel'] = 'Intel(Fake) CPU'

        flag_list = ['vmx', 'sse2', 'nx']

        if cpuarch.real() == cpuarch.X86_64:
            flag_list += cpuinfo.flags()

        flags = set(flag_list)

        caps['cpuFlags'] = ','.join(flags) + ',model_486,model_pentium,' \
            'model_pentium2,model_pentium3,model_pentiumpro,' \
            'model_qemu32,model_coreduo,model_core2duo,model_n270,' \
            'model_Conroe,model_Penryn,model_Nehalem,model_Opteron_G1'
    elif cpuarch.is_ppc(arch):
        caps['emulatedMachines'] = _PPC64LE_MACHINES
        caps['cpuModel'] = 'POWER 8(fake)'
        caps['cpuFlags'] = 'powernv,model_POWER8'
    elif cpuarch.is_arm(arch):
        caps['emulatedMachines'] = _AARCH64_MACHINES
        caps['cpuModel'] = 'AARCH64 (fake)'
        caps['cpuFlags'] = ''
    else:
        raise cpuarch.UnsupportedArchitecture(arch)
예제 #2
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)
예제 #3
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)