From 34cddd3be83e608d6ae60c7dd4a8ddd83b06d7a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20P=C3=B6hn?= Date: Tue, 7 Mar 2017 15:14:10 +0100 Subject: [PATCH] delete associated libvirt domain/image when destroying builder vm --- fdroidserver/build.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/fdroidserver/build.py b/fdroidserver/build.py index d9ef9a0e..ceaf76d0 100644 --- a/fdroidserver/build.py +++ b/fdroidserver/build.py @@ -220,6 +220,25 @@ def get_clean_vm(reset=False): if os.path.exists('builder'): logging.info("Removing broken/incomplete/unwanted build server") vagrant(['destroy', '-f'], cwd='builder') + if provider == 'libvirt': + import libvirt + virConnect = None + virDomain = None + try: + virConnect = libvirt.open('qemu:///system') + virDomain = virConnect.lookupByName('builder_default') + except libvirt.libvirtError: + logging.debug("no libvirt domain found, skipping delete attempt") + if virDomain: + virDomain.undefineFlags(libvirt.VIR_DOMAIN_UNDEFINE_MANAGED_SAVE + | libvirt.VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA + | libvirt.VIR_DOMAIN_UNDEFINE_NVRAM) + if virConnect: + storagePool = virConnect.storagePoolLookupByName('default') + if storagePool: + for vol in storagePool.listAllVolumes(): + if vol.name().startswith('builder'): + vol.delete() shutil.rmtree('builder') os.mkdir('builder')