diff --git a/gns3server/compute/qemu/qemu_vm.py b/gns3server/compute/qemu/qemu_vm.py index 23540e8c1..1f8029ab9 100644 --- a/gns3server/compute/qemu/qemu_vm.py +++ b/gns3server/compute/qemu/qemu_vm.py @@ -2070,16 +2070,12 @@ class QemuVM(KernelDatapathMixin, BaseNode): if external_console_port: return ["-serial", f"telnet:127.0.0.1:{internal_console_port},server,nowait"] - else: - return [] def _vnc_options(self, port): if port: vnc_port = port - 5900 # subtract by 5900 to get the display number - return ["-vnc", f"{self._manager.port_manager.console_host}:{vnc_port}"] - else: - return [] + return ["-vnc", f"{self._manager.port_manager.console_host}:{vnc_port}", "-device", "virtio-gpu-pci"] def _spice_options(self, port): @@ -2094,9 +2090,7 @@ class QemuVM(KernelDatapathMixin, BaseNode): console_host = "::" except OSError as e: raise QemuError(f"Could not check if IPv6 is enabled: {e}") - return ["-spice", f"addr={console_host},port={port},disable-ticketing=on", "-vga", "qxl"] - else: - return [] + return ["-spice", f"addr={console_host},port={port},disable-ticketing=on", "-device", "virtio-gpu-pci"] def _spice_with_agent_options(self, port): @@ -2124,17 +2118,29 @@ class QemuVM(KernelDatapathMixin, BaseNode): def _console_options(self): + console_options = [] if self._console_type in ("telnet", "ssh") and self._wrap_console: - return self._serial_options(self._internal_console_port, self.console) + console_options = self._serial_options(self._internal_console_port, self.console) elif self._console_type == "vnc": - return self._vnc_options(self.console) + console_options = self._vnc_options(self.console) elif self._console_type == "spice": - return self._spice_options(self.console) + console_options = self._spice_options(self.console) elif self._console_type == "spice+agent": - return self._spice_with_agent_options(self.console) + console_options = self._spice_with_agent_options(self.console) elif self._console_type != "none": raise QemuError(f"Console type {self._console_type} is unknown") - return [] + + if self._console_type in ("vnc", "spice"): + if self.platform == "aarch64": + # add a USB controller with a keyboard and mouse + console_options.extend( + ["-device", "qemu-xhci,id=usb", "-device", "usb-kbd,bus=usb.0", "-device", "usb-tablet,bus=usb.0"] + ) + else: + # avoiding mouse offset (see https://github.com/GNS3/gns3-server/issues/2335) + console_options.extend(["-machine", "usb=on", "-device", "usb-tablet"]) + + return console_options def _aux_options(self): @@ -2569,8 +2575,8 @@ class QemuVM(KernelDatapathMixin, BaseNode): raise QemuError(f"Cannot copy {vars_name} file to the node working directory: {e}") log.debug(f"Configuring UEFI boot mode using firmware file: '{firmware_path}'") - options.extend(["-drive", f"if=pflash,format=raw,readonly,file={firmware_path}"]) - options.extend(["-drive", f"if=pflash,format=raw,file={vars_node_path}"]) + options.extend(["-drive", f"file={firmware_path},if=pflash,unit=0,format=raw,readonly=on"]) + options.extend(["-drive", f"file={vars_node_path},if=pflash,unit=1,format=raw"]) # edk2 firmware requires a Random Number Generator (RNG) device in order to turn network adapters on options.extend(["-object", "rng-random,filename=/dev/urandom,id=rng0"]) @@ -2745,7 +2751,7 @@ class QemuVM(KernelDatapathMixin, BaseNode): Disable graphics for Qemu if no graphics options are specified. """ - if any(opt in self._options for opt in ["-display", "-nographic", "-curses", "-sdl-spice", "-vnc"]): + if any(opt in self._options for opt in ["-display", "-nographic", "-curses", "-sdl-spice", "-vnc", "-spice"]): return [] return ["-display", "none"] @@ -2925,6 +2931,13 @@ class QemuVM(KernelDatapathMixin, BaseNode): if await self._run_with_hardware_acceleration(self.qemu_path, self._options): command.extend(["-machine", "accel=kvm"]) kvm_enabled = True + else: + self.project.emit( + "log.warning", + { + "message": f'QEMU VM "{self._name}": KVM hardware acceleration is not available, performance will be reduced' + }, + ) command.extend(["-boot", f"order={self._boot_priority}"]) command.extend(self._cdrom_option()) command.extend(await self._disk_options()) @@ -2966,10 +2979,6 @@ class QemuVM(KernelDatapathMixin, BaseNode): ) command.extend(self._kvmclock_off_options(additional_opt_list)) command.extend(additional_opt_list) - - # avoiding mouse offset (see https://github.com/GNS3/gns3-server/issues/2335) - if self._console_type == "vnc": - command.extend(["-machine", "usb=on", "-device", "usb-tablet"]) return command def asdict(self): diff --git a/gns3server/schemas/controller/templates/qemu_templates.py b/gns3server/schemas/controller/templates/qemu_templates.py index 4976dd5fd..f8fbda2bf 100644 --- a/gns3server/schemas/controller/templates/qemu_templates.py +++ b/gns3server/schemas/controller/templates/qemu_templates.py @@ -95,7 +95,10 @@ class QemuTemplate(TemplateBase): False, description="Automatically create a config disk on HDD disk interface (secondary slave)" ) tpm: Optional[bool] = Field(False, description="Enable Trusted Platform Module (TPM)") - uefi: Optional[bool] = Field(False, description="Enable UEFI boot mode") + uefi: Optional[bool] = Field( + default_factory=lambda data: data.get("platform") == QemuPlatform.aarch64, + description="Enable UEFI boot mode", + ) on_close: Optional[QemuOnCloseAction] = Field( QemuOnCloseAction.power_off, description="Action to execute on the VM is closed" ) diff --git a/tests/compute/qemu/test_qemu_vm.py b/tests/compute/qemu/test_qemu_vm.py index 96b1d5e4f..24da240c8 100644 --- a/tests/compute/qemu/test_qemu_vm.py +++ b/tests/compute/qemu/test_qemu_vm.py @@ -455,9 +455,9 @@ async def test_uefi_boot_mode_option(vm, tmpdir, images_dir, fake_qemu_img_binar f.write("1") options = await vm._build_command() - assert " ".join(["-drive", f"if=pflash,format=raw,readonly,file={ovmf_code_path}"]) in " ".join(options) + assert " ".join(["-drive", f"file={ovmf_code_path},if=pflash,unit=0,format=raw,readonly=on"]) in " ".join(options) assert " ".join( - ["-drive", "if=pflash,format=raw,file={}".format(os.path.join(vm.working_dir, "OVMF_VARS_4M.fd"))] + ["-drive", f"file={os.path.join(vm.working_dir, 'OVMF_VARS_4M.fd')},if=pflash,unit=1,format=raw"] ) in " ".join(options) @@ -492,9 +492,9 @@ async def test_uefi_firmware_selection( vars_node_path = Path(vm.working_dir) / vars_name assert options == [ "-drive", - f"if=pflash,format=raw,readonly,file={code_path}", + f"file={code_path},if=pflash,unit=0,format=raw,readonly=on", "-drive", - f"if=pflash,format=raw,file={vars_node_path}", + f"file={vars_node_path},if=pflash,unit=1,format=raw", "-object", "rng-random,filename=/dev/urandom,id=rng0", "-device", @@ -534,9 +534,9 @@ async def test_uefi_existing_variables_store( options = vm._bios_option() assert options[:4] == [ "-drive", - f"if=pflash,format=raw,readonly,file={code_path}", + f"file={code_path},if=pflash,unit=0,format=raw,readonly=on", "-drive", - f"if=pflash,format=raw,file={vars_node_path}", + f"file={vars_node_path},if=pflash,unit=1,format=raw", ] assert vars_node_path.read_bytes() == b"existing variables" @@ -581,7 +581,7 @@ async def test_spice_option(vm, fake_qemu_img_binary): vm._console = 5905 options = await vm._build_command() assert "-spice addr=127.0.0.1,port=5905,disable-ticketing=on" in " ".join(options) - assert "-vga qxl" in " ".join(options) + assert "-device virtio-gpu-pci" in " ".join(options) @pytest.mark.asyncio