From 75f18e2ac7c9b9afa554896844d3b97ab1a9addd Mon Sep 17 00:00:00 2001 From: NaeiKinDus Date: Fri, 7 Mar 2025 00:00:00 +0000 Subject: [PATCH] fix(tooling): added missing steps to virtd reset task --- Taskfile.yml | 5 +++-- scripts/reset_virtd.sh | 12 ++++++++++++ 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 scripts/reset_virtd.sh diff --git a/Taskfile.yml b/Taskfile.yml index d6eaf95..5be858a 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -70,12 +70,13 @@ tasks: vars: VIRSH_CONNECT: '{{.VIRSH_CONNECT | default "qemu:///system"}}' cmds: - - ./scripts/purge_virsh.sh + - ./scripts/reset_virtd.sh - task: 'molecule' vars: CLI_ARGS: 'destroy' - sudo systemctl restart nftables.service - - sudo systemctl restart libvirtd.service + - sudo systemctl restart libvirtd.service # reset libvirtd related nft rules + - sudo systemctl restart docker.service # reset docker related nft rules ansible:new:role:*: desc: create a new role for the specified collection diff --git a/scripts/reset_virtd.sh b/scripts/reset_virtd.sh new file mode 100644 index 0000000..f547e26 --- /dev/null +++ b/scripts/reset_virtd.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +VIRSH_CONNECT="${VIRSH_CONNECT:=qemu:///system}" +VIRSH_VOL_POOL="${VIRSH_VOL_POOL:=default}" + +for domain in $(virsh -c "${VIRSH_CONNECT}" list --name --all); do + virsh -c "${VIRSH_CONNECT}" destroy "${domain}" || true + virsh -c "${VIRSH_CONNECT}" undefine "${domain}" || true +done + +for volume in $(virsh -c "${VIRSH_CONNECT}" vol-list --pool "${VIRSH_VOL_POOL}" | tail -n +3 | sed -E 's/^\s*([^\s]+)\s+.*$/\1/'); do + virsh -c "${VIRSH_CONNECT}" vol-delete --pool "${VIRSH_VOL_POOL}" "${volume}" || true +done