diff --git a/libvirt-ansible-python/requirements.txt b/libvirt-ansible-python/requirements.txt index baeee94..85c6487 100644 --- a/libvirt-ansible-python/requirements.txt +++ b/libvirt-ansible-python/requirements.txt @@ -1,8 +1,8 @@ +pyyaml>=6.0 +dotmap>=1.3.30 +protobuf==3.20.1 pulumi>=3.0.0,<4.0.0 pulumi_libvirt>=0.3.0 pulumi-command>=0.4.1 -pyyaml>=6.0 Jinja2>=3.1.2 -dotmap>=1.3.30 passlib>=1.7.4 -protobuf==3.20.1 diff --git a/libvirt-python/Pulumi.yaml b/libvirt-python/Pulumi.yaml index 8fc7ae7..57c14dd 100644 --- a/libvirt-python/Pulumi.yaml +++ b/libvirt-python/Pulumi.yaml @@ -1,3 +1,4 @@ +--- name: ${PROJECT} description: ${DESCRIPTION} runtime: python diff --git a/libvirt-python/__main__.py b/libvirt-python/__main__.py index b0e039e..cf773df 100644 --- a/libvirt-python/__main__.py +++ b/libvirt-python/__main__.py @@ -1,31 +1,29 @@ -"""A Pulumi-based infrastructure with libvirt and Python""" +"""A Pulumi deployment with libvirt and Python""" +import yaml +from dotmap import DotMap import pulumi import pulumi_libvirt as lv +from passlib.hash import sha512_crypt +from jinja2 import Template +conf = DotMap(yaml.safe_load(open("input.yaml").read())) +conf.password = sha512_crypt.hash(conf.password, rounds=4096) config = pulumi.Config() -pool = lv.Pool("default", - type = "dir", - path = "/var/tmp/libvirt/pulumi" -) +pool = lv.Pool("mypool", type = "dir", path = conf.poolpath) +baseimg = lv.Volume("myimage", pool = pool.name, source = conf.image_url) -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", +volume = lv.Volume("mydisk", base_volume_id = baseimg.id, pool = pool.name, - size = int(config.require("disksize")) * 1024 ** 3 + size = int(conf.disksize) * 1024 ** 3 ) # Stream configuration files -userdata = open("./cloud-init/user-data", "r").read() -metadata = open("./cloud-init/meta-data", "r").read() -networkconfig = open("./cloud-init/network-config", "r").read() +userdata = Template(open("./cloud-init/user-data.jinja").read()).render(conf) +metadata = Template(open("./cloud-init/meta-data.jinja").read()).render(conf) +networkconfig = open("./cloud-init/network-config").read() cloudinit = lv.CloudInitDisk("cloud-init", meta_data = metadata, @@ -33,13 +31,14 @@ cloudinit = lv.CloudInitDisk("cloud-init", network_config = networkconfig ) -vm = lv.Domain("debian11", +vm = lv.Domain(conf.name, boot_devices = [ lv.DomainBootDeviceArgs( devs = [ "hd", "cdrom" ] ) ], cloudinit = cloudinit.id, + vcpus = conf.vcpu, disks = [ lv.DomainDiskArgs(volume_id = volume.id) ], - memory = int(config.require("memory")), + memory = int(conf.ram), network_interfaces = [ lv.DomainNetworkInterfaceArgs( network_name = "default", wait_for_lease = True diff --git a/libvirt-python/cloud-init/meta-data b/libvirt-python/cloud-init/meta-data deleted file mode 100644 index 75c7c6a..0000000 --- a/libvirt-python/cloud-init/meta-data +++ /dev/null @@ -1,2 +0,0 @@ -instance-id: debian11 -local-hostname: debian11 diff --git a/libvirt-python/cloud-init/meta-data.jinja b/libvirt-python/cloud-init/meta-data.jinja new file mode 100644 index 0000000..30f5b90 --- /dev/null +++ b/libvirt-python/cloud-init/meta-data.jinja @@ -0,0 +1,2 @@ +instance-id: {{ name }} +local-hostname: {{ name }} diff --git a/libvirt-python/cloud-init/user-data b/libvirt-python/cloud-init/user-data deleted file mode 100644 index 6609114..0000000 --- a/libvirt-python/cloud-init/user-data +++ /dev/null @@ -1,24 +0,0 @@ -#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/cloud-init/user-data.jinja b/libvirt-python/cloud-init/user-data.jinja new file mode 100644 index 0000000..68ccfcf --- /dev/null +++ b/libvirt-python/cloud-init/user-data.jinja @@ -0,0 +1,24 @@ +#cloud-config +resize_rootfs: true +users: + - name: {{ username }} + sudo: ALL=(ALL) NOPASSWD:ALL + groups: users, admin + shell: /bin/bash + ssh_authorized_keys: + {% for key in sshkeys %} + - "{{ key }}" + {% endfor %} + hashed_passwd: {{ password }} +ssh_pwauth: true +disable_root: false +chpasswd: + expire: false + list: | + root:{{ password }} + syntaxerrormmm:{{ password }} +#packages: +# - qemu-guest-agent +#power_state: +# delay: now +# mode: reboot diff --git a/libvirt-python/input.yaml b/libvirt-python/input.yaml new file mode 100644 index 0000000..e5d8ef1 --- /dev/null +++ b/libvirt-python/input.yaml @@ -0,0 +1,15 @@ +--- +# Basic VM configuration +name: virtual-machine +vcpu: 1 +ram: 2048 +disksize: 20 +username: syntaxerrormmm +password: cicciopasticcio +sshkeys: + - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFioHkaV1NhX6NCqsJakJw8EVBOcDHm1MEbpY499CPtG syntaxerrormmm@fisso" + - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILu91hBh8pNRt4eE1pug0Y4jCHZDCcMJ+vj3CiF5EQHV syntaxerrormmm@syntaxxps" + - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIP/hn/0xn6DRS2B0paFzDQRakupgTQQ5hitQhqOfWcqz syntaxerrormmm@microbo" + +image_url: "https://cdimage.debian.org/images/cloud/bullseye-backports/20220711-1073/debian-11-backports-generic-amd64-20220711-1073.qcow2" +poolpath: /var/tmp/libvirt/pulumi diff --git a/libvirt-python/requirements.txt b/libvirt-python/requirements.txt index 8e10d74..3033806 100644 --- a/libvirt-python/requirements.txt +++ b/libvirt-python/requirements.txt @@ -1,2 +1,7 @@ +pyyaml>=6.0 +dotmap>=1.3.30 +protobuf==3.20.1 pulumi>=3.0.0,<4.0.0 pulumi_libvirt>=0.3.0 +Jinja2>=3.1.2 +passlib>=1.7.4