]> git.ipfire.org Git - thirdparty/mkosi.git/commitdiff
Remove vmspawn verb in favor of VirtualMachineMonitor= setting
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Sat, 16 Mar 2024 19:04:36 +0000 (20:04 +0100)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Sun, 17 Mar 2024 08:19:54 +0000 (09:19 +0100)
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.

mkosi/__init__.py
mkosi/config.py
mkosi/resources/mkosi.md
tests/test_config.py
tests/test_json.py

index 67cc46d4342b40f5b52cc054fc9dde69a345a974..17e53743f0c3990e08d669898923fd878199a3e9 100644 (file)
@@ -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)
index 26030e68aa77df1bfcacf9c47828142916880b53..a38e668e30f611fb5c8f2409f7f8b0e0ccea70cd 100644 (file)
@@ -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:
index a6916d736c0ce063993388cdad7a006f262a08ed..ea1d173e086328f9d83f828ed4d1c93f97382c36 100644 (file)
@@ -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
index 3eb0dd815543877c8da1a010d7dc43ce6ddaac2e..a06c0e37f21a51ede24c859aa2ca3aafd6c6acd4 100644 (file)
@@ -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"])
 
index 1c0281928e879148f82bfa710bcae739e236ed6c..fdbbd151d35da0c423f78102974a90e75592c880 100644 (file)
@@ -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",