def delete_machine(self, id):
if self.isCurrentStorageAction(id):
raise Exception("Can't delete a locked machine")
domain = self._get_domain(id)
if domain:
if domain.state(0)[0] != libvirt.VIR_DOMAIN_SHUTOFF:
domain.destroy()
domain.undefineFlags(
libvirt.VIR_DOMAIN_UNDEFINE_SNAPSHOTS_METADATA)
poolpath = os.path.join(self.basepath, id)
try:
diskpool = self.connection.storagePoolLookupByName(id)
for vol in diskpool.listAllVolumes():
vol.delete()
diskpool.destroy()
except BaseException:
pass
if os.path.exists(poolpath):
shutil.rmtree(poolpath)
return True
评论列表
文章目录