diff --git a/libvirt-python/.gitignore b/libvirt-python/.gitignore new file mode 100644 index 0000000..a3807e5 --- /dev/null +++ b/libvirt-python/.gitignore @@ -0,0 +1,2 @@ +*.pyc +venv/ diff --git a/libvirt-python/Pulumi.yaml b/libvirt-python/Pulumi.yaml new file mode 100644 index 0000000..8fc7ae7 --- /dev/null +++ b/libvirt-python/Pulumi.yaml @@ -0,0 +1,5 @@ +name: ${PROJECT} +description: ${DESCRIPTION} +runtime: python +template: + description: A Pulumi deployment with libvirt and Python diff --git a/libvirt-python/README.md b/libvirt-python/README.md new file mode 100644 index 0000000..0f35e7d --- /dev/null +++ b/libvirt-python/README.md @@ -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 + diff --git a/libvirt-python/__main__.py b/libvirt-python/__main__.py new file mode 100644 index 0000000..eaea592 --- /dev/null +++ b/libvirt-python/__main__.py @@ -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]) diff --git a/libvirt-python/cloud-init/meta-data b/libvirt-python/cloud-init/meta-data new file mode 100644 index 0000000..75c7c6a --- /dev/null +++ b/libvirt-python/cloud-init/meta-data @@ -0,0 +1,2 @@ +instance-id: debian11 +local-hostname: debian11 diff --git a/libvirt-python/cloud-init/network-config b/libvirt-python/cloud-init/network-config new file mode 100644 index 0000000..5d3100d --- /dev/null +++ b/libvirt-python/cloud-init/network-config @@ -0,0 +1,4 @@ +version: 2 +ethernets: + interface0: + dhcp4: true diff --git a/libvirt-python/cloud-init/user-data b/libvirt-python/cloud-init/user-data new file mode 100644 index 0000000..6609114 --- /dev/null +++ b/libvirt-python/cloud-init/user-data @@ -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 diff --git a/libvirt-python/requirements.txt b/libvirt-python/requirements.txt new file mode 100644 index 0000000..8e10d74 --- /dev/null +++ b/libvirt-python/requirements.txt @@ -0,0 +1,2 @@ +pulumi>=3.0.0,<4.0.0 +pulumi_libvirt>=0.3.0