pulumi-templates/pve-vm-python/__main__.py

77 lines
2.1 KiB
Python
Raw Normal View History

2022-08-21 01:12:55 +02:00
"""A ProxmoxVE VM template with Python"""
2022-08-17 01:52:53 +02:00
2022-08-21 01:12:55 +02:00
import yaml
from dotmap import DotMap
2022-08-17 01:52:53 +02:00
import pulumi
import pulumi_proxmoxve as proxmox
2022-08-21 01:12:55 +02:00
conf = DotMap(yaml.safe_load(open("input.yaml").read()))
2022-08-17 01:52:53 +02:00
config = pulumi.Config()
2022-08-17 02:16:30 +02:00
provider = proxmox.Provider("proxmoxve",
virtual_environment = {
2022-08-21 01:12:55 +02:00
"endpoint": conf.pve.url,
"insecure": conf.pve.insecure,
"username": conf.pve.username,
2022-08-21 01:15:13 +02:00
"password": config.require_secret("password")
2022-08-17 02:16:30 +02:00
}
)
2022-08-17 01:52:53 +02:00
2022-08-21 01:12:55 +02:00
vm = proxmox.vm.VirtualMachine(conf.vm.name,
node_name = conf.pve.nodename,
2022-08-17 01:52:53 +02:00
agent = proxmox.vm.VirtualMachineAgentArgs(
enabled = True,
trim = True,
type = "virtio"
),
bios = "seabios",
cpu = proxmox.vm.VirtualMachineCpuArgs(
2022-08-21 01:12:55 +02:00
cores = conf.vm.cores,
sockets = conf.vm.sockets
2022-08-17 01:52:53 +02:00
),
memory = proxmox.vm.VirtualMachineMemoryArgs(
2022-08-21 01:12:55 +02:00
dedicated = conf.vm.ram
2022-08-17 01:52:53 +02:00
),
clone = proxmox.vm.VirtualMachineCloneArgs(
2022-08-21 01:12:55 +02:00
node_name = conf.pve.nodename,
vm_id = conf.vm.clone,
full = True
2022-08-17 01:52:53 +02:00
),
disks = [
proxmox.vm.VirtualMachineDiskArgs(
interface = "virtio0",
2022-08-21 01:12:55 +02:00
datastore_id = conf.pve.storage,
size = conf.vm.disksize,
file_format = "qcow2"
)
],
2022-08-17 01:52:53 +02:00
network_devices = [
proxmox.vm.VirtualMachineNetworkDeviceArgs(
bridge = "vmbr0",
model = "virtio"
)
],
on_boot = True,
operating_system = proxmox.vm.VirtualMachineOperatingSystemArgs(
type = "l26"
),
initialization = proxmox.vm.VirtualMachineInitializationArgs(
type = "nocloud",
2022-08-21 01:12:55 +02:00
datastore_id = conf.pve.storage,
2022-08-17 01:52:53 +02:00
user_account = proxmox.vm.VirtualMachineInitializationUserAccountArgs(
2022-08-21 01:12:55 +02:00
username = conf.vm.username,
password = conf.vm.password,
keys = conf.vm.sshkeys
2022-08-17 01:52:53 +02:00
)
),
2022-08-17 02:19:17 +02:00
opts = pulumi.ResourceOptions(
provider = provider
)
2022-08-17 01:52:53 +02:00
)
2022-08-17 02:44:02 +02:00
# Getting local IP
# First item of the ipv4_addresses is of the loopback interface (so the usual 127.0.0.1). Let's get the second and grab only the text.
lanip = vm.ipv4_addresses[1][0]
2022-08-17 01:52:53 +02:00
2022-08-17 02:44:02 +02:00
pulumi.export("ip", lanip)