From: Daan De Meyer Date: Sat, 16 Mar 2024 19:04:36 +0000 (+0100) Subject: Remove vmspawn verb in favor of VirtualMachineMonitor= setting X-Git-Tag: v23~85^2~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=94708ee0853b8ae2ebe334fb5d11f0fa1f072c04;p=thirdparty%2Fmkosi.git Remove vmspawn verb in favor of VirtualMachineMonitor= setting Instead of adding a new verb for each new virtual machine monitor we want to support, let's configure the vmm to use with a new setting. As vmspawn is still experimental we don't need to keep backwards compat intact in this case. --- diff --git a/mkosi/__init__.py b/mkosi/__init__.py index 67cc46d43..17e53743f 100644 --- a/mkosi/__init__.py +++ b/mkosi/__init__.py @@ -41,6 +41,7 @@ from mkosi.config import ( SecureBootSignTool, ShimBootloader, Verb, + Vmm, __version__, format_bytes, parse_config, @@ -2630,7 +2631,7 @@ def check_tools(config: Config, verb: Verb) -> None: if verb == Verb.boot: check_systemd_tool(config, "systemd-nspawn", version="254", reason="boot images") - if verb == Verb.vmspawn: + if verb == Verb.qemu and config.vmm == Vmm.vmspawn: check_systemd_tool(config, "systemd-vmspawn", version="256~devel", reason="boot images with vmspawn") @@ -4234,11 +4235,15 @@ def run_verb(args: Args, images: Sequence[Config], *, resources: Path) -> None: if args.verb in (Verb.shell, Verb.boot) else contextlib.nullcontext() ): + run_vm = { + Vmm.qemu: run_qemu, + Vmm.vmspawn: run_vmspawn, + }[last.vmm] + { Verb.shell: run_shell, Verb.boot: run_shell, - Verb.qemu: run_qemu, + Verb.qemu: run_vm, Verb.serve: run_serve, Verb.burn: run_burn, - Verb.vmspawn: run_vmspawn, }[args.verb](args, last) diff --git a/mkosi/config.py b/mkosi/config.py index 26030e68a..a38e668e3 100644 --- a/mkosi/config.py +++ b/mkosi/config.py @@ -72,7 +72,6 @@ class Verb(StrEnum): journalctl = enum.auto() coredumpctl = enum.auto() burn = enum.auto() - vmspawn = enum.auto() def supports_cmdline(self) -> bool: return self in ( @@ -84,7 +83,6 @@ class Verb(StrEnum): Verb.journalctl, Verb.coredumpctl, Verb.burn, - Verb.vmspawn, ) def needs_build(self) -> bool: @@ -95,7 +93,6 @@ class Verb(StrEnum): Verb.qemu, Verb.serve, Verb.burn, - Verb.vmspawn, ) def needs_root(self) -> bool: @@ -265,6 +262,11 @@ class Network(StrEnum): none = enum.auto() +class Vmm(StrEnum): + qemu = enum.auto() + vmspawn = enum.auto() + + class Architecture(StrEnum): alpha = enum.auto() arc = enum.auto() @@ -1371,6 +1373,7 @@ class Config: runtime_network: Network ssh_key: Optional[Path] ssh_certificate: Optional[Path] + vmm: Vmm # QEMU-specific options qemu_gui: bool @@ -2623,6 +2626,15 @@ SETTINGS = ( paths=("mkosi.crt",), help="Certificate for use with mkosi ssh in X509 format", ), + ConfigSetting( + dest="vmm", + name="VirtualMachineMonitor", + metavar="VMM", + section="Host", + parse=config_make_enum_parser(Vmm), + default=Vmm.qemu, + help="Set the virtual machine monitor to use for mkosi qemu", + ), ConfigSetting( dest="qemu_gui", metavar="BOOL", @@ -3725,6 +3737,7 @@ def summary(config: Config) -> str: SSH Signing Key: {none_to_none(config.ssh_key)} SSH Certificate: {none_to_none(config.ssh_certificate)} + Virtual Machine Monitor: {config.vmm} QEMU GUI: {yes_no(config.qemu_gui)} QEMU CPU Cores: {config.qemu_smp} QEMU Memory: {config.qemu_mem} @@ -3864,6 +3877,7 @@ def json_type_transformer(refcls: Union[type[Args], type[Config]]) -> Callable[[ Cacheonly: enum_transformer, Network: enum_transformer, KeySource: key_source_transformer, + Vmm: enum_transformer, } def json_transformer(key: str, val: Any) -> Any: diff --git a/mkosi/resources/mkosi.md b/mkosi/resources/mkosi.md index a6916d736..ea1d173e0 100644 --- a/mkosi/resources/mkosi.md +++ b/mkosi/resources/mkosi.md @@ -18,8 +18,6 @@ mkosi — Build Bespoke OS Images `mkosi [options…] qemu [qemu parameters…]` -`mkosi [options…] vmspawn [vmspawn settings…]` - `mkosi [options…] ssh [command line…]` `mkosi [options…] journalctl [command line…]` @@ -83,21 +81,12 @@ The following command line verbs are known: `qemu` -: Similar to `boot`, but uses `qemu` to boot up the image, i.e. instead - of container virtualization virtual machine virtualization is used. - This verb is only supported for disk images that contain a boot loader - and cpio images in which a kernel was installed. For cpio images a - kernel can also be provided by passing the `-kernel` qemu argument to - the `qemu` verb. Any arguments specified after the `qemu` verb are - appended to the `qemu` invocation. - -`vmspawn` - -: Similar to `boot`, but uses `systemd-vmspawn` to boot up the image, i.e. - instead of container virtualization virtual machine virtualization is used. - This verb is only supported for disk and directory type images. - Any arguments specified after the `vmspawn` verb are appended to the - `systemd-vmspawn` invocation. +: Similar to `boot`, but uses the configured virtual machine monitor (by + default `qemu`) to boot up the image, i.e. instead of container + virtualization virtual machine virtualization is used. How extra + command line arguments are interpreted depends on the configured + virtual machine monitor. See `VirtualMachineMonitor=` for more + information. `ssh` @@ -1450,6 +1439,22 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`, : List of colon-separated paths to look for tools in, before using the regular `$PATH` search path. +`VirtualMachineMonitor=`, `--vmm=` + +: Configures the virtual machine monitor to use. Takes one of `qemu` or + `vmspawn`. Defaults to `qemu`. + +: When set to `qemu`, the image is booted with `qemu`. Most output + formats can be booted in `qemu`. Any arguments specified after the + verb are appended to the `qemu` invocation and are interpreted as + extra qemu command line arguments. + +: When set to `vmspawn`, `systemd-vmspawn` is used to boot up the image, + `vmspawn` only supports disk and directory type images. Any arguments + specified after the verb are appended to the `systemd-vmspawn` + invocation and are interpreted as extra vmspawn options and extra + kernel command line arguments. + `QemuGui=`, `--qemu-gui=` : If enabled, qemu is executed with its graphical interface instead of diff --git a/tests/test_config.py b/tests/test_config.py index 3eb0dd815..a06c0e37f 100644 --- a/tests/test_config.py +++ b/tests/test_config.py @@ -318,7 +318,6 @@ def test_parse_load_verb(tmp_path: Path) -> None: assert parse_config(["qemu"])[0].verb == Verb.qemu assert parse_config(["journalctl"])[0].verb == Verb.journalctl assert parse_config(["coredumpctl"])[0].verb == Verb.coredumpctl - assert parse_config(["vmspawn"])[0].verb == Verb.vmspawn with pytest.raises(SystemExit): parse_config(["invalid"]) diff --git a/tests/test_json.py b/tests/test_json.py index 1c0281928..fdbbd151d 100644 --- a/tests/test_json.py +++ b/tests/test_json.py @@ -29,6 +29,7 @@ from mkosi.config import ( SecureBootSignTool, ShimBootloader, Verb, + Vmm, ) from mkosi.distributions import Distribution from mkosi.versioncomp import GenericVersion @@ -311,6 +312,7 @@ def test_config() -> None: "source": "", "type": "file" }, + "VirtualMachineMonitor": "qemu", "WithDocs": true, "WithNetwork": false, "WithRecommends": true, @@ -349,6 +351,7 @@ def test_config() -> None: extra_trees = [], finalize_scripts = [], hostname = None, + vmm = Vmm.qemu, image = "default", image_id = "myimage", image_version = "5",