fix: wait for talos iso download

This commit is contained in:
eding 2026-07-19 11:22:39 +02:00
parent 8a900ed28c
commit 1357a918df

View file

@ -3,6 +3,7 @@ import json
import os
import sys
import ssl
import time
import urllib.error
import urllib.parse
import urllib.request
@ -30,13 +31,37 @@ 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,
})
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():
parser = argparse.ArgumentParser()