From b567f0548f4fb4803ffbd06cd404f45cdc701c3f 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 10:09:10 +0900 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B0=D1=82=D1=87=D0=B5=D1=80=20=D1=80?= =?UTF-8?q?=D0=B5=D1=81=D1=83=D1=80=D1=81=D0=BE=D0=B2=20=D1=81=D1=83=D1=89?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=B2=D1=83=D1=8E=D1=89=D0=B8=D1=85=20VM=20?= =?UTF-8?q?=D0=B1=D1=8B=D0=BB=20=D0=B7=D0=B0=D1=89=D0=B8=D1=89=D1=91=D0=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/patch_existing_vm_resources.py | 48 ++++++++++++-------------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/scripts/patch_existing_vm_resources.py b/scripts/patch_existing_vm_resources.py index 5ada047..8f3ee26 100644 --- a/scripts/patch_existing_vm_resources.py +++ b/scripts/patch_existing_vm_resources.py @@ -7,6 +7,7 @@ if not app_path.exists(): raise SystemExit(f'app.py not found: {app_path}') changed = [] +warnings = [] text = app_path.read_text() if 'import tempfile' not in text: @@ -144,27 +145,19 @@ def apply_vm_resources(name: str, memory_mb: int, vcpus: int, guest_arch: str) - if 'def apply_vm_resources(name: str, memory_mb: int, vcpus: int, guest_arch: str)' not in text: marker = '\n\ndef vm_details(name: str) -> dict[str, Any]:' - if marker not in text: - raise SystemExit('vm_details marker not found') - text = text.replace(marker, helpers + marker, 1) - changed.append('existing VM resources helpers added') + if marker in text: + text = text.replace(marker, helpers + marker, 1) + changed.append('existing VM resources helpers added') + else: + warnings.append('vm_details marker not found, helpers skipped') else: changed.append('existing VM resources helpers already present') if '"resource_settings": vm_resource_settings(name)' 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", "")})', - ), + ('"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: @@ -172,7 +165,7 @@ if '"resource_settings": vm_resource_settings(name)' not in text: changed.append('vm detail context gets resource settings') break else: - raise SystemExit('vm detail context marker not found') + warnings.append('vm detail context marker not found, resource context skipped') else: changed.append('vm detail context already has resource settings') @@ -190,15 +183,14 @@ 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: - raise SystemExit('vm action marker not found') - text = text.replace(marker, route + marker, 1) - changed.append('existing VM resources route added') + markers = ['\n\n@app.post("/vm/{name}/boot-order")', '\n\n@app.post("/vm/{name}/iso/mount")', '\n\n@app.post("/vm/{name}/{action}")'] + for marker in markers: + if marker in text: + text = text.replace(marker, route + marker, 1) + changed.append('existing VM resources route added') + break + else: + warnings.append('vm action marker not found, resources route skipped') else: changed.append('existing VM resources route already present') @@ -207,3 +199,7 @@ app_path.write_text(text) print('existing VM resources patch applied:') for item in changed: print(f'- {item}') +if warnings: + print('Warnings:') + for item in warnings: + print(f'- {item}')