description

adding cloud-init, network-config

tasks

cat << EOF > cloud_init_network_config.yaml:

version: 2
ethernets:
  ens3:
    dhcp4: true
"""A Python Pulumi program"""

import os
import pulumi_libvirt as libvirt

provider = libvirt.Provider("provider",
  libvirt.ProviderArgs()
)

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" ],
  mode      = "nat"
)

domain = libvirt.Domain("ubuntu",
  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
  )]
)