From 931c77a86664d3cf4b576410ee404a971faf491e 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 04:58:31 +0900 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B0=D1=82=D1=87=20DHCP=20leases=20?= =?UTF-8?q?=D0=B1=D0=BE=D0=BB=D1=8C=D1=88=D0=B5=20=D0=BD=D0=B5=20=D0=B2?= =?UTF-8?q?=D0=B0=D0=BB=D0=B8=D0=BB=20=D1=83=D1=81=D1=82=D0=B0=D0=BD=D0=BE?= =?UTF-8?q?=D0=B2=D1=89=D0=B8=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/patch_dhcp_leases_empty.py | 55 ++++++++++++++++++------------ 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/scripts/patch_dhcp_leases_empty.py b/scripts/patch_dhcp_leases_empty.py index 61ddff9..5a7b0ec 100644 --- a/scripts/patch_dhcp_leases_empty.py +++ b/scripts/patch_dhcp_leases_empty.py @@ -4,18 +4,22 @@ import re import sys app_path = Path(sys.argv[1]) if len(sys.argv) > 1 else Path('/opt/virtuality/web/app.py') +changed: list[str] = [] +warnings: list[str] = [] + if not app_path.exists(): - raise SystemExit(f'app.py not found: {app_path}') + print(f'WARN: app.py not found: {app_path}') + raise SystemExit(0) dashboard_template_path = app_path.parent / 'templates' / 'dashboard.html' if not dashboard_template_path.exists(): - raise SystemExit(f'dashboard.html not found: {dashboard_template_path}') + print(f'WARN: dashboard.html not found: {dashboard_template_path}') + raise SystemExit(0) -changed: list[str] = [] text = app_path.read_text(encoding='utf-8') -# Remove helper blocks injected by older versions of this patch. They were too invasive -# and could leave stale references on servers that had several hotfixes applied. +# Older versions of this patch injected helper blocks. Remove them first so repeated +# installs stay deterministic and do not accumulate stale NETWORK_NAME references. text, removed_helpers = re.subn( r"\n\ndef parse_dhcp_leases_output\(output: str\).*?\n\ndef parse_virsh_list\(\) -> list\[dict\[str, str\]\]:", "\n\ndef parse_virsh_list() -> list[dict[str, str]]:", @@ -68,35 +72,42 @@ text, replaced = re.subn( count=1, flags=re.S, ) -if not replaced: - raise SystemExit('parse_virsh_list block not found') -changed.append('parse_virsh_list was replaced with a safe inline IP resolver') +if replaced: + changed.append('parse_virsh_list was replaced with a safe inline IP resolver') +else: + warnings.append('parse_virsh_list block not found, app.py IP injection skipped') app_path.write_text(text, encoding='utf-8') dashboard_html = dashboard_template_path.read_text(encoding='utf-8') + +header_old = 'IDNameStateActions' +header_new = 'IDNameIPStateActions' +name_cell = '''{{ vm.name }} + {{ vm.name }} + {{ vm.ip|default("—") }} + IP' not in dashboard_html: - dashboard_html = dashboard_html.replace( - 'IDNameStateActions', - 'IDNameIPStateActions' - ) - dashboard_html = dashboard_html.replace( - '{{ vm.name }}\n {{ vm.name }}\n {{ vm.ip|default(\'—\') }}\n Виртуальных машин пока нет', 'colspan="5" class="muted">Виртуальных машин пока нет') changed.append('Dashboard VM IP column was added') -elif "vm.ip" not in dashboard_html: - dashboard_html = dashboard_html.replace( - '{{ vm.name }}\n {{ vm.name }}\n {{ vm.ip|default(\'—\') }}\n