From 8249f6fdbc0cd1edfff88469816a81864f9f4b74 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Mon, 10 May 2021 12:25:35 +0200 Subject: [PATCH] copr-hv: templated provision scripts --- .../tasks/setup_provisioning_environment.yml | 12 ++++++++ .../templates/provision/upload-qcow2-images | 29 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100755 roles/copr/backend/templates/provision/upload-qcow2-images diff --git a/roles/copr/backend/tasks/setup_provisioning_environment.yml b/roles/copr/backend/tasks/setup_provisioning_environment.yml index 8e66e98aff..99e5dbb38d 100644 --- a/roles/copr/backend/tasks/setup_provisioning_environment.yml +++ b/roles/copr/backend/tasks/setup_provisioning_environment.yml @@ -23,6 +23,18 @@ tags: - provision_config +- name: templated provision scripts + template: + src: "{{ roles_path }}/copr/backend/templates/provision/{{ item }}" + dest: "{{ provision_directory }}/{{ item }}" + mode: 0755 + with_items: + - upload-qcow2-images + tags: + - provision_config + when: + - cloud_vars is not defined + - name: generate cloud-oriented vars files template: src: "{{ roles_path }}/copr/backend/templates/provision/{{ item }}" diff --git a/roles/copr/backend/templates/provision/upload-qcow2-images b/roles/copr/backend/templates/provision/upload-qcow2-images new file mode 100755 index 0000000000..14ac1b8eb8 --- /dev/null +++ b/roles/copr/backend/templates/provision/upload-qcow2-images @@ -0,0 +1,29 @@ +#! /bin/bash -x + +die() { echo >&2 "$*" ; exit 1 ; } + +image=$1 + +connections=' +{% for host in groups["copr_hypervisor"] %} + qemu+ssh://copr@{{ hostvars[host]['inventory_hostname'] }}/system +{% endfor %} +' + +new_volume=$2 +if test -z "$new_volume"; then + image_prefix=copr-builder- + new_volume=$image_prefix$(date +"%Y%m%d_%H%M%S") +fi + +export VIRSH_DEFAULT_CONNECT_URI= + +test -n "$image" || die "first argument (image) required" +test -f "$image" || die "image $image not found" + +pool=images +for connection in $connections; do + virsh --connect="$connection" vol-create-as --pool "$pool" "$new_volume" 1M + virsh --connect="$connection" vol-upload --pool "$pool" "$new_volume" --sparse "$image" +done +echo "uploaded images $new_volume"