fix: use proxmox host address for iso baking
This commit is contained in:
parent
d80b469e57
commit
25c6d8b7f9
|
|
@ -31,7 +31,7 @@ resource "null_resource" "stage_talos_image" {
|
||||||
|
|
||||||
provisioner "local-exec" {
|
provisioner "local-exec" {
|
||||||
interpreter = ["python", "-c"]
|
interpreter = ["python", "-c"]
|
||||||
command = "import subprocess; subprocess.run(['python', r'${path.module}/scripts/stage_talos_image.py', '--api-url', '${var.proxmox_api_url}', '--api-token', '${var.proxmox_api_token}', '--node', '${self.triggers.proxmox_node}', '--storage', '${var.talos_image_storage}', '--image-url', '${local.talos_iso_download_url}', '--filename', '${self.triggers.filename}', '--network-config', r'${local_file.metal_network_config[each.key].filename}'], check=True)"
|
command = "import subprocess; subprocess.run(['python', r'${path.module}/scripts/stage_talos_image.py', '--api-url', '${var.proxmox_api_url}', '--api-token', '${var.proxmox_api_token}', '--node', '${self.triggers.proxmox_node}', '--node-address', '${lookup(var.node_addresses, self.triggers.proxmox_node, self.triggers.proxmox_node)}', '--storage', '${var.talos_image_storage}', '--image-url', '${local.talos_iso_download_url}', '--filename', '${self.triggers.filename}', '--network-config', r'${local_file.metal_network_config[each.key].filename}'], check=True)"
|
||||||
}
|
}
|
||||||
|
|
||||||
depends_on = [local_file.metal_network_config]
|
depends_on = [local_file.metal_network_config]
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ def api_request(base_url, token, method, path, data=None):
|
||||||
return json.loads(response.read().decode())
|
return json.loads(response.read().decode())
|
||||||
|
|
||||||
|
|
||||||
def ensure_image(base_url, token, node, storage, image_url, filename, network_config_path=None):
|
def ensure_image(base_url, token, node, node_address, storage, image_url, filename, network_config_path=None):
|
||||||
content_path = f"/api2/json/nodes/{node}/storage/{storage}/content"
|
content_path = f"/api2/json/nodes/{node}/storage/{storage}/content"
|
||||||
response = api_request(base_url, token, "GET", content_path)
|
response = api_request(base_url, token, "GET", content_path)
|
||||||
for item in response.get("data", []):
|
for item in response.get("data", []):
|
||||||
|
|
@ -51,7 +51,7 @@ def ensure_image(base_url, token, node, storage, image_url, filename, network_co
|
||||||
wait_for_task(base_url, token, node, task.get("data"))
|
wait_for_task(base_url, token, node, task.get("data"))
|
||||||
|
|
||||||
if network_config_path:
|
if network_config_path:
|
||||||
build_custom_iso(base_url, token, node, storage, source_filename, filename, network_config_path)
|
build_custom_iso(base_url, token, node_address, storage, source_filename, filename, network_config_path)
|
||||||
wait_for_storage_content(base_url, token, node, storage, filename)
|
wait_for_storage_content(base_url, token, node, storage, filename)
|
||||||
|
|
||||||
response = api_request(base_url, token, "GET", content_path)
|
response = api_request(base_url, token, "GET", content_path)
|
||||||
|
|
@ -89,15 +89,15 @@ 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 run_ssh(node, script):
|
def run_ssh(node_address, script):
|
||||||
ssh = shutil.which("ssh")
|
ssh = shutil.which("ssh")
|
||||||
if ssh is None:
|
if ssh is None:
|
||||||
raise RuntimeError("ssh is required to customize Talos ISO on the Proxmox host")
|
raise RuntimeError("ssh is required to customize Talos ISO on the Proxmox host")
|
||||||
subprocess.run([ssh, f"root@{node}", script], check=True)
|
subprocess.run([ssh, f"root@{node_address}", script], check=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def build_custom_iso(base_url, token, node, storage, source_filename, output_filename, network_config_path):
|
def build_custom_iso(base_url, token, node_address, storage, source_filename, output_filename, network_config_path):
|
||||||
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")
|
||||||
|
|
||||||
|
|
@ -121,7 +121,7 @@ def build_custom_iso(base_url, token, node, storage, source_filename, output_fil
|
||||||
"-eltorito-alt-boot -e EFI/BOOT/BOOTX64.EFI -no-emul-boot -isohybrid-gpt-basdat "
|
"-eltorito-alt-boot -e EFI/BOOT/BOOTX64.EFI -no-emul-boot -isohybrid-gpt-basdat "
|
||||||
"-V TALOS \"$TMPDIR/extract\" >/dev/null 2>&1"
|
"-V TALOS \"$TMPDIR/extract\" >/dev/null 2>&1"
|
||||||
)
|
)
|
||||||
run_ssh(node, script)
|
run_ssh(node_address, script)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
@ -129,6 +129,7 @@ def main():
|
||||||
parser.add_argument("--api-url", required=True)
|
parser.add_argument("--api-url", required=True)
|
||||||
parser.add_argument("--api-token", required=True)
|
parser.add_argument("--api-token", required=True)
|
||||||
parser.add_argument("--node", required=True)
|
parser.add_argument("--node", required=True)
|
||||||
|
parser.add_argument("--node-address", required=True)
|
||||||
parser.add_argument("--storage", required=True)
|
parser.add_argument("--storage", required=True)
|
||||||
parser.add_argument("--image-url", required=True)
|
parser.add_argument("--image-url", required=True)
|
||||||
parser.add_argument("--filename", required=True)
|
parser.add_argument("--filename", required=True)
|
||||||
|
|
@ -136,7 +137,7 @@ def main():
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
filename, downloaded = ensure_image(args.api_url, args.api_token, args.node, args.storage, args.image_url, args.filename, args.network_config)
|
filename, downloaded = ensure_image(args.api_url, args.api_token, args.node, args.node_address, args.storage, args.image_url, args.filename, args.network_config)
|
||||||
except urllib.error.HTTPError as exc:
|
except urllib.error.HTTPError as exc:
|
||||||
sys.stderr.write(exc.read().decode())
|
sys.stderr.write(exc.read().decode())
|
||||||
raise
|
raise
|
||||||
|
|
|
||||||
|
|
@ -168,6 +168,12 @@ variable "node_interfaces" {
|
||||||
# }
|
# }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
variable "node_addresses" {
|
||||||
|
description = "Map of Proxmox node names to SSH/API reachable hostnames or IPs"
|
||||||
|
type = map(string)
|
||||||
|
default = {}
|
||||||
|
}
|
||||||
|
|
||||||
variable "create_vlan_interface" {
|
variable "create_vlan_interface" {
|
||||||
description = "Whether to create VLAN interfaces (true for tagged VLANs, false for untagged)"
|
description = "Whether to create VLAN interfaces (true for tagged VLANs, false for untagged)"
|
||||||
type = bool
|
type = bool
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue