description

Add autostart

tasks

"""A Python Pulumi program"""

import os
import pulumi
import pulumi_libvirt as libvirt

pool = libvirt.Pool("cluster",
  type = "dir",
  path = "/var/lib/libvirt/images/cluster_storage"
)

ubuntu = libvirt.Volume("ubuntu",
  pool   = pool.name,
  source = "http://media/_cloud/ubuntu-20.04-server-cloudimg-amd64.img",

)

filesystem = libvirt.Volume("filesystem",
  base_volume_id = ubuntu.id,
  pool           = pool.name,
  size           = 10000000000
)

with open('cloud_init_user_data.yaml') as f:
    cloud_init_user_data = f.read()

with open('cloud_init_network_config.yaml') as f:
    cloud_init_network_config = f.read()

cloud_init = libvirt.CloudInitDisk("cloud-init",
  meta_data      = cloud_init_user_data,
  network_config = cloud_init_network_config,
  pool           = pool.name,
  user_data      = cloud_init_user_data
)

network = libvirt.Network("network",
  addresses = [ "192.168.10.0/24" ],
  autostart = True,
  mode      = "nat"
)

domain = libvirt.Domain("ubuntu",
  autostart = True,
  cloudinit = cloud_init.id,
  consoles  = [ libvirt.DomainConsoleArgs(
    type        = "pty",
    target_port = "0",
    target_type = "serial"
  )],
  disks    = [ libvirt.DomainDiskArgs(
    volume_id = filesystem.id
  )],
  network_interfaces = [ libvirt.DomainNetworkInterfaceArgs(
    network_id = network.id,
    wait_for_lease = True
  )]
)

pulumi.export("IP Address", domain.network_interfaces[0])
pulumi.export("VM Name", domain.name)