1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2026-11-09 11:46:49 +00:00

fix(interfaces): an ethernet interface needs no bridge member, and unreadable host devices are reported

The form required a bridge member for an ethernet interface, which does
not use one. When the host's network devices could not be read, the error
was swallowed and every creation failed with "the device is not on this
host"; the page now shows the real error and does not try.
This commit is contained in:
catborise 2026-10-07 23:57:10 +03:00
parent 9fdb039977
commit 55eb63a09f
3 changed files with 42 additions and 6 deletions

View file

@ -14,7 +14,8 @@ class AddInterface(forms.Form):
required=True,
choices=(("none", "none"), ("onboot", "onboot"), ("hotplug", "hotplug")),
)
netdev = forms.CharField(max_length=15, required=True)
# a bridge's member; an ethernet interface configures the device in name
netdev = forms.CharField(max_length=15, required=False)
ipv4_type = forms.ChoiceField(
required=True,
choices=(("dhcp", "dhcp"), ("static", "static"), ("none", "none")),
@ -93,6 +94,8 @@ class AddInterface(forms.Form):
def clean_netdev(self):
netdev = self.cleaned_data["netdev"]
if not netdev:
return netdev
if not re.fullmatch(r"[A-Za-z0-9_.-]{1,15}", netdev) or netdev in (".", ".."):
raise forms.ValidationError(
_("The device name may have up to 15 letters, digits and . _ -")
@ -111,7 +114,9 @@ class AddInterface(forms.Form):
self.add_error("stp", _("A bridge needs STP on or off"))
if cleaned.get("delay") is None and "delay" not in self.errors:
self.add_error("delay", _("A bridge needs a forward delay"))
if netdev and netdev not in self.netdevs:
if not netdev and "netdev" not in self.errors:
self.add_error("netdev", _("A bridge needs a device"))
elif netdev and netdev not in self.netdevs:
self.add_error("netdev", _("The device is not on this host"))
elif netdev and netdev == name:
self.add_error("netdev", _("A bridge cannot contain itself"))