mirror of
https://github.com/retspen/webvirtcloud
synced 2026-12-03 17:36:05 +00:00
fix(instances): a VM's network cards name networks and filters its host has
libvirt saves a network card whose network or filter the host does not have, and the VM then does not start: a card added or changed with an unknown network (net:missing) or filter was saved and the page said the card was changed. Adding or changing a card now refuses a network or filter the host does not have; a stopped network is still the host's. A migration defines the VM on the destination the same way: a shut-off VM moved to a host without one of its networks or filters stayed there unable to start. The migration now refuses such a destination before anything changes.
This commit is contained in:
parent
a78d92e7aa
commit
3308a75557
11 changed files with 340 additions and 222 deletions
|
|
@ -172,6 +172,13 @@ class wvmInstances(wvmConnect):
|
|||
# a host device is of the source host: the destination may have none, or another one
|
||||
if any(etree.fromstring(xml).xpath(HOST_DEVICES) for xml in definitions):
|
||||
raise util.OperationError(gettext_noop("A VM with host devices cannot be migrated; remove them first"))
|
||||
networks, filters = self.unknown_networks([etree.fromstring(xml) for xml in definitions])
|
||||
if networks:
|
||||
raise util.OperationError(gettext_noop("The destination host does not have these networks of the VM: %(names)s"),
|
||||
names=", ".join(networks))
|
||||
if filters:
|
||||
raise util.OperationError(gettext_noop("The destination host does not have these network filters of the VM: %(names)s"),
|
||||
names=", ".join(filters))
|
||||
copies = self.disk_copies(conn, definitions, pools or {})
|
||||
if copies:
|
||||
mode.append("disks copied: " + ", ".join(f"{copy['target']} to {copy['pool'].name()}" for copy in copies))
|
||||
|
|
@ -2750,8 +2757,17 @@ class wvmInstance(wvmConnect):
|
|||
etree.SubElement(iface, "model", type=model)
|
||||
if nwfilter:
|
||||
etree.SubElement(iface, "filterref", filter=nwfilter)
|
||||
self.check_card(iface)
|
||||
self._attach_device(etree.tostring(iface).decode())
|
||||
|
||||
def check_card(self, iface):
|
||||
"""Refuses a network card whose network or filter this host does not have."""
|
||||
networks, filters = self.unknown_networks([iface])
|
||||
if networks:
|
||||
raise util.OperationError(gettext_noop("This host has no network %(name)s"), name=networks[0])
|
||||
if filters:
|
||||
raise util.OperationError(gettext_noop("This host has no network filter %(name)s"), name=filters[0])
|
||||
|
||||
def _attach_device(self, xml):
|
||||
"""Attach to the persistent definition and, when the VM is active, to
|
||||
the running one, in one call. QEMU checks a copy of the persistent
|
||||
|
|
@ -2829,6 +2845,7 @@ class wvmInstance(wvmConnect):
|
|||
iface.remove(old_filter)
|
||||
if nwfilter and iface.find("filterref") is None:
|
||||
etree.SubElement(iface, "filterref", filter=nwfilter)
|
||||
self.check_card(iface)
|
||||
|
||||
self._defineXML(etree.tostring(tree).decode())
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue