From ff2f4252e48d2d66a8ebd0cc606519d9efa346c7 Mon Sep 17 00:00:00 2001 From: Emiliano Vavassori Date: Mon, 3 Jul 2023 21:05:54 +0200 Subject: [PATCH] =?UTF-8?q?Selezione=20pi=C3=B9=20rapida=20per=20immagine?= =?UTF-8?q?=20con=20libvirt.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libvirt-ansible-python/__main__.py | 3 ++- libvirt-ansible-python/cloud-images.yaml | 3 +++ libvirt-ansible-python/input.yaml | 2 +- libvirt-python/__main__.py | 3 ++- libvirt-python/cloud-images.yaml | 3 +++ libvirt-python/input.yaml | 2 +- 6 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 libvirt-ansible-python/cloud-images.yaml create mode 100644 libvirt-python/cloud-images.yaml diff --git a/libvirt-ansible-python/__main__.py b/libvirt-ansible-python/__main__.py index a3fb66a..a92b05e 100644 --- a/libvirt-ansible-python/__main__.py +++ b/libvirt-ansible-python/__main__.py @@ -9,6 +9,7 @@ from jinja2 import Template from passlib.hash import sha512_crypt conf = DotMap(yaml.safe_load(open("./input.yaml", "r").read())) +cloudimages = DotMap(yaml.safe_load(open('cloud-images.yaml').read())) # Replacing readed password with its own counterpart. conf.password = sha512_crypt.hash(conf.password, rounds=4096) @@ -22,7 +23,7 @@ pool = lv.Pool("pool", baseimg = lv.Volume("base-image", pool = pool.name, - source = conf.image_url + source = cloudimages[conf.image] #source = "https://cdimage.debian.org/images/cloud/bullseye-backports/20220711-1073/debian-11-backports-generic-amd64-20220711-1073.qcow2" ) diff --git a/libvirt-ansible-python/cloud-images.yaml b/libvirt-ansible-python/cloud-images.yaml new file mode 100644 index 0000000..815ca3e --- /dev/null +++ b/libvirt-ansible-python/cloud-images.yaml @@ -0,0 +1,3 @@ +buster: https://cloud.debian.org/images/cloud/buster-backports/latest/debian-10-backports-generic-amd64.qcow2 +bullseye: https://cloud.debian.org/images/cloud/bullseye-backports/latest/debian-11-backports-generic-amd64.qcow2 +bookworm: https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2 diff --git a/libvirt-ansible-python/input.yaml b/libvirt-ansible-python/input.yaml index 319a596..7873040 100644 --- a/libvirt-ansible-python/input.yaml +++ b/libvirt-ansible-python/input.yaml @@ -11,7 +11,7 @@ sshkeys: - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILu91hBh8pNRt4eE1pug0Y4jCHZDCcMJ+vj3CiF5EQHV syntaxerrormmm@syntaxxps" - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIP/hn/0xn6DRS2B0paFzDQRakupgTQQ5hitQhqOfWcqz syntaxerrormmm@microbo" -image_url: "https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2" +image: bookworm poolpath: /var/tmp/libvirt/pulumi # Ansible configuration diff --git a/libvirt-python/__main__.py b/libvirt-python/__main__.py index dab5679..e1d76c0 100644 --- a/libvirt-python/__main__.py +++ b/libvirt-python/__main__.py @@ -8,11 +8,12 @@ from passlib.hash import sha512_crypt from jinja2 import Template conf = DotMap(yaml.safe_load(open("input.yaml").read())) +cloudimages = DotMap(yaml.safe_load(open("cloud-images.yaml").read())) conf.password = sha512_crypt.hash(conf.password, rounds=4096) config = pulumi.Config() pool = lv.Pool("mypool", type = "dir", path = conf.poolpath) -baseimg = lv.Volume("myimage", pool = pool.name, source = conf.image_url) +baseimg = lv.Volume("myimage", pool = pool.name, source = cloudimages[conf.image]) volume = lv.Volume("mydisk", base_volume_id = baseimg.id, diff --git a/libvirt-python/cloud-images.yaml b/libvirt-python/cloud-images.yaml new file mode 100644 index 0000000..815ca3e --- /dev/null +++ b/libvirt-python/cloud-images.yaml @@ -0,0 +1,3 @@ +buster: https://cloud.debian.org/images/cloud/buster-backports/latest/debian-10-backports-generic-amd64.qcow2 +bullseye: https://cloud.debian.org/images/cloud/bullseye-backports/latest/debian-11-backports-generic-amd64.qcow2 +bookworm: https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2 diff --git a/libvirt-python/input.yaml b/libvirt-python/input.yaml index d6347e2..06f45c5 100644 --- a/libvirt-python/input.yaml +++ b/libvirt-python/input.yaml @@ -11,5 +11,5 @@ sshkeys: - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAILu91hBh8pNRt4eE1pug0Y4jCHZDCcMJ+vj3CiF5EQHV syntaxerrormmm@syntaxxps" - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIP/hn/0xn6DRS2B0paFzDQRakupgTQQ5hitQhqOfWcqz syntaxerrormmm@microbo" -image_url: "https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-generic-amd64.qcow2" +image: bookworm poolpath: /var/tmp/libvirt/pulumi