1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-10 20:26:48 +00:00

fix: a network, pool or secret a VM needs is not stopped or deleted

Stopping a network cut the running VMs on it off, deleting one or a
secret kept the VMs that name it from starting, and stopping a pool
took the disks of running VMs away, all without a word. Each is now
refused with the VMs (and, for a secret, the pools) that need it:
stopping while a running VM uses it, deleting while a VM's definition
names it. A disk given by its file path does not need its pool's
definition. The API's pool stop is refused the same way.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
catborise 2026-10-22 07:53:24 +03:00
parent ef1faf57c8
commit 887b807451
9 changed files with 268 additions and 3 deletions

View file

@ -155,9 +155,27 @@ class wvmStorage(wvmConnect):
return self.pool.create(0)
def stop(self):
"""Refused while it holds a disk of a running VM, named by the pool
or by a volume's path: that VM would lose the disk."""
name = self.pool.name()
paths = {vol.path() for vol in self.pool.listAllVolumes()}
vms = self.domains_using(
lambda domain: domain.xpath("devices/disk/source[@pool=$name]", name=name)
or paths.intersection(self._source_paths(domain)),
running_only=True,
)
if vms:
raise util.OperationError(f"Pool {name} holds disks of the running VMs {', '.join(vms)}; "
"shut them down first")
return self.pool.destroy()
def delete(self):
"""Refused while a VM's definition names it for a disk: that VM would
no longer start. A disk given by its file path does not need it."""
name = self.pool.name()
if vms := self.domains_using(lambda domain: domain.xpath("devices/disk/source[@pool=$name]", name=name)):
raise util.OperationError(f"VMs {', '.join(vms)} have disks in pool {name} by its name and would no "
"longer start; detach those disks first")
self.pool.undefine()
def get_autostart(self):