backend: libvirt-delete: allow searching volumes in other pools
This commit is contained in:
parent
f54c597aa7
commit
99e373a3ea
3 changed files with 19 additions and 11 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
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):
|
def get_hv_identification_from_pool_id(pool_id):
|
||||||
""" Get unique ID of the hypervisor """
|
""" Get unique ID of the hypervisor """
|
||||||
if pool_id.startswith("copr_hv_x86_64_01"):
|
if pool_id.startswith("copr_hv_x86_64_01"):
|
||||||
|
|
|
@ -12,6 +12,8 @@ import time
|
||||||
|
|
||||||
import libvirt
|
import libvirt
|
||||||
|
|
||||||
|
from helpers import get_volume_pools
|
||||||
|
|
||||||
def repeat(call, args):
|
def repeat(call, args):
|
||||||
""" Repeat the given function call, with args """
|
""" Repeat the given function call, with args """
|
||||||
attempts = 3
|
attempts = 3
|
||||||
|
@ -59,15 +61,16 @@ def _main():
|
||||||
except Exception:
|
except Exception:
|
||||||
logging.exception("domain can't be removed")
|
logging.exception("domain can't be removed")
|
||||||
|
|
||||||
pool = repeat(conn.storagePoolLookupByName, ("images",))
|
for pool_name in get_volume_pools():
|
||||||
for volume_name in repeat(pool.listVolumes, ()):
|
pool = repeat(conn.storagePoolLookupByName, (pool_name,))
|
||||||
if not volume_name.startswith(args.domainname):
|
for volume_name in repeat(pool.listVolumes, ()):
|
||||||
continue
|
if not volume_name.startswith(args.domainname):
|
||||||
try:
|
continue
|
||||||
repeat(_delete_volume, (pool, volume_name,))
|
try:
|
||||||
logging.info("volume %s removed", volume_name)
|
repeat(_delete_volume, (pool, volume_name,))
|
||||||
except Exception:
|
logging.info("volume %s removed", volume_name)
|
||||||
logging.exception("volume %s can not be removed", volume_name)
|
except Exception:
|
||||||
|
logging.exception("volume %s can not be removed", volume_name)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
_main()
|
_main()
|
||||||
|
|
|
@ -11,7 +11,7 @@ import re
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
import libvirt
|
import libvirt
|
||||||
from helpers import get_hv_identification_from_pool_id
|
from helpers import get_hv_identification_from_pool_id, get_volume_pools
|
||||||
|
|
||||||
|
|
||||||
def _get_parser():
|
def _get_parser():
|
||||||
|
@ -42,7 +42,7 @@ def _main():
|
||||||
|
|
||||||
# Some of those suffixes are used by Red Hat Copr
|
# Some of those suffixes are used by Red Hat Copr
|
||||||
known_suffixes = ["_root_disk$", "_config_cd$", "_swap$", "_root$", "_config$"]
|
known_suffixes = ["_root_disk$", "_config_cd$", "_swap$", "_root$", "_config$"]
|
||||||
volume_pool_names = ["images", "swap-space"]
|
volume_pool_names = get_volume_pools()
|
||||||
|
|
||||||
for pool_name in volume_pool_names:
|
for pool_name in volume_pool_names:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue