mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-10 04:06:47 +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:
parent
ef1faf57c8
commit
887b807451
9 changed files with 268 additions and 3 deletions
|
|
@ -161,10 +161,25 @@ class wvmNetwork(wvmConnect):
|
|||
def start(self):
|
||||
self.net.create()
|
||||
|
||||
def _vms_on_it(self, running_only):
|
||||
name = self.net.name()
|
||||
return self.domains_using(
|
||||
lambda domain: domain.xpath("devices/interface[@type='network']/source[@network=$name]", name=name),
|
||||
running_only,
|
||||
)
|
||||
|
||||
def stop(self):
|
||||
"""Refused while a running VM is on it: that VM would be cut off."""
|
||||
if vms := self._vms_on_it(running_only=True):
|
||||
raise util.OperationError(f"Network {self.net.name()} is in use by the running VMs {', '.join(vms)}; "
|
||||
"shut them down or remove their network cards first")
|
||||
self.net.destroy()
|
||||
|
||||
def delete(self):
|
||||
"""Refused while a VM's definition names it: that VM would no longer start."""
|
||||
if vms := self._vms_on_it(running_only=False):
|
||||
raise util.OperationError(f"VMs {', '.join(vms)} use network {self.net.name()} and would no longer "
|
||||
"start; remove their network cards first")
|
||||
self.net.undefine()
|
||||
|
||||
def update(self, command, section, xml, parentIndex, flags=0):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue