diff --git a/scripts/patch_existing_vm_iso_mount.py b/scripts/patch_existing_vm_iso_mount.py index 3ac1e95..de0a185 100644 --- a/scripts/patch_existing_vm_iso_mount.py +++ b/scripts/patch_existing_vm_iso_mount.py @@ -112,7 +112,6 @@ if '"current_iso": current_vm_iso(name)' not in text: old = '"boot_message": request.query_params.get("boot_message", ""), "boot_error": request.query_params.get("boot_error", "")})' new = '"boot_message": request.query_params.get("boot_message", ""), "boot_error": request.query_params.get("boot_error", ""), "isos": list_iso_files(), "current_iso": current_vm_iso(name), "iso_message": request.query_params.get("iso_message", ""), "iso_error": request.query_params.get("iso_error", "")})' if old not in text: - # Fallback for installations without boot-order patch context yet. old = '"host_ip": system_summary()["ip"]})' new = '"host_ip": system_summary()["ip"], "isos": list_iso_files(), "current_iso": current_vm_iso(name), "iso_message": request.query_params.get("iso_message", ""), "iso_error": request.query_params.get("iso_error", "")})' if old not in text: @@ -157,19 +156,85 @@ else: app_path.write_text(text) +iso_card = r''' +
+
+

ISO-привод

+ cdrom +
+ {% if current_iso %} +
Сейчас подключен ISO: {{ current_iso }}
+ {% else %} +
ISO сейчас не подключён.
+ {% endif %} +
+ + +
+
+ +
+ {% if not isos %} +
ISO-образов пока нет. Сначала загрузи .iso в разделе ISO.
+ {% endif %} +

Для запущенной VM ISO подключается live и сохраняется в конфигурации. Для выключенной VM ISO будет доступен при следующем старте.

+
+''' + +boot_card = r''' +
+
+

Порядок загрузки

+ boot order +
+
+ + +
+

Чтобы загрузиться с ISO, выбери “Сначала ISO/CD-ROM, потом диск”. Если VM запущена, новый порядок сработает после перезапуска.

+
+''' + if template_path.exists(): tpl = template_path.read_text() original = tpl - if 'action="/vm/{{ vm.name }}/iso/mount"' not in tpl: - block = r''' - - {% if iso_message %} -
{{ iso_message }}
- {% endif %} - {% if iso_error %} -
{{ iso_error }}
- {% endif %} + # Normalize legacy separate cards into one two-column settings grid. + legacy_boot = r''' +
+
+

Порядок загрузки

+ boot order +
+
+ + +
+

Настройка меняет XML-конфигурацию VM через virsh define. Если машина сейчас запущена, новый порядок загрузки сработает после перезапуска.

+
+''' + legacy_iso = r'''

ISO-привод

@@ -200,11 +265,28 @@ if template_path.exists():

Для запущенной VM ISO подключается live и сохраняется в конфигурации. Для выключенной VM ISO будет доступен при следующем старте. Чтобы загрузиться с ISO, выставь порядок загрузки “Сначала ISO/CD-ROM, потом диск”.

''' - marker = '\n\n
' - if marker not in tpl: - raise SystemExit('vm detail grid marker not found') - tpl = tpl.replace(marker, block + marker, 1) - changed.append('ISO mount card added to vm_detail.html') + settings_grid = r''' + +
+''' + iso_card + boot_card + r'''
+''' + + if 'vm-boot-iso-grid' not in tpl: + if legacy_boot in tpl or legacy_iso in tpl: + tpl = tpl.replace(legacy_boot, '') + tpl = tpl.replace(legacy_iso, '') + marker = '\n\n
' + if marker not in tpl: + raise SystemExit('vm detail grid marker not found') + tpl = tpl.replace(marker, settings_grid + marker, 1) + changed.append('ISO and boot order cards moved into two-column grid') + elif 'action="/vm/{{ vm.name }}/iso/mount"' not in tpl: + marker = '\n\n
' + if marker not in tpl: + raise SystemExit('vm detail grid marker not found') + tpl = tpl.replace(marker, settings_grid + marker, 1) + changed.append('ISO and boot order two-column grid added') + if tpl != original: template_path.write_text(tpl)