fix: bake talos iso on proxmox host
This commit is contained in:
parent
f854710025
commit
d80b469e57
|
|
@ -7,7 +7,6 @@ import shutil
|
||||||
import ssl
|
import ssl
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import tempfile
|
|
||||||
import time
|
import time
|
||||||
import urllib.error
|
import urllib.error
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
@ -90,65 +89,39 @@ def wait_for_storage_content(base_url, token, node, storage, filename):
|
||||||
raise RuntimeError(f"timed out waiting for {filename} to appear in {node}/{storage}")
|
raise RuntimeError(f"timed out waiting for {filename} to appear in {node}/{storage}")
|
||||||
|
|
||||||
|
|
||||||
def detect_proxmox_iso_dir(storage):
|
def run_ssh(node, script):
|
||||||
candidates = [
|
ssh = shutil.which("ssh")
|
||||||
Path("/var/lib/vz/template/iso"),
|
if ssh is None:
|
||||||
Path("C:/var/lib/vz/template/iso"),
|
raise RuntimeError("ssh is required to customize Talos ISO on the Proxmox host")
|
||||||
]
|
subprocess.run([ssh, f"root@{node}", script], check=True)
|
||||||
for candidate in candidates:
|
|
||||||
if candidate.exists():
|
|
||||||
return candidate
|
|
||||||
raise RuntimeError(f"unable to find ISO directory for storage '{storage}'")
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def build_custom_iso(base_url, token, node, storage, source_filename, output_filename, network_config_path):
|
def build_custom_iso(base_url, token, node, storage, source_filename, output_filename, network_config_path):
|
||||||
iso_dir = detect_proxmox_iso_dir(storage)
|
|
||||||
storage_path = iso_dir / source_filename
|
|
||||||
output_path = iso_dir / output_filename
|
|
||||||
network_config = Path(network_config_path).read_text(encoding="utf-8").strip()
|
network_config = Path(network_config_path).read_text(encoding="utf-8").strip()
|
||||||
installer_meta = base64.b64encode(gzip.compress(f"0xa={network_config}".encode("utf-8"), compresslevel=9)).decode("ascii")
|
installer_meta = base64.b64encode(gzip.compress(f"0xa={network_config}".encode("utf-8"), compresslevel=9)).decode("ascii")
|
||||||
|
|
||||||
xorriso = shutil.which("xorriso")
|
script = (
|
||||||
if xorriso is None:
|
"set -eu; "
|
||||||
raise RuntimeError("xorriso is required to build Talos ISO with embedded META")
|
f"SRC='/var/lib/vz/template/iso/{source_filename}'; "
|
||||||
|
f"OUT='/var/lib/vz/template/iso/{output_filename}'; "
|
||||||
with tempfile.TemporaryDirectory() as temp_dir:
|
"TMPDIR=$(mktemp -d); trap 'rm -rf \"$TMPDIR\"' EXIT; "
|
||||||
temp_path = Path(temp_dir)
|
"xorriso -osirrox on -indev \"$SRC\" -extract / \"$TMPDIR/extract\" >/dev/null 2>&1; "
|
||||||
extract_dir = temp_path / "extract"
|
"for CFG in \"$TMPDIR/extract/isolinux/isolinux.cfg\" \"$TMPDIR/extract/boot/grub/grub.cfg\"; do "
|
||||||
extract_dir.mkdir()
|
" if [ -f \"$CFG\" ]; then "
|
||||||
output_tmp = temp_path / output_filename
|
f" sed -i '0,/---/s// talos.environment=INSTALLER_META_BASE64={installer_meta} ---/' \"$CFG\"; "
|
||||||
|
" fi; "
|
||||||
subprocess.run([xorriso, "-osirrox", "on", "-indev", str(storage_path), "-extract", "/", str(extract_dir)], check=True)
|
"done; "
|
||||||
|
"xorriso -as mkisofs "
|
||||||
isolinux_cfg = extract_dir / "isolinux" / "isolinux.cfg"
|
"-o \"$OUT\" "
|
||||||
grub_cfg = extract_dir / "boot" / "grub" / "grub.cfg"
|
"-isohybrid-mbr \"$TMPDIR/extract/isolinux/isohdpfx.bin\" "
|
||||||
append = f" talos.environment=INSTALLER_META_BASE64={installer_meta}"
|
"-c isolinux/boot.cat "
|
||||||
for cfg in (isolinux_cfg, grub_cfg):
|
"-b isolinux/isolinux.bin "
|
||||||
if cfg.exists():
|
"-no-emul-boot -boot-load-size 4 -boot-info-table "
|
||||||
text = cfg.read_text(encoding="utf-8")
|
"-eltorito-alt-boot -e EFI/BOOT/BOOTX64.EFI -no-emul-boot -isohybrid-gpt-basdat "
|
||||||
text = text.replace("---", f"{append} ---", 1)
|
"-V TALOS \"$TMPDIR/extract\" >/dev/null 2>&1"
|
||||||
cfg.write_text(text, encoding="utf-8")
|
)
|
||||||
|
run_ssh(node, script)
|
||||||
subprocess.run([
|
|
||||||
xorriso,
|
|
||||||
"-as", "mkisofs",
|
|
||||||
"-o", str(output_tmp),
|
|
||||||
"-isohybrid-mbr", str(extract_dir / "isolinux" / "isohdpfx.bin"),
|
|
||||||
"-c", "isolinux/boot.cat",
|
|
||||||
"-b", "isolinux/isolinux.bin",
|
|
||||||
"-no-emul-boot",
|
|
||||||
"-boot-load-size", "4",
|
|
||||||
"-boot-info-table",
|
|
||||||
"-eltorito-alt-boot",
|
|
||||||
"-e", "EFI/BOOT/BOOTX64.EFI",
|
|
||||||
"-no-emul-boot",
|
|
||||||
"-isohybrid-gpt-basdat",
|
|
||||||
"-V", "TALOS",
|
|
||||||
str(extract_dir),
|
|
||||||
], check=True)
|
|
||||||
|
|
||||||
shutil.copyfile(output_tmp, output_path)
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue