From daa60c8252d0e955acbfe9eaca52dbb272230d80 Mon Sep 17 00:00:00 2001 From: Wido den Hollander Date: Fri, 16 Oct 2026 12:06:03 +0000 Subject: [PATCH] kvm: only emit known video and CPU model names in the domain XML VideoDef now maps the video.hardware detail through an enum of the model types libvirt accepts, and CpuModeDef only accepts plain QEMU model names for guest.cpu.model. Unknown values are ignored with a warning and the agent default is used instead, like the agent already does for disk controllers, NIC models and the TPM. --- .../resource/LibvirtComputingResource.java | 31 ++++++--- .../hypervisor/kvm/resource/LibvirtVMDef.java | 63 ++++++++++++++++++- .../LibvirtComputingResourceTest.java | 43 ++++++++++++- .../kvm/resource/LibvirtVMDefTest.java | 31 +++++++++ 4 files changed, 156 insertions(+), 12 deletions(-) diff --git a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java index 7c3f826be171..4c3fc56b6843 100644 --- a/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java +++ b/plugins/hypervisors/kvm/src/main/java/com/cloud/hypervisor/kvm/resource/LibvirtComputingResource.java @@ -332,7 +332,7 @@ public class LibvirtComputingResource extends ServerResourceBase implements Serv private static final String KVMCLOCK = "kvmclock"; private static final String HYPERVCLOCK = "hypervclock"; private static final String WINDOWS = "Windows"; - private static final String X86_DEFAULT_VIDEO_MODEL = "vga"; + private static final VideoDef.VideoModel X86_DEFAULT_VIDEO_MODEL = VideoDef.VideoModel.VGA; private static final int X86_DEFAULT_VIDEO_RAM_KIB = 32768; private static final String Q35 = "q35"; private static final String PTY = "pty"; @@ -3352,26 +3352,35 @@ protected ConsoleDef createConsoleDef() { protected VideoDef createVideoDef(VirtualMachineTO vmTO) { Map details = vmTO.getDetails(); - String videoHw = this.videoHw; + VideoDef.VideoModel videoModel = VideoDef.VideoModel.fromString(this.videoHw); + if (videoModel == null && StringUtils.isNotBlank(this.videoHw)) { + LOGGER.warn("Ignoring unsupported video model '{}' from {}", this.videoHw, AgentProperties.VM_VIDEO_HARDWARE.getName()); + } int videoRam = this.videoRam; if (details != null) { if (details.containsKey(VmDetailConstants.VIDEO_HARDWARE)) { - videoHw = details.get(VmDetailConstants.VIDEO_HARDWARE); + String requested = details.get(VmDetailConstants.VIDEO_HARDWARE); + VideoDef.VideoModel requestedModel = VideoDef.VideoModel.fromString(requested); + if (requestedModel != null) { + videoModel = requestedModel; + } else { + LOGGER.warn("Ignoring unsupported {} '{}' of VM {}", VmDetailConstants.VIDEO_HARDWARE, requested, vmTO.getName()); + } } if (details.containsKey(VmDetailConstants.VIDEO_RAM)) { String value = details.get(VmDetailConstants.VIDEO_RAM); videoRam = NumbersUtil.parseInt(value, videoRam); } } - if (StringUtils.isBlank(videoHw) && isGuestX86(vmTO)) { + if (videoModel == null && isGuestX86(vmTO)) { // With no