Files
ProxMenux/oci/src/proxmenux_oci/host.py
T
MacRimiandClaude Opus 5 bcabcb618c feat(oci): run official container images as native LXC containers
Adds the OCI manager: an engine that turns a Docker Compose file into an
LXC definition, a catalog of 365 applications drawn from LinuxServer.io
and other container image sources, and a per-instance registry recording
what each container was built from. Reachable from the main menu.

Catalog text is translated like every other string in the project: the
taglines go through translate() and land in lang/*.json, so the entries
read in all eight languages instead of only English.

Translation cache builder:
- a failed translation leaves the key absent rather than writing English,
  which previously made the string count as translated forever
- a result identical to a 3+ word source is rejected, catching a provider
  that silently returns the text it was given
- strings that are nothing but glossary terms keep their source spelling
  instead of being discarded as failures
- no backoff between attempts when the provider is deterministic
- application names are protected so "HAOS One" survives translation
- argos joins the provider list, and the workflow reads the OCI sources

Audit & Report:
- findings that moved in the wrong direction between runs are reported
  alongside the ones that improved
- an accepted risk can carry a review date and is flagged when it falls due
- backup checks explain in plain language what they looked at and what to
  do next

Monitor:
- disks can be excluded from periodic reads, and an idle disk says so
  instead of showing a stale temperature
- per-disk identity survives a controller or enclosure change
- scheduled Borg backups resolve their SSH key from the repository entry
- PVE upgrades log the package list and the resulting dpkg changes

The web build no longer copies scripts/ into public/: the documentation
links to GitHub, so nothing read that folder.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-09-22 18:24:59 +02:00

83 lines
2.9 KiB
Python

"""Facts read from the local Proxmox node: storages, bridges and the timezone."""
from __future__ import annotations
import ipaddress
import json
import subprocess
from pathlib import Path
from typing import Any
def _pvesh(path: str, *arguments: str) -> list[dict[str, Any]]:
try:
result = subprocess.run(["pvesh", "get", path, "--output-format", "json", *arguments],
capture_output=True, text=True, timeout=30, check=False)
rows = json.loads(result.stdout) if result.returncode == 0 else []
except (OSError, ValueError, subprocess.TimeoutExpired):
return []
return [row for row in rows if isinstance(row, dict)] if isinstance(rows, list) else []
def storages(content: str) -> list[dict[str, Any]]:
"""Active storages of this node that accept `content` (rootdir, vztmpl, ...),
the one with most free space first."""
rows = [row for row in _pvesh("/nodes/localhost/storage", "--content", content, "--enabled", "1")
if row.get("active") and row.get("storage")]
return sorted(rows, key=lambda row: -(row.get("avail") or 0))
def default_storage(content: str, preferred: str) -> str:
names = [row["storage"] for row in storages(content)]
if preferred in names or not names:
return preferred
return names[0]
# Private networks that ProxMenux creates for multi-container applications.
PRIVATE_STACK_NETWORK = ipaddress.ip_network("10.77.0.0/16")
def _private_stack_bridge(row: dict[str, Any]) -> bool:
if row.get("bridge_ports") or not row.get("cidr"):
return False
try:
return ipaddress.ip_interface(row["cidr"]).network.subnet_of(PRIVATE_STACK_NETWORK)
except (TypeError, ValueError):
return False
def bridges(include_private: bool = False) -> list[dict[str, Any]]:
"""Bridges of this node; the private networks of multi-container
applications are left out unless `include_private` is set."""
rows = [row for row in _pvesh("/nodes/localhost/network", "--type", "any_bridge") if row.get("iface")
and (include_private or not _private_stack_bridge(row))]
return sorted(rows, key=lambda row: row["iface"])
def default_bridge(preferred: str) -> str:
names = [row["iface"] for row in bridges()]
if preferred in names or not names:
return preferred
return names[0]
def timezone() -> str:
try:
value = Path("/etc/timezone").read_text(encoding="utf-8").strip()
except OSError:
value = ""
if not value:
try:
value = subprocess.run(["timedatectl", "show", "-p", "Timezone", "--value"],
capture_output=True, text=True, timeout=10, check=False).stdout.strip()
except (OSError, subprocess.TimeoutExpired):
value = ""
return value or "Etc/UTC"
def gib(value: Any) -> int:
try:
return int(value) // 2**30
except (TypeError, ValueError):
return 0