From b00fcfeada04ea3ba1bcd3e548815d7afbd10f4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D0=B8=D0=BA=D1=82=D0=BE=D1=80?= <78488229+viktor138irk@users.noreply.github.com> Date: Thu, 7 May 2026 07:50:35 +0900 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B0=D1=82=D1=87=20=D1=80=D0=B5=D1=81?= =?UTF-8?q?=D1=83=D1=80=D1=81=D0=BE=D0=B2=20VM=20=D0=B1=D1=8B=D0=BB=20?= =?UTF-8?q?=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BF=D0=BE=D1=80=D1=8F=D0=B4=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=83=D1=81=D1=82=D0=B0=D0=BD=D0=BE=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/patch_existing_vm_resources.py | 37 +++++++++++++++++++------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/scripts/patch_existing_vm_resources.py b/scripts/patch_existing_vm_resources.py index e3386bd..5ada047 100644 --- a/scripts/patch_existing_vm_resources.py +++ b/scripts/patch_existing_vm_resources.py @@ -49,9 +49,14 @@ def current_vm_arch(name: str) -> str: return (os_type.attrib.get("arch") if os_type is not None else "") or "unknown" +def vm_runtime_state(name: str) -> str: + result = run_cmd(["virsh", "domstate", name], timeout=8) + return (result.get("stdout") or "unknown").strip().lower() + + def vm_resource_settings(name: str) -> dict[str, Any]: dominfo = run_cmd(["virsh", "dominfo", name], timeout=10).get("stdout") or "" - state = (parse_dominfo_value(dominfo, "State") or vm_state(name)).lower() + state = (parse_dominfo_value(dominfo, "State") or vm_runtime_state(name)).lower() vcpus_raw = parse_dominfo_value(dominfo, "CPU(s)") used_memory_raw = parse_dominfo_value(dominfo, "Used memory") max_memory_raw = parse_dominfo_value(dominfo, "Max memory") @@ -147,15 +152,27 @@ else: changed.append('existing VM resources helpers already present') if '"resource_settings": vm_resource_settings(name)' not in text: - old = '"iso_message": request.query_params.get("iso_message", ""), "iso_error": request.query_params.get("iso_error", "")})' - new = '"iso_message": request.query_params.get("iso_message", ""), "iso_error": request.query_params.get("iso_error", ""), "resource_settings": vm_resource_settings(name), "resource_message": request.query_params.get("resource_message", ""), "resource_error": request.query_params.get("resource_error", "")})' - if old not in text: - old = '"host_ip": system_summary()["ip"]})' - new = '"host_ip": system_summary()["ip"], "resource_settings": vm_resource_settings(name), "resource_message": request.query_params.get("resource_message", ""), "resource_error": request.query_params.get("resource_error", "")})' - if old not in text: + replacements = [ + ( + '"iso_message": request.query_params.get("iso_message", ""), "iso_error": request.query_params.get("iso_error", "")})', + '"iso_message": request.query_params.get("iso_message", ""), "iso_error": request.query_params.get("iso_error", ""), "resource_settings": vm_resource_settings(name), "resource_message": request.query_params.get("resource_message", ""), "resource_error": request.query_params.get("resource_error", "")})', + ), + ( + '"boot_message": request.query_params.get("boot_message", ""), "boot_error": request.query_params.get("boot_error", "")})', + '"boot_message": request.query_params.get("boot_message", ""), "boot_error": request.query_params.get("boot_error", ""), "resource_settings": vm_resource_settings(name), "resource_message": request.query_params.get("resource_message", ""), "resource_error": request.query_params.get("resource_error", "")})', + ), + ( + '"host_ip": system_summary()["ip"]})', + '"host_ip": system_summary()["ip"], "resource_settings": vm_resource_settings(name), "resource_message": request.query_params.get("resource_message", ""), "resource_error": request.query_params.get("resource_error", "")})', + ), + ] + for old, new in replacements: + if old in text: + text = text.replace(old, new, 1) + changed.append('vm detail context gets resource settings') + break + else: raise SystemExit('vm detail context marker not found') - text = text.replace(old, new, 1) - changed.append('vm detail context gets resource settings') else: changed.append('vm detail context already has resource settings') @@ -174,6 +191,8 @@ def vm_resources_apply(request: Request, name: str, memory_mb: int = Form(...), if '@app.post("/vm/{name}/resources")' not in text: marker = '\n\n@app.post("/vm/{name}/boot-order")' + if marker not in text: + marker = '\n\n@app.post("/vm/{name}/iso/mount")' if marker not in text: marker = '\n\n@app.post("/vm/{name}/{action}")' if marker not in text: