UI: Added process executor. Display vm status correctly in list. | CLI: Added get_qemu_version(), fixed virtio audio bug.

This commit is contained in:
Qubasa
2023-12-26 18:02:43 +01:00
parent 4d8c20f284
commit ca265b0c59
11 changed files with 219 additions and 105 deletions

View File

@@ -16,8 +16,9 @@ def url_ok(url: str) -> None:
try:
# Open the URL and get the response object
res = urllib.request.urlopen(req)
# Return True if the status code is 200 (OK)
if not res.status_code == 200:
if not res.getcode() == 200:
raise ClanError(f"URL has status code: {res.status_code}")
except urllib.error.URLError as ex:
raise ClanError(f"URL error: {ex}")

View File

@@ -38,7 +38,7 @@ def inspect_flake(flake_url: str | Path, flake_attr: str) -> FlakeConfig:
]
)
proc = subprocess.run(cmd, text=True, capture_output=True)
proc = subprocess.run(cmd, text=True, stdout=subprocess.PIPE)
assert proc.stdout is not None
if proc.returncode != 0:
raise ClanError(
@@ -47,8 +47,6 @@ command: {shlex.join(cmd)}
exit code: {proc.returncode}
stdout:
{proc.stdout}
stderr:
{proc.stderr}
"""
)
res = proc.stdout.strip()

View File

@@ -22,7 +22,7 @@ def list_machines(flake_url: Path | str) -> list[str]:
"--json",
]
)
proc = subprocess.run(cmd, text=True, capture_output=True)
proc = subprocess.run(cmd, text=True, stdout=subprocess.PIPE)
assert proc.stdout is not None
if proc.returncode != 0:
raise ClanError(
@@ -31,8 +31,6 @@ command: {shlex.join(cmd)}
exit code: {proc.returncode}
stdout:
{proc.stdout}
stderr:
{proc.stderr}
"""
)
res = proc.stdout.strip()

View File

@@ -18,8 +18,29 @@ from .inspect import VmConfig, inspect_vm
log = logging.getLogger(__name__)
def get_qemu_version() -> list[int]:
# Run the command and capture the output
output = subprocess.check_output(["qemu-kvm", "--version"])
# Decode the output from bytes to string
output_str = output.decode("utf-8")
# Split the output by newline and get the first line
first_line = output_str.split("\n")[0]
# Split the first line by space and get the third element
version = first_line.split(" ")[3]
# Split the version by dot and convert each part to integer
version_list = [int(x) for x in version.split(".")]
# Return the version as a list of integers
return version_list
def graphics_options(vm: VmConfig) -> list[str]:
common = ["-audio", "driver=pa,model=virtio"]
common: list[str] = []
# Check if the version is greater than 8.1.3 to enable virtio audio
if get_qemu_version() > [8, 1, 3]:
common = ["-audio", "driver=pa,model=virtio"]
if vm.wayland:
# fmt: off
return [