Files
virtuality/web/catalog.py
T
Claude 1e29134fb3 Подготовка к 0.11: общий модуль core.py, каталог облачных образов, образцы вывода virsh
- web/core.py: настройки, авторизация, run_cmd, хранилище фоновых операций
  и шаблоны вынесены в общий модуль, чтобы новые функции жили в отдельных
  модулях; app.py пока не переключён;
- web/catalog.py: официальные облачные образы Ubuntu 26.04/24.04,
  Debian 13, Alpine 3.23 (amd64/arm64) и типы ОС для установки с ISO;
- tests/fixtures: реалистичный вывод virsh для тестов будущих парсеров;
- presenters.format_bytes.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019LEUXMcdZo7b87mjkUsPgg
2026-09-25 14:04:11 +00:00

83 строки
4.6 KiB
Python

"""Catalog of ready-to-run cloud images for the quick VM flow.
Each entry points to the vendor's official cloud image. Images boot in seconds
and are configured through cloud-init (user, password, SSH key) — no installer.
"""
from typing import Any
# osinfo ids must exist in osinfo-db shipped with Ubuntu 24.04+/Debian 13.
CLOUD_IMAGES: list[dict[str, Any]] = [
{
"id": "ubuntu-26.04",
"title": "Ubuntu Server 26.04 LTS",
"vendor": "Ubuntu",
"hint": "Самая свежая LTS, поддержка до 2031 года. Рекомендуем.",
"osinfo": "ubuntu24.04",
"recommended": True,
"login": "ubuntu",
"arches": {
"x86_64": {"url": "https://cloud-images.ubuntu.com/resolute/current/resolute-server-cloudimg-amd64.img", "sums": "https://cloud-images.ubuntu.com/resolute/current/SHA256SUMS", "algo": "sha256"},
"aarch64": {"url": "https://cloud-images.ubuntu.com/resolute/current/resolute-server-cloudimg-arm64.img", "sums": "https://cloud-images.ubuntu.com/resolute/current/SHA256SUMS", "algo": "sha256"},
},
},
{
"id": "ubuntu-24.04",
"title": "Ubuntu Server 24.04 LTS",
"vendor": "Ubuntu",
"hint": "Проверенная LTS, поддержка до 2029 года.",
"osinfo": "ubuntu24.04",
"login": "ubuntu",
"arches": {
"x86_64": {"url": "https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img", "sums": "https://cloud-images.ubuntu.com/noble/current/SHA256SUMS", "algo": "sha256"},
"aarch64": {"url": "https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-arm64.img", "sums": "https://cloud-images.ubuntu.com/noble/current/SHA256SUMS", "algo": "sha256"},
},
},
{
"id": "debian-13",
"title": "Debian 13",
"vendor": "Debian",
"hint": "Лёгкий и стабильный. Хорош для домашних сервисов.",
"osinfo": "debian13",
"login": "debian",
"arches": {
"x86_64": {"url": "https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-amd64.qcow2", "sums": "https://cloud.debian.org/images/cloud/trixie/latest/SHA512SUMS", "algo": "sha512"},
"aarch64": {"url": "https://cloud.debian.org/images/cloud/trixie/latest/debian-13-genericcloud-arm64.qcow2", "sums": "https://cloud.debian.org/images/cloud/trixie/latest/SHA512SUMS", "algo": "sha512"},
},
},
{
"id": "alpine-3.23",
"title": "Alpine Linux 3.23",
"vendor": "Alpine",
"hint": "Очень маленький: 200 МБ на диске, стартует мгновенно.",
"osinfo": "alpinelinux3.21",
"login": "alpine",
"arches": {
"x86_64": {"url": "https://dl-cdn.alpinelinux.org/alpine/v3.23/releases/cloud/nocloud_alpine-3.23.0-x86_64-uefi-cloudinit-r0.qcow2", "sums": "https://dl-cdn.alpinelinux.org/alpine/v3.23/releases/cloud/nocloud_alpine-3.23.0-x86_64-uefi-cloudinit-r0.qcow2.sha512", "algo": "sha512", "uefi": True},
"aarch64": {"url": "https://dl-cdn.alpinelinux.org/alpine/v3.23/releases/cloud/nocloud_alpine-3.23.0-aarch64-uefi-cloudinit-r0.qcow2", "sums": "https://dl-cdn.alpinelinux.org/alpine/v3.23/releases/cloud/nocloud_alpine-3.23.0-aarch64-uefi-cloudinit-r0.qcow2.sha512", "algo": "sha512", "uefi": True},
},
},
]
# OS families for the "install from ISO" flow. virt-install picks the right
# virtual hardware from osinfo: Windows gets SATA/e1000e (works without extra
# drivers), win11 additionally gets UEFI + TPM.
OS_TYPES: list[dict[str, Any]] = [
{"id": "linux", "title": "Linux", "hint": "Ubuntu, Debian, Fedora и другие", "osinfo": "detect=on,require=off"},
{"id": "windows11", "title": "Windows 11 / Server 2025", "hint": "Нужны UEFI и TPM — включим сами", "osinfo": "win11"},
{"id": "windows10", "title": "Windows 10 / Server 2019–2022", "hint": "Классическая загрузка", "osinfo": "win10"},
{"id": "other", "title": "Другая система", "hint": "FreeBSD, старые ОС, экзотика", "osinfo": "generic"},
]
def cloud_image(image_id: str) -> dict[str, Any] | None:
return next((item for item in CLOUD_IMAGES if item["id"] == image_id), None)
def os_type(type_id: str) -> dict[str, Any]:
return next((item for item in OS_TYPES if item["id"] == type_id), OS_TYPES[0])
def image_filename(entry: dict[str, Any], arch: str) -> str:
url = entry["arches"][arch]["url"]
return url.rsplit("/", 1)[-1]