Aggiunta template per libvirt e python.

This commit is contained in:
Emiliano Vavassori 2022-08-20 00:14:02 +02:00
parent 1651a1e269
commit f54055a65c
8 changed files with 105 additions and 0 deletions

2
libvirt-python/.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.pyc
venv/

View File

@ -0,0 +1,5 @@
name: ${PROJECT}
description: ${DESCRIPTION}
runtime: python
template:
description: A Pulumi deployment with libvirt and Python

9
libvirt-python/README.md Normal file
View File

@ -0,0 +1,9 @@
# Quick configuration #
To quickly set up your pulumi deployment, configure the following settings:
$ pulumi config set libvirt:url --plaintext "qemu:///system"
$ pulumi config set image_url --plaintext "https://cdimage.debian.org/images/cloud/bullseye-backports/20220711-1073/debian-11-backports-generic-amd64-20220711-1073.qcow2"
$ pulumi config set disksize --int 20
$ pulumi config set memory --int 2048

View File

@ -0,0 +1,57 @@
"""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 = config.require("disksize") * 1024 ** 3
)
# Stream configuration files
userdata = open("./user-data", "r").read()
metadata = open("./meta-data", "r").read()
networkconfig = open("./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 = 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])

View File

@ -0,0 +1,2 @@
instance-id: debian11
local-hostname: debian11

View File

@ -0,0 +1,4 @@
version: 2
ethernets:
interface0:
dhcp4: true

View File

@ -0,0 +1,24 @@
#cloud-config
resize_rootfs: true
users:
- name: syntaxerrormmm
sudo: ALL=(ALL) NOPASSWD:ALL
groups: users, admin
shell: /bin/bash
ssh_authorized_keys:
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFioHkaV1NhX6NCqsJakJw8EVBOcDHm1MEbpY499CPtG syntaxerrormmm@fisso
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILu91hBh8pNRt4eE1pug0Y4jCHZDCcMJ+vj3CiF5EQHV syntaxerrormmm@syntaxxps
- ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIP/hn/0xn6DRS2B0paFzDQRakupgTQQ5hitQhqOfWcqz syntaxerrormmm@microbo
hashed_passwd: $6$rounds=4096$4ZUeoch.EwyR/TLb$.71i1otUQpw2eMlrjcP3H4XxsnLlVbIQxagFDGviOvCaIz7ONa.tTZPO09YL7hiAh4vLaTcGD43VoAM6tEYjx/
ssh_pwauth: true
disable_root: false
chpasswd:
expire: false
list: |
root:$6$rounds=4096$4ZUeoch.EwyR/TLb$.71i1otUQpw2eMlrjcP3H4XxsnLlVbIQxagFDGviOvCaIz7ONa.tTZPO09YL7hiAh4vLaTcGD43VoAM6tEYjx/
syntaxerrormmm:$6$rounds=4096$4ZUeoch.EwyR/TLb$.71i1otUQpw2eMlrjcP3H4XxsnLlVbIQxagFDGviOvCaIz7ONa.tTZPO09YL7hiAh4vLaTcGD43VoAM6tEYjx/
#packages:
# - qemu-guest-agent
#power_state:
# delay: now
# mode: reboot

View File

@ -0,0 +1,2 @@
pulumi>=3.0.0,<4.0.0
pulumi_libvirt>=0.3.0