diff --git a/locale/tr/LC_MESSAGES/django.mo b/locale/tr/LC_MESSAGES/django.mo index 6f7d8a68..fd4f5021 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 191dac3a..88af8163 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:50+0000\n" +"POT-Creation-Date: 2026-11-12 12:53+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" @@ -9789,7 +9789,7 @@ 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:260 +#: vrtManager/interface.py:263 #, python-format msgid "" "Interface %(iface)s is in use by the running VMs %(vms)s; shut them down or " @@ -9798,12 +9798,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:275 +#: vrtManager/interface.py:281 vrtManager/virtsecrets.py:118 +#, python-format +msgid "VMs %(names)s" +msgstr "%(names)s sanal makineleri" + +#: vrtManager/interface.py:283 +#, python-format +msgid "networks %(names)s" +msgstr "%(names)s ağları" + +#: vrtManager/interface.py:285 +#, 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 #, python-format msgid "Stop interface %(iface)s before deleting it" msgstr "%(iface)s arabirimini silmeden önce durdurun" -#: vrtManager/interface.py:279 +#: vrtManager/interface.py:301 #, python-format msgid "" "Bridge %(iface)s has addresses and several members: give the addresses to one" @@ -10251,11 +10267,6 @@ msgstr "" msgid "Type the secret's value" msgstr "Parolanın değerini yazın" -#: vrtManager/virtsecrets.py:118 -#, python-format -msgid "VMs %(names)s" -msgstr "%(names)s sanal makineleri" - #: vrtManager/virtsecrets.py:120 #, python-format msgid "pools %(names)s" diff --git a/locale/zh/LC_MESSAGES/django.mo b/locale/zh/LC_MESSAGES/django.mo index 760fa9f7..8a1da889 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 d197fcc9..fb24c243 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:50+0000\n" +"POT-Creation-Date: 2026-11-12 12:53+0000\n" "PO-Revision-Date: \n" "Last-Translator: \n" "Language-Team: \n" @@ -9217,19 +9217,34 @@ msgid "" "changed: %(rollback_err)s" msgstr "%(err)s;回滚更改也失败了,主机的配置可能已被更改:%(rollback_err)s" -#: vrtManager/interface.py:260 +#: vrtManager/interface.py:263 #, 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:275 +#: vrtManager/interface.py:281 vrtManager/virtsecrets.py:118 +#, python-format +msgid "VMs %(names)s" +msgstr "虚拟机 %(names)s" + +#: vrtManager/interface.py:283 +#, python-format +msgid "networks %(names)s" +msgstr "网络 %(names)s" + +#: vrtManager/interface.py:285 +#, 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 #, python-format msgid "Stop interface %(iface)s before deleting it" msgstr "删除接口 %(iface)s 前请先停止它" -#: vrtManager/interface.py:279 +#: vrtManager/interface.py:301 #, python-format msgid "" "Bridge %(iface)s has addresses and several members: give the addresses to one" @@ -9648,11 +9663,6 @@ msgstr "Ceph 密钥是 base64 文本,即 `ceph auth get-key` 输出的内容" msgid "Type the secret's value" msgstr "请输入机密的值" -#: vrtManager/virtsecrets.py:118 -#, python-format -msgid "VMs %(names)s" -msgstr "虚拟机 %(names)s" - #: vrtManager/virtsecrets.py:120 #, python-format msgid "pools %(names)s" diff --git a/vrtManager/interface.py b/vrtManager/interface.py index 4a40a77f..789d97b6 100644 --- a/vrtManager/interface.py +++ b/vrtManager/interface.py @@ -80,13 +80,14 @@ def interface_info(iface, tree): def networks_by_device(conn): - """The host's libvirt networks by the devices they use: their bridge, or - every interface or physical function they forward to. One listing, one + """The host's libvirt networks by the devices they use: their bridge, the + device NAT or routing goes out by, or every interface or physical + function they forward to. One listing, one XML read per network.""" by_device = {} for net in conn.listAllNetworks(0): tree = ElementTree.fromstring(net.XMLDesc(0)) - devices = {attribute(tree, "bridge", "name")} + devices = {attribute(tree, "bridge", "name"), attribute(tree, "forward", "dev")} for forward in tree.findall("forward/interface") + tree.findall("forward/pf"): devices.add(forward.get("dev")) devices.discard(None) @@ -109,15 +110,18 @@ class wvmInterfaces(wvmConnect): def get_member_candidates(self, netdevs): """The devices of netdevs a new bridge can take: not the loopback, a bridge, bond or VLAN of the host nor a device in one as configured, at - any depth (a bridge's bond's devices), not the bridge of a libvirt - network and not a VM's tap (libvirt names them vnetN and macvtapN).""" + any depth (a bridge's bond's devices), not a device a libvirt network + or a VM's macvtap card uses and not a VM's tap (libvirt names them + vnetN and macvtapN).""" taken = {"lo"} for iface in self.wvm.listAllInterfaces(0): tree = ElementTree.fromstring(iface.XMLDesc(VIR_INTERFACE_XML_INACTIVE)) if tree.get("type") in ("bridge", "bond", "vlan"): taken.update(element.get("name") for element in tree.iter("interface")) - for net in self.wvm.listAllNetworks(0): - taken.add(util.get_xml_path(net.XMLDesc(0), "/network/bridge/@name")) + taken.update(networks_by_device(self.wvm)) + for _name, trees in self.domain_trees(): + for tree in trees: + taken.update(tree.xpath("devices/interface[@type='direct']/source/@dev")) return [dev for dev in netdevs if dev not in taken and not dev.startswith(("vnet", "macvtap"))] def define_iface(self, xml, flag=0): @@ -264,6 +268,24 @@ class wvmInterface(wvmConnect): def start_iface(self): self.iface.create() + def check_unused(self): + """Refused while a VM's network card (in any of its definitions, the + VM running or not) or a libvirt network names the interface: that VM + or network would no longer start.""" + name = self.iface.name() + networks = networks_by_device(self.wvm).get(name, []) + vms = self.domains_using(lambda tree: any( + name in (source.get("bridge"), source.get("dev")) or source.get("network") in networks + for source in tree.xpath("devices/interface/source"))) + named = [] + if vms: + named.append(util.message(gettext_noop("VMs %(names)s"), names=", ".join(vms))) + if networks: + named.append(util.message(gettext_noop("networks %(names)s"), names=", ".join(networks))) + if named: + raise util.OperationError(gettext_noop("Interface %(iface)s is used by %(named)s; remove it from them first"), + iface=name, named=named) + 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 @@ -273,6 +295,7 @@ class wvmInterface(wvmConnect): All of it is one change of the host's configuration.""" if self.iface.isActive(): raise util.OperationError(gettext_noop("Stop interface %(iface)s before deleting it"), iface=self.iface.name()) + self.check_unused() tree = ElementTree.fromstring(self.iface.XMLDesc(VIR_INTERFACE_XML_INACTIVE)) members = tree.findall("bridge/interface") if len(members) > 1 and tree.findall("protocol"): diff --git a/vrtManager/tests/test_interface_delete.py b/vrtManager/tests/test_interface_delete.py index e2a93eab..41375df3 100644 --- a/vrtManager/tests/test_interface_delete.py +++ b/vrtManager/tests/test_interface_delete.py @@ -64,6 +64,22 @@ class DeleteInterfaceTestCase(SimpleTestCase): conn.delete_iface() conn.iface.undefine.assert_not_called() + def test_an_interface_a_vm_or_a_network_names_is_refused(self): + # the VM is shut off: its saved definition names the bridge, and it would not start + vm = MagicMock(**{"name.return_value": "web-1", "isPersistent.return_value": True, + "XMLDesc.return_value": "" + ""}) + lab = MagicMock(**{"name.return_value": "lab", + "XMLDesc.return_value": ""}) + for domains, networks, why in (([vm], [], "used by VMs web-1;"), ([], [lab], "used by networks lab;"), + ([vm], [lab], "used by VMs web-1; networks lab;")): + conn = interface("") + conn.wvm.listAllDomains.return_value = domains + conn.wvm.listAllNetworks.return_value = networks + with self.subTest(why), self.assertRaisesRegex(OperationError, why): + conn.delete_iface() + conn.iface.undefine.assert_not_called() + def test_a_member_libvirt_refuses_rolls_the_whole_change_back(self): conn = interface(f"{BOND}") conn.wvm.interfaceDefineXML.side_effect = libvirt.libvirtError("netcf: cannot write") diff --git a/vrtManager/tests/test_interface_reads.py b/vrtManager/tests/test_interface_reads.py index 57779d14..d30ffbd5 100644 --- a/vrtManager/tests/test_interface_reads.py +++ b/vrtManager/tests/test_interface_reads.py @@ -63,6 +63,16 @@ class ReadTests(SimpleTestCase): for listed in conn.wvm.listAllInterfaces.return_value: listed.XMLDesc.assert_called_with(libvirt.VIR_INTERFACE_XML_INACTIVE) + def test_a_device_a_vm_or_a_network_uses_is_taken(self): + # a VM's macvtap card, running or not, and a network forwarding to it would be cut off + conn = self.interfaces(networks=[""]) + conn.wvm.listAllNetworks.return_value[0].name.return_value = "direct" + conn.wvm.listAllDomains.return_value = [MagicMock(**{ + "name.return_value": "web-1", "isPersistent.return_value": False, + "XMLDesc.return_value": "" + ""})] + self.assertEqual(conn.get_member_candidates(["eno5", "eno6", "eno7"]), ["eno7"]) + def test_a_device_in_a_bond_of_a_bridge_is_taken(self): nested = ("" "" @@ -97,12 +107,12 @@ class BridgeUseTests(SimpleTestCase): from vrtManager.interface import networks_by_device nets = [MagicMock(**{"name.return_value": name, "XMLDesc.return_value": xml}) for name, xml in ( - ("default", ""), + ("default", ""), ("lan", ""), ("direct", ""), ("sriov", ""))] self.assertEqual(networks_by_device(MagicMock(**{"listAllNetworks.return_value": nets})), - {"virbr0": ["default"], "br0": ["lan"], "eth0": ["direct"], "eth1": ["direct"], "eth2": ["sriov"]}) + {"virbr0": ["default"], "eth3": ["default"], "br0": ["lan"], "eth0": ["direct"], "eth1": ["direct"], "eth2": ["sriov"]}) doms = [MagicMock(**{"name.return_value": name, "XMLDesc.return_value": xml}) for name, xml in ( ("web", "" ""),