pulumi-templates/libvirt-python/__main__.py

58 lines
1.6 KiB
Python
Raw Normal View History

"""A Pulumi-based infrastructure with libvirt and Python"""
import pulumi
import pulumi_libvirt as lv
config = pulumi.Config()
pool = lv.Pool("default",
type = "dir",
path = "/var/tmp/libvirt/pulumi"
)
baseimg = lv.Volume("base-image",
pool = pool.name,
source = config.require("image_url")
#source = "https://cdimage.debian.org/images/cloud/bullseye-backports/20220711-1073/debian-11-backports-generic-amd64-20220711-1073.qcow2"
)
volume = lv.Volume("disk",
base_volume_id = baseimg.id,
pool = pool.name,
size = int(config.require("disksize")) * 1024 ** 3
)
# Stream configuration files
userdata = open("./cloud-init/user-data", "r").read()
metadata = open("./cloud-init/meta-data", "r").read()
networkconfig = open("./cloud-init/network-config", "r").read()
cloudinit = lv.CloudInitDisk("cloud-init",
meta_data = metadata,
user_data = userdata,
network_config = networkconfig
)
vm = lv.Domain("debian11",
boot_devices = [ lv.DomainBootDeviceArgs(
devs = [ "hd", "cdrom" ]
) ],
cloudinit = cloudinit.id,
disks = [ lv.DomainDiskArgs(volume_id = volume.id) ],
memory = int(config.require("memory")),
network_interfaces = [ lv.DomainNetworkInterfaceArgs(
network_name = "default",
wait_for_lease = True
) ],
consoles = [ lv.DomainConsoleArgs(
type = "pty",
target_port = 0,
target_type = "serial"
) ],
opts = pulumi.ResourceOptions(
custom_timeouts = pulumi.CustomTimeouts(create = "3m")
)
)
pulumi.export("ip", vm.network_interfaces[0]['addresses'][0])