Files
opentofu-standart-vm/generate.py
Iurii Anfinogenov 40694927c8 commit fix
2026-05-03 13:23:54 +00:00

54 lines
1004 B
Python

#!/usr/bin/env python3
BASE_IP = "192.168.20"
START = 10
COUNT = 5
CPU = 2
MEMORY = 2048
GATEWAY = "192.168.20.1"
def generate():
print("locals {")
print(" nodes = {")
for i in range(COUNT):
idx = i + 1
last_octet = START + i
if last_octet > 254:
raise ValueError("IP overflow")
ip = f"{BASE_IP}.{last_octet}"
comma = "," if i < COUNT - 1 else ""
print(f""" k8s-worker-{idx} = {{
index = {idx}
cpu = {CPU}
memory = {MEMORY}
disks = [
{{
datastore = "ssd2"
interface = "scsi0"
size = 20
import_from = "local:import/ubuntu-24.qcow2"
}}
]
network_devices = [
{{
bridge = "vmbr0"
vlan_id = 20
ip = "{ip}"
cidr = 24
gateway = "{GATEWAY}"
}}
]
}}{comma}""")
print(" }")
print("}")
if __name__ == "__main__":
generate()