diff --git a/locale/tr/LC_MESSAGES/django.mo b/locale/tr/LC_MESSAGES/django.mo index fd4f5021..601496c8 100644 Binary files a/locale/tr/LC_MESSAGES/django.mo and b/locale/tr/LC_MESSAGES/django.mo differ diff --git a/locale/tr/LC_MESSAGES/django.po b/locale/tr/LC_MESSAGES/django.po index 88af8163..a05745a0 100644 --- a/locale/tr/LC_MESSAGES/django.po +++ b/locale/tr/LC_MESSAGES/django.po @@ -11,7 +11,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-11-12 12:53+0000\n" +"POT-Creation-Date: 2026-11-12 13:01+0000\n" "PO-Revision-Date: 2020-11-04 12:00+0000\n" "Last-Translator: catborise , 2020\n" "Language-Team: Turkish (https://www.transifex.com/catborise/teams/110663/tr/)\n" @@ -9780,7 +9780,7 @@ msgstr "Bilinmeyen çökme eylemi %(action)s" msgid "Network interface %(mac)s is not in the definition" msgstr "%(mac)s ağ arayüzü tanımda yok" -#: vrtManager/interface.py:35 vrtManager/network.py:194 +#: vrtManager/interface.py:37 vrtManager/network.py:194 #, python-format msgid "" "%(err)s; rolling the change back failed too, the host's configuration may be " @@ -9789,7 +9789,25 @@ msgstr "" "%(err)s; değişikliğin geri alınması da başarısız oldu, sunucunun " "yapılandırması değişmiş olabilir: %(rollback_err)s" -#: vrtManager/interface.py:263 +#: vrtManager/interface.py:192 +#, python-format +msgid "" +"Device %(dev)s carries the address this panel reaches the host by: give the " +"bridge that address or DHCP, or the host is cut off" +msgstr "" +"%(dev)s aygıtı, panelin sunucuya ulaştığı adresi taşıyor: köprüye bu adresi " +"ya da DHCP verin, yoksa sunucuyla bağlantı kesilir" + +#: vrtManager/interface.py:300 +#, python-format +msgid "" +"Interface %(iface)s carries the address this panel reaches the host by; " +"stopping it would cut the host off" +msgstr "" +"%(iface)s arayüzü, panelin sunucuya ulaştığı adresi taşıyor; durdurulursa " +"sunucuyla bağlantı kesilir" + +#: vrtManager/interface.py:302 #, python-format msgid "" "Interface %(iface)s is in use by the running VMs %(vms)s; shut them down or " @@ -9798,28 +9816,28 @@ msgstr "" "%(iface)s arayüzünü çalışan %(vms)s VM'leri kullanıyor; önce onları kapatın " "veya ağ kartlarını başka yere taşıyın" -#: vrtManager/interface.py:281 vrtManager/virtsecrets.py:118 +#: vrtManager/interface.py:320 vrtManager/virtsecrets.py:118 #, python-format msgid "VMs %(names)s" msgstr "%(names)s sanal makineleri" -#: vrtManager/interface.py:283 +#: vrtManager/interface.py:322 #, python-format msgid "networks %(names)s" msgstr "%(names)s ağları" -#: vrtManager/interface.py:285 +#: vrtManager/interface.py:324 #, python-format msgid "Interface %(iface)s is used by %(named)s; remove it from them first" msgstr "" "%(iface)s arayüzü %(named)s tarafından kullanılıyor; önce onlardan kaldırın" -#: vrtManager/interface.py:296 +#: vrtManager/interface.py:335 #, python-format msgid "Stop interface %(iface)s before deleting it" msgstr "%(iface)s arabirimini silmeden önce durdurun" -#: vrtManager/interface.py:301 +#: vrtManager/interface.py:340 #, python-format msgid "" "Bridge %(iface)s has addresses and several members: give the addresses to one" diff --git a/locale/zh/LC_MESSAGES/django.mo b/locale/zh/LC_MESSAGES/django.mo index 8a1da889..456aec54 100644 Binary files a/locale/zh/LC_MESSAGES/django.mo and b/locale/zh/LC_MESSAGES/django.mo differ diff --git a/locale/zh/LC_MESSAGES/django.po b/locale/zh/LC_MESSAGES/django.po index fb24c243..6512ee00 100644 --- a/locale/zh/LC_MESSAGES/django.po +++ b/locale/zh/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2026-11-12 12:53+0000\n" +"POT-Creation-Date: 2026-11-12 13:01+0000\n" "PO-Revision-Date: \n" "Last-Translator: \n" "Language-Team: \n" @@ -9210,41 +9210,55 @@ msgstr "未知的崩溃操作 %(action)s" msgid "Network interface %(mac)s is not in the definition" msgstr "网络接口 %(mac)s 不在定义中" -#: vrtManager/interface.py:35 vrtManager/network.py:194 +#: vrtManager/interface.py:37 vrtManager/network.py:194 #, python-format msgid "" "%(err)s; rolling the change back failed too, the host's configuration may be " "changed: %(rollback_err)s" msgstr "%(err)s;回滚更改也失败了,主机的配置可能已被更改:%(rollback_err)s" -#: vrtManager/interface.py:263 +#: vrtManager/interface.py:192 +#, python-format +msgid "" +"Device %(dev)s carries the address this panel reaches the host by: give the " +"bridge that address or DHCP, or the host is cut off" +msgstr "设备 %(dev)s 承载着本面板访问该主机所用的地址:请为网桥设置该地址或 DHCP,否则会切断与主机的连接" + +#: vrtManager/interface.py:300 +#, python-format +msgid "" +"Interface %(iface)s carries the address this panel reaches the host by; " +"stopping it would cut the host off" +msgstr "接口 %(iface)s 承载着本面板访问该主机所用的地址;停止它会切断与主机的连接" + +#: vrtManager/interface.py:302 #, python-format msgid "" "Interface %(iface)s is in use by the running VMs %(vms)s; shut them down or " "move their network cards first" msgstr "接口 %(iface)s 正被运行中的虚拟机 %(vms)s 使用;请先关闭它们或移走其网卡" -#: vrtManager/interface.py:281 vrtManager/virtsecrets.py:118 +#: vrtManager/interface.py:320 vrtManager/virtsecrets.py:118 #, python-format msgid "VMs %(names)s" msgstr "虚拟机 %(names)s" -#: vrtManager/interface.py:283 +#: vrtManager/interface.py:322 #, python-format msgid "networks %(names)s" msgstr "网络 %(names)s" -#: vrtManager/interface.py:285 +#: vrtManager/interface.py:324 #, python-format msgid "Interface %(iface)s is used by %(named)s; remove it from them first" msgstr "接口 %(iface)s 正被 %(named)s 使用;请先从中移除它" -#: vrtManager/interface.py:296 +#: vrtManager/interface.py:335 #, python-format msgid "Stop interface %(iface)s before deleting it" msgstr "删除接口 %(iface)s 前请先停止它" -#: vrtManager/interface.py:301 +#: vrtManager/interface.py:340 #, python-format msgid "" "Bridge %(iface)s has addresses and several members: give the addresses to one" diff --git a/vrtManager/interface.py b/vrtManager/interface.py index 789d97b6..3dd37ce5 100644 --- a/vrtManager/interface.py +++ b/vrtManager/interface.py @@ -1,5 +1,7 @@ from django.utils.translation import gettext_noop import contextlib +import ipaddress +import socket from functools import cached_property from xml.etree import ElementTree @@ -96,6 +98,36 @@ def networks_by_device(conn): return by_device +def panel_addresses(host): + """The addresses the panel reaches host by, as resolved here.""" + try: + return {ipaddress.ip_address(info[4][0]) for info in socket.getaddrinfo(host, None)} + except OSError: # not resolved here: libvirt reached it otherwise + return set() + + +def panel_devices(conn, addresses): + """The host's interfaces that carry one of addresses (panel_addresses), + with the devices in them at any depth: stopping or rebuilding one cuts + the panel off the host. One whose addresses libvirt cannot tell (netcf + and a virtio card, running_xml) and that leases them may carry them.""" + remote = any(not address.is_loopback for address in addresses) + devices = set() + for iface in conn.listAllInterfaces(0): + try: + tree = ElementTree.fromstring(iface.XMLDesc(0)) + carries = addresses & {ipaddress.ip_address(ip.get("address")) for ip in tree.iter("ip")} + except libvirtError as err: + if err.get_error_code() != VIR_ERR_XML_ERROR: + raise + tree = ElementTree.fromstring(iface.XMLDesc(VIR_INTERFACE_XML_INACTIVE)) + carries = remote and (tree.find("protocol/dhcp") is not None or tree.find("protocol/autoconf") is not None + or addresses & {ipaddress.ip_address(ip.get("address")) for ip in tree.iter("ip")}) + if carries: + devices.update(element.get("name") for element in tree.iter("interface")) + return devices + + class wvmInterfaces(wvmConnect): def get_ifaces_info(self): """Every interface of the host (interface_info) and whether libvirt @@ -130,17 +162,20 @@ class wvmInterfaces(wvmConnect): 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.""" + interface has; and its MTU, which the bridge takes (netcf gives the + bridge's to its members). 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"" + return f"", None + mtu = attribute(member, "mtu", "size") for tag in ("start", "mtu", "protocol"): for child in member.findall(tag): member.remove(child) - return ElementTree.tostring(member, encoding="unicode") + return ElementTree.tostring(member, encoding="unicode"), mtu def create_iface( self, @@ -157,8 +192,20 @@ class wvmInterfaces(wvmConnect): stp, delay, ): + if itype == "bridge": + member, mtu = self.bridge_member_xml(netdev) + # the bridge takes its device's addresses away: without the panel's, the host is cut off + addresses = panel_addresses(self.host) + static = {ipaddress.ip_address(address.split("/")[0]) + for kind, address in ((ipv4_type, ipv4_addr), (ipv6_type, ipv6_addr)) if kind == "static"} + leased = {version for version, kind in ((4, ipv4_type), (6, ipv6_type)) if kind == "dhcp"} + if netdev in panel_devices(self.wvm, addresses) and not any( + address in static or address.version in leased for address in addresses): + raise util.OperationError(gettext_noop("Device %(dev)s carries the address this panel reaches the host by: give the bridge that address or DHCP, or the host is cut off"), dev=netdev) xml = f""" """ + if itype == "bridge" and mtu: + xml += f"" if ipv4_type == "dhcp": xml += """ @@ -183,7 +230,7 @@ class wvmInterfaces(wvmConnect): xml += """""" if itype == "bridge": xml += f""" - {self.bridge_member_xml(netdev)} + {member} """ xml += """""" # the form refuses a name the host defines, so nothing is replaced; @@ -258,8 +305,11 @@ class wvmInterface(wvmConnect): return sorted(cards, key=lambda card: (card["vm"], card["tap"] or "")) def stop_iface(self): - """Refused while a running VM has a card on it (get_vms): that VM would be cut off.""" + """Refused while a running VM has a card on it (get_vms): that VM would + be cut off; and when it carries the panel's way to the host.""" name = self.iface.name() + if name in panel_devices(self.wvm, panel_addresses(self.host)): + raise util.OperationError(gettext_noop("Interface %(iface)s carries the address this panel reaches the host by; stopping it would cut the host off"), iface=name) if cards := self.get_vms(networks_by_device(self.wvm).get(name, [])): raise util.OperationError(gettext_noop("Interface %(iface)s is in use by the running VMs %(vms)s; shut them down or move their network cards first"), iface=name, vms=", ".join(sorted({card["vm"] for card in cards}))) @@ -289,7 +339,7 @@ class wvmInterface(wvmConnect): def delete_iface(self): """Undefine the interface, stopped first. netcf removes a bridge's members with it, so each member is defined again on its own, as virsh - iface-unbridge does: with the bridge's start mode and, when it is the + iface-unbridge does: with the bridge's start mode and MTU and, when it is the only one, addresses; a bridge with addresses and several members is refused, which of them takes the addresses being the user's choice. All of it is one change of the host's configuration.""" @@ -303,5 +353,5 @@ class wvmInterface(wvmConnect): with changes(self.wvm): self.iface.undefine() for member in members: - member.extend(tree.findall("start") + tree.findall("protocol")) + member.extend(tree.findall("start") + tree.findall("mtu") + tree.findall("protocol")) self.wvm.interfaceDefineXML(ElementTree.tostring(member, encoding="unicode"), 0) diff --git a/vrtManager/tests/test_interface_delete.py b/vrtManager/tests/test_interface_delete.py index 41375df3..5322407d 100644 --- a/vrtManager/tests/test_interface_delete.py +++ b/vrtManager/tests/test_interface_delete.py @@ -40,6 +40,12 @@ class DeleteInterfaceTestCase(SimpleTestCase): self.assertEqual(bond.xpath("start/@mode"), ["onboot"]) self.assertEqual(bond.xpath("protocol/ip/@address"), ["192.0.2.10"]) + def test_the_members_take_the_bridge_mtu(self): + # the bridge held it for them: jumbo frames go on + (eth1,) = delete("" + "") + self.assertEqual(eth1.xpath("mtu/@size"), ["9000"]) + def test_several_members_take_the_start_mode(self): members = delete( "" diff --git a/vrtManager/tests/test_interface_reads.py b/vrtManager/tests/test_interface_reads.py index d30ffbd5..6ea4f9c6 100644 --- a/vrtManager/tests/test_interface_reads.py +++ b/vrtManager/tests/test_interface_reads.py @@ -138,6 +138,7 @@ class BridgeUseTests(SimpleTestCase): ""})])): dom = MagicMock(**{"name.return_value": "web", "XMLDesc.return_value": f"{cards}"}) conn = wvmInterface.__new__(wvmInterface) + conn.host = "192.0.2.1" conn.iface = MagicMock(**{"name.return_value": "eno2"}) conn.wvm = MagicMock(**{"listAllDomains.return_value": [dom], "listAllNetworks.return_value": nets}) with self.subTest(cards), self.assertRaisesRegex(OperationError, "in use by the running VMs web"): diff --git a/vrtManager/tests/test_interface_xml.py b/vrtManager/tests/test_interface_xml.py index 1bd7586f..37e8a80e 100644 --- a/vrtManager/tests/test_interface_xml.py +++ b/vrtManager/tests/test_interface_xml.py @@ -13,6 +13,7 @@ from vrtManager.interface import wvmInterfaces class Ipv6XmlTestCase(SimpleTestCase): def xml(self, gw): conn = wvmInterfaces.__new__(wvmInterfaces) + conn.host = "192.0.2.1" conn.wvm = MagicMock() conn.define_iface = MagicMock() conn.get_iface = MagicMock() @@ -32,6 +33,7 @@ class Ipv6XmlTestCase(SimpleTestCase): class Ipv4XmlTestCase(SimpleTestCase): def xml(self, addr, gw): conn = wvmInterfaces.__new__(wvmInterfaces) + conn.host = "192.0.2.1" conn.wvm = MagicMock() conn.define_iface = MagicMock() conn.get_iface = MagicMock() @@ -60,6 +62,7 @@ class BridgeMemberXmlTestCase(SimpleTestCase): def member(self, host_xml): conn = wvmInterfaces.__new__(wvmInterfaces) + conn.host = "192.0.2.1" conn.wvm = MagicMock() conn.define_iface = MagicMock() @@ -72,6 +75,7 @@ class BridgeMemberXmlTestCase(SimpleTestCase): conn.get_iface = MagicMock(side_effect=get_iface) conn.create_iface("br1", "bridge", "onboot", "bond0", "none", "", "", "none", "", "", "on", 0) + self.conn = conn self.assertTrue(conn.define_iface.return_value.create.called) members = etree.fromstring(conn.define_iface.call_args[0][0]).findall("bridge/interface") self.assertEqual(len(members), 1) @@ -92,6 +96,9 @@ class BridgeMemberXmlTestCase(SimpleTestCase): # what only a top-level interface has: the bridge holds the addresses for tag in ("start", "mtu", "protocol"): self.assertIsNone(member.find(tag), tag) + # the bridge takes its MTU: netcf gives it to the members, jumbo frames go on + bridge = etree.fromstring(self.conn.define_iface.call_args[0][0]) + self.assertEqual(bridge.xpath("mtu/@size"), ["9000"]) def test_a_vlan_keeps_its_tag_and_device(self): member = self.member( @@ -106,9 +113,11 @@ class BridgeMemberXmlTestCase(SimpleTestCase): def test_a_device_the_host_does_not_define_is_ethernet(self): member = self.member(None) self.assertEqual(member.attrib, {"type": "ethernet", "name": "bond0"}) + self.assertEqual(etree.fromstring(self.conn.define_iface.call_args[0][0]).xpath("mtu"), []) def test_other_lookup_errors_are_not_hidden(self): conn = wvmInterfaces.__new__(wvmInterfaces) + conn.host = "192.0.2.1" conn.wvm = MagicMock() conn.define_iface = MagicMock() err = libvirt.libvirtError("cannot recv data") @@ -121,6 +130,7 @@ class BridgeMemberXmlTestCase(SimpleTestCase): def test_an_interface_that_does_not_start_is_rolled_back(self): # the definition, and the member's own configuration it changed, as they were conn = wvmInterfaces.__new__(wvmInterfaces) + conn.host = "192.0.2.1" conn.wvm = MagicMock() conn.define_iface = MagicMock() iface = conn.define_iface.return_value @@ -129,3 +139,67 @@ class BridgeMemberXmlTestCase(SimpleTestCase): conn.create_iface("br1", "ethernet", "onboot", "", "none", "", "", "none", "", "", "on", 0) conn.wvm.changeRollback.assert_called_once_with(0) conn.wvm.changeCommit.assert_not_called() + + +class PanelDeviceTestCase(SimpleTestCase): + """The interface that carries the address the panel reaches the host by, + and the devices in it, keep the panel's way to the host.""" + + def conn(self, cls): + conn = cls.__new__(cls) + conn.host = "192.0.2.10" + bridge = ("" + "") + other = "" + conn.wvm = MagicMock(**{"listAllInterfaces.return_value": [MagicMock(**{"XMLDesc.return_value": x}) for x in (bridge, other)], + "listAllDomains.return_value": [], "listAllNetworks.return_value": []}) + return conn + + def test_it_is_not_stopped(self): + from vrtManager.interface import wvmInterface + from vrtManager.util import OperationError + + for name in ("br0", "eno1"): + conn = self.conn(wvmInterface) + conn.iface = MagicMock(**{"name.return_value": name}) + with self.subTest(name), self.assertRaisesRegex(OperationError, "carries the address this panel reaches the host by"): + conn.stop_iface() + conn.iface.destroy.assert_not_called() + conn.iface.name.return_value = "eno2" + conn.stop_iface() + conn.iface.destroy.assert_called_once_with() + + def test_a_bridge_over_it_keeps_the_address(self): + from vrtManager.util import OperationError + + def create(netdev, ipv4_type, ipv4_addr="", ipv6_type="none", ipv6_addr=""): + conn = self.conn(wvmInterfaces) + conn.define_iface = MagicMock() + conn.get_iface = MagicMock(side_effect=no_interface(netdev)) + conn.create_iface("br1", "bridge", "onboot", netdev, ipv4_type, ipv4_addr, "", ipv6_type, ipv6_addr, "", "on", 0) + return conn.define_iface + + for kwargs in ({"ipv4_type": "none"}, {"ipv4_type": "static", "ipv4_addr": "192.0.2.11/24"}, + {"ipv4_type": "none", "ipv6_type": "static", "ipv6_addr": "2001:db8::10/64"}, + # DHCP of the other family leaves the panel's IPv4 address behind + {"ipv4_type": "none", "ipv6_type": "dhcp"}): + with self.subTest(**kwargs), self.assertRaisesRegex(OperationError, "Device eno1 carries the address"): + create("eno1", **kwargs) + for netdev, kwargs in (("eno1", {"ipv4_type": "static", "ipv4_addr": "192.0.2.10/24"}), + ("eno1", {"ipv4_type": "dhcp"}), ("eno2", {"ipv4_type": "none"})): + with self.subTest(netdev=netdev, **kwargs): + self.assertTrue(create(netdev, **kwargs).called) + + def test_one_whose_leased_addresses_libvirt_cannot_tell_is_kept(self): + # netcf gives no running XML for a virtio card ("link speed -1"): its saved one has no lease + from vrtManager.interface import panel_devices + import ipaddress + + err = libvirt.libvirtError("Invalid value for attribute 'speed' in element 'link': '-1'") + err.err = (libvirt.VIR_ERR_XML_ERROR, libvirt.VIR_FROM_INTERFACE, str(err), 2, None, None, None, 0, 0) + saved = "" + eth0 = MagicMock(**{"XMLDesc.side_effect": lambda flags=0: saved if flags else (_ for _ in ()).throw(err)}) + conn = MagicMock(**{"listAllInterfaces.return_value": [eth0]}) + self.assertEqual(panel_devices(conn, {ipaddress.ip_address("192.0.2.10")}), {"eth0"}) + # a panel on the host itself is not cut off by it + self.assertEqual(panel_devices(conn, {ipaddress.ip_address("127.0.0.1")}), set())