From 1357a918dfc308d7f648624f910743d4288dd448 Mon Sep 17 00:00:00 2001 From: eding Date: Sun, 19 Jul 2026 11:22:39 +0200 Subject: [PATCH] fix: wait for talos iso download --- terraform/scripts/stage_talos_image.py | 29 ++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/terraform/scripts/stage_talos_image.py b/terraform/scripts/stage_talos_image.py index 35dcf07..5ca766f 100644 --- a/terraform/scripts/stage_talos_image.py +++ b/terraform/scripts/stage_talos_image.py @@ -3,6 +3,7 @@ import json import os import sys import ssl +import time import urllib.error import urllib.parse import urllib.request @@ -30,12 +31,36 @@ def ensure_image(base_url, token, node, storage, image_url, filename): return filename, False download_path = f"/api2/json/nodes/{node}/storage/{storage}/download-url" - api_request(base_url, token, "POST", download_path, { + task = api_request(base_url, token, "POST", download_path, { "content": "iso", "filename": filename, "url": image_url, }) - return filename, True + wait_for_task(base_url, token, node, task.get("data")) + + response = api_request(base_url, token, "GET", content_path) + for item in response.get("data", []): + if item.get("volid", "").endswith(filename): + return filename, True + + raise RuntimeError(f"download task finished but {filename} was not found in {storage}") + + +def wait_for_task(base_url, token, node, upid): + if not upid: + raise RuntimeError("missing Proxmox task id for ISO download") + + status_path = f"/api2/json/nodes/{node}/tasks/{urllib.parse.quote(upid, safe='')}/status" + for _ in range(180): + response = api_request(base_url, token, "GET", status_path) + data = response.get("data", {}) + if data.get("status") == "stopped": + if data.get("exitstatus") == "OK": + return + raise RuntimeError(f"download task failed with exit status {data.get('exitstatus')}") + time.sleep(2) + + raise RuntimeError("timed out waiting for ISO download task to finish") def main():