From d923eb687751ce0d9c7e3fd5f1b806cbb6bce337 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup Date: Tue, 20 Sep 2022 16:41:50 +0200 Subject: [PATCH] copr-be: don't require additional helpers.py edits --- roles/copr/backend/files/provision/helpers.py | 5 ----- .../backend/files/provision/libvirt-delete | 9 +++++---- .../copr/backend/files/provision/libvirt-list | 18 +++++++----------- 3 files changed, 12 insertions(+), 20 deletions(-) diff --git a/roles/copr/backend/files/provision/helpers.py b/roles/copr/backend/files/provision/helpers.py index b686089f8c..35fd7d3945 100644 --- a/roles/copr/backend/files/provision/helpers.py +++ b/roles/copr/backend/files/provision/helpers.py @@ -1,8 +1,3 @@ -def get_volume_pools(): - """ Get a list of pools where to search for Resalloc-related volumes """ - return ["images"] - - def get_hv_identification_from_pool_id(pool_id): """ Get unique ID of the hypervisor """ if pool_id.startswith("copr_hv_x86_64_01"): diff --git a/roles/copr/backend/files/provision/libvirt-delete b/roles/copr/backend/files/provision/libvirt-delete index 4e31e84232..f3b937d1c0 100755 --- a/roles/copr/backend/files/provision/libvirt-delete +++ b/roles/copr/backend/files/provision/libvirt-delete @@ -12,8 +12,6 @@ import time import libvirt -from helpers import get_volume_pools - def repeat(call, args): """ Repeat the given function call, with args """ attempts = 3 @@ -61,8 +59,11 @@ def _main(): except Exception: logging.exception("domain can't be removed") - for pool_name in get_volume_pools(): - pool = repeat(conn.storagePoolLookupByName, (pool_name,)) + + for pool in repeat(conn.listAllStoragePools, ()): + if pool.name() not in ["images", "swap-space"]: + continue + for volume_name in repeat(pool.listVolumes, ()): if not volume_name.startswith(args.domainname): continue diff --git a/roles/copr/backend/files/provision/libvirt-list b/roles/copr/backend/files/provision/libvirt-list index 9e500341cc..e89b656917 100755 --- a/roles/copr/backend/files/provision/libvirt-list +++ b/roles/copr/backend/files/provision/libvirt-list @@ -11,7 +11,7 @@ import re import argparse import sys import libvirt -from helpers import get_hv_identification_from_pool_id, get_volume_pools +from helpers import get_hv_identification_from_pool_id def _get_parser(): @@ -40,20 +40,16 @@ def _main(): # Gather the list of all domains here vm_names = set() - # Some of those suffixes are used by Red Hat Copr + # Some of those are used by Red Hat Copr known_suffixes = ["_root_disk$", "_config_cd$", "_swap$", "_root$", "_config$"] - volume_pool_names = get_volume_pools() - - for pool_name in volume_pool_names: - try: - pool = conn.storagePoolLookupByName(pool_name) - except libvirt.libvirtError: - msg = "Pool {0} not found\n".format(pool_name) - sys.stderr.write(msg) - continue + known_pools = ["images", "swap-space"] + for pool in conn.listAllStoragePools(): # List all the volumes in the volume pool that seem to be related to # the given Pool name + if pool.name() not in known_pools: + continue + for volume in pool.listVolumes(): if volume.startswith(pool_id): for suffix in known_suffixes: