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

fix(interfaces): a bridge over a bond or vlan keeps the device's settings

A new bridge always declared its member as type='ethernet'. On a host
with the netcf backend that rewrote the member's configuration: a bond
lost its BONDING_OPTS and a vlan its VLAN=yes. The member is now taken
from the host's own definition of the device (a bond keeps its mode and
devices, a vlan its tag), without the start mode, MTU and addresses that
only a top-level interface has; a device the host does not define stays
ethernet.
This commit is contained in:
catborise 2026-10-08 23:23:22 +03:00
parent 6ca823725c
commit 342f6a7135
2 changed files with 93 additions and 2 deletions

View file

@ -1,6 +1,6 @@
from xml.etree import ElementTree
from libvirt import VIR_INTERFACE_XML_INACTIVE
from libvirt import VIR_ERR_NO_INTERFACE, VIR_INTERFACE_XML_INACTIVE, libvirtError
from vrtManager import util
from vrtManager.connection import wvmConnect
@ -10,6 +10,21 @@ class wvmInterfaces(wvmConnect):
def define_iface(self, xml, flag=0):
self.wvm.interfaceDefineXML(xml, flag)
def bridge_member_xml(self, netdev):
"""netdev as a bridge member: as the host defines it (a bond keeps its
mode and devices, a vlan its tag), without what only a top-level
interface has. A device the host does not define is ethernet."""
try:
member = ElementTree.fromstring(self.get_iface(netdev).XMLDesc(VIR_INTERFACE_XML_INACTIVE))
except libvirtError as err:
if err.get_error_code() != VIR_ERR_NO_INTERFACE:
raise
return f"<interface type='ethernet' name='{netdev}'/>"
for tag in ("start", "mtu", "protocol"):
for child in member.findall(tag):
member.remove(child)
return ElementTree.tostring(member, encoding="unicode")
def create_iface(
self,
name,
@ -51,7 +66,7 @@ class wvmInterfaces(wvmConnect):
xml += """</protocol>"""
if itype == "bridge":
xml += f"""<bridge stp='{stp}' delay='{delay}'>
<interface name='{netdev}' type='ethernet'/>
{self.bridge_member_xml(netdev)}
</bridge>"""
xml += """</interface>"""
self.define_iface(xml)