Skip to content
Open
53 changes: 53 additions & 0 deletions lib/vdsm/aarch64HardwareInfo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# SPDX-FileCopyrightText: Red Hat, Inc.
# SPDX-License-Identifier: GPL-2.0-or-later


import logging
import os.path
import subprocess

from vdsm import cpuinfo
from vdsm.common import cache



def get_sys_info():

cmd = 'dmidecode -t system'
sys_info = {}
try:
output = subprocess.check_output(cmd, shell=True, universal_newlines=True)
for item in output.split("\n"):
if 'Manufacturer' in item or \
'Product Name' in item or \
'Version' in item or \
'Serial Number' in item or \
'UUID' in item or \
'Family' in item :
item = item.strip()
key = item.split(":")[0].strip()
value = item.split(":")[1].strip()
sys_info[key]=value

except:
logging.exception('Error while getting system information')

return sys_info




@cache.memoized
def getHardwareInfoStructure():
sys_info_dict=get_sys_info()


return {
'systemSerialNumber': sys_info_dict.get('Serial Number', 'unavailable'),
'systemFamily': sys_info_dict.get('Family', 'unavailable'),
'systemVersion': sys_info_dict.get('Version', 'unavailable'),
'systemUUID': sys_info_dict.get('UUID', 'unavailable'),
'systemProductName': sys_info_dict.get('Product Name', 'unavailable'),
'systemManufacturer': sys_info_dict.get('Manufacturer', 'unavailable'),
}

4 changes: 4 additions & 0 deletions lib/vdsm/machinetype.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from vdsm.common import cpuarch
from vdsm.common import libvirtconnection
from vdsm.common.config import config
from vdsm.validatehost import is_valid_virt_host


class _CpuMode:
Expand Down Expand Up @@ -146,12 +147,15 @@ def compatible_cpu_models():
compatible_models = [model for (model, usable)
in all_models.items()
if usable == 'yes']
logging.debug('Compatible CPU models: %s', compatible_models)
# Current QEMU doesn't report POWER compatibility modes, so we
# must add them ourselves.
if cpuarch.is_ppc(arch) and \
'POWER9' in compatible_models and \
'POWER8' not in compatible_models:
compatible_models.append('POWER8')
if cpuarch.is_arm(arch) and is_valid_virt_host():
compatible_models.append('virt_aarch64')
return list(set(["model_" + model for model in compatible_models]))


Expand Down
3 changes: 3 additions & 0 deletions lib/vdsm/supervdsm_api/hwinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ def getHardwareInfo(*args, **kwargs):
elif cpuarch.is_ppc(arch):
from vdsm.ppc64HardwareInfo import getHardwareInfoStructure
return getHardwareInfoStructure()
elif cpuarch.is_arm(arch):
from vdsm.aarch64HardwareInfo import getHardwareInfoStructure
return getHardwareInfoStructure()
else:
# not implemented over other architecture
return {}
Expand Down
49 changes: 49 additions & 0 deletions lib/vdsm/validatehost.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# SPDX-FileCopyrightText: Red Hat, Inc.
# SPDX-License-Identifier: GPL-2.0-or-later

import logging
import subprocess

VIRT_HOST_VALIDATE_CMD = "virt-host-validate"

def exec_validate_cmd(cmd):
"""Execute a command and convert returned values to native string.

Note that this function should not be used if output data could be
undecodable bytes.
"""
try:
out = subprocess.check_output(cmd).decode("utf-8")
except Exception as err:
logging.exception(f"Unexpected {err}, {type(err)}")

logging.info(f"output {out}")
return out

def is_valid_virt_host():
""" Validate host is valid for virtualization
Below is the command and output
If host is not valid, the failure will be logged
# virt-host-validate
QEMU: Checking if device /dev/kvm exists : PASS
QEMU: Checking if device /dev/kvm is accessible : PASS
QEMU: Checking if device /dev/vhost-net exists : PASS
QEMU: Checking if device /dev/net/tun exists : PASS
QEMU: Checking for cgroup 'cpu' controller support : PASS
QEMU: Checking for cgroup 'cpuacct' controller support : PASS
QEMU: Checking for cgroup 'cpuset' controller support : PASS
QEMU: Checking for cgroup 'memory' controller support : PASS
QEMU: Checking for cgroup 'devices' controller support : PASS
QEMU: Checking for cgroup 'blkio' controller support : PASS
QEMU: Checking for device assignment IOMMU support : WARN
QEMU: Checking for secure guest support : WARN

"""

out = exec_validate_cmd(VIRT_HOST_VALIDATE_CMD)
valid_host = False

if ('fail' not in out.lower()):
valid_host = True

return valid_host