Skip to content

Commit

Permalink
Add a new QemuRemovable option to allow attaching the image to qemu a…
Browse files Browse the repository at this point in the history
…s removable

Add noqa for overlength line

Fix failing test

Rewrap QemuRemovable section on the man page to column 109
  • Loading branch information
pwicks86 committed Oct 10, 2024
1 parent 7b138bc commit 550618b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
9 changes: 9 additions & 0 deletions mkosi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,7 @@ class Config:
qemu_vsock_cid: int
qemu_swtpm: ConfigFeature
qemu_cdrom: bool
qemu_removable: bool
qemu_firmware: QemuFirmware
qemu_firmware_variables: Optional[Path]
qemu_kernel: Optional[Path]
Expand Down Expand Up @@ -3419,6 +3420,14 @@ def parse_ini(path: Path, only_sections: Collection[str] = ()) -> Iterator[tuple
parse=config_parse_boolean,
help="Attach the image as a CD-ROM to the virtual machine",
),
ConfigSetting(
dest="qemu_removable",
metavar="BOOLEAN",
nargs="?",
section="Host",
parse=config_parse_boolean,
help="Attach the image as a removable drive to the virtual machine",
),
ConfigSetting(
dest="qemu_firmware",
section="Host",
Expand Down
2 changes: 1 addition & 1 deletion mkosi/qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,7 +1282,7 @@ def add_virtiofs_mount(
cache = f"cache.writeback=on,cache.direct={yes_no(direct)},cache.no-flush={yes_no(ephemeral)},aio=io_uring" # noqa: E501
cmdline += [
"-drive", f"if=none,id=mkosi,file={fname},format=raw,discard=on,{cache}",
"-device", f"scsi-{'cd' if config.qemu_cdrom else 'hd'},drive=mkosi,bootindex=1",
"-device", f"scsi-{'cd' if config.qemu_cdrom else 'hd'},drive=mkosi,bootindex=1{',removable=on' if config.qemu_removable else ''}", # noqa: E501
] # fmt: skip

if config.qemu_swtpm == ConfigFeature.enabled or (
Expand Down
4 changes: 4 additions & 0 deletions mkosi/resources/man/mkosi.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,10 @@ boolean argument: either `1`, `yes`, or `true` to enable, or `0`, `no`,
attach the image to the virtual machine as a CD-ROM device. Takes a
boolean. Defaults to `no`.

`QemuRemovable=`, `--qemu-removable=`
: When used with the `qemu` verb, this option specifies whether to attach the image to the virtual machine
as a removable device. Takes a boolean. Defaults to `no`.

`QemuFirmware=`, `--qemu-firmware=`
: When used with the `qemu` verb, this option specifies which firmware
to use. Takes one of `uefi`, `uefi-secure-boot`, `bios`, `linux`, or
Expand Down
2 changes: 2 additions & 0 deletions tests/test_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ def test_config() -> None:
"QemuKernel": null,
"QemuKvm": "auto",
"QemuMem": 123,
"QemuRemovable": false,
"QemuSmp": 2,
"QemuSwtpm": "auto",
"QemuVsock": "enabled",
Expand Down Expand Up @@ -481,6 +482,7 @@ def test_config() -> None:
proxy_url="https://my/proxy",
qemu_args=[],
qemu_cdrom=False,
qemu_removable=False,
qemu_drives=[
QemuDrive("abc", 200, Path("/foo/bar"), "abc,qed", "red"),
QemuDrive("abc", 200, None, "", "wcd"),
Expand Down

0 comments on commit 550618b

Please sign in to comment.