Pulumi start | libvirt-python 06 | get IP address and and VM Name
description⌗
get IP address and and VM Name
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" ],
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
)]
)
pulumi.export("IP Address", domain.network_interfaces[0])
pulumi.export("VM Name", domain.name)
Read other posts