description

adding cloud-init, userdata

tasks

cat << EOF > cloud_init_user_data.yaml:

#cloud-config
ssh_pwauth: True
chpasswd:
  list: |
                ubuntu:ubuntu
  expire: False
packages:
  - qemu-guest-agent
runcmd:
  - [ timedatectl, set-timezone, Asia/Tokyo   ]
  - [ systemctl, enable, --now, qemu-guest-agent ]
EOF
"""A Python Pulumi program"""

import os
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()

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

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
  )]
)