diff --git a/instances/jobs.py b/instances/jobs.py
index 3842d1ab..13d6df12 100644
--- a/instances/jobs.py
+++ b/instances/jobs.py
@@ -836,6 +836,18 @@ def _check_disk_name(conn, data):
raise util.OperationError(_("Image has already exist. Please check volumes or change instance name"))
+def _check_networks(conn, data):
+ """Each NIC's network and the filter must be the host's: the VM would
+ not start."""
+ networks = data["networks"].split(",")
+ if "" in networks:
+ raise util.OperationError(_("Each network card needs a network"))
+ for network in sorted(set(networks) - set(conn.get_networks())):
+ raise util.OperationError(_("This host has no network %(name)s"), name=network)
+ if data["nwfilter"] and data["nwfilter"] not in conn.get_nwfilters():
+ raise util.OperationError(_("This host has no network filter %(name)s"), name=data["nwfilter"])
+
+
def _check_macs(conn, data):
"""Two NICs of one MAC on a network reach neither reliably."""
try:
@@ -902,6 +914,7 @@ class CreateInstance(Kind):
if util.get_xml_path(pool.XMLDesc(0), "/pool/@type") not in FILE_POOL_TYPES:
raise util.OperationError(_("The cloud-init seed needs a directory storage pool for the disk"))
_check_macs(conn, data)
+ _check_networks(conn, data)
if data["firmware"] and data["firmware"] not in conn.get_firmwares(data["arch"], data["machine"]):
raise util.OperationError(_("This host offers no firmware %(firmware)s"), firmware=data["firmware"])
if data["tpm"] and not conn.get_tpm_model(data["arch"], data["machine"]):
@@ -925,6 +938,7 @@ class CreateInstance(Kind):
raise util.OperationError(_("A virtual machine with this name already exists"))
_check_disk_name(conn, op.params)
_check_macs(conn, op.params)
+ _check_networks(conn, op.params) # one deleted since the job was queued
def run(self, op, ctx):
data = op.params
diff --git a/instances/tests/test_cloud_init_create.py b/instances/tests/test_cloud_init_create.py
index f70f0148..fe37d9ab 100644
--- a/instances/tests/test_cloud_init_create.py
+++ b/instances/tests/test_cloud_init_create.py
@@ -35,6 +35,7 @@ class CloudInitCreateTestCase(TransactionTestCase):
missing.get_error_code = lambda: libvirt.VIR_ERR_NO_DOMAIN
self.conn.wvm.lookupByUUIDString.side_effect = missing # until the job defines the VM
self.conn.get_instances.return_value = []
+ self.conn.get_networks.return_value = ["default"]
self.conn.get_cache_modes.return_value = {"none": "Disable cache"}
self.conn.get_firmwares.return_value = ["BIOS", "UEFI", "UEFI Secure Boot"]
self.conn.get_dom_capabilities.return_value = {"cpu_modes": ["host-model"]}
diff --git a/instances/tests/test_create_job.py b/instances/tests/test_create_job.py
index a845f8cb..c082faa9 100644
--- a/instances/tests/test_create_job.py
+++ b/instances/tests/test_create_job.py
@@ -30,6 +30,8 @@ class CreateJobTestCase(TransactionTestCase):
self.conn = patcher.start().return_value
self.addCleanup(patcher.stop)
self.conn.get_instances.return_value = []
+ self.conn.get_networks.return_value = ["default"]
+ self.conn.get_nwfilters.return_value = ["clean-traffic"]
self.conn.get_cache_modes.return_value = {"none": "Disable cache"}
self.conn.get_firmwares.return_value = ["BIOS", "UEFI", "UEFI Secure Boot"]
self.conn.get_disk_bus_types.return_value = ["virtio", "sata"]
@@ -187,6 +189,29 @@ class CreateJobTestCase(TransactionTestCase):
with self.assertRaises(PermissionDenied):
CreateInstance().precheck(op, None)
+ def test_a_network_or_filter_deleted_while_queued_is_refused(self):
+ # the VM would be defined with a card it cannot start with
+ response = self.client.post(f"/api/v1/computes/{self.compute.pk}/instances/create/x86_64/q35/",
+ {**BODY, "nwfilter": "clean-traffic"}, content_type="application/json")
+ self.assertEqual(response.status_code, 202)
+ op = Operation.objects.get()
+ CreateInstance().precheck(op, None)
+ self.conn.get_nwfilters.return_value = []
+ with self.assertRaisesMessage(libvirt.libvirtError, "This host has no network filter clean-traffic"):
+ CreateInstance().precheck(op, None)
+ self.conn.get_networks.return_value = []
+ with self.assertRaisesMessage(libvirt.libvirtError, "This host has no network default"):
+ CreateInstance().precheck(op, None)
+
+ def test_a_network_card_without_a_network_is_refused(self):
+ # else the VM would be defined with once its disks are made
+ url = f"/api/v1/computes/{self.compute.pk}/instances/create/x86_64/q35/"
+ for networks in ("default,", ","):
+ with self.subTest(networks=networks):
+ response = self.client.post(url, {**BODY, "networks": networks}, content_type="application/json")
+ self.assertContains(response, "Each network card needs a network", status_code=400)
+ self.assertFalse(Operation.objects.exists())
+
def test_a_mac_of_another_vm_on_the_host_is_refused(self):
url = f"/api/v1/computes/{self.compute.pk}/instances/create/x86_64/q35/"
nic = ""
diff --git a/instances/tests/test_create_rollback.py b/instances/tests/test_create_rollback.py
index 12c689e9..e83f969a 100644
--- a/instances/tests/test_create_rollback.py
+++ b/instances/tests/test_create_rollback.py
@@ -36,6 +36,7 @@ class CreateRollbackTestCase(TestCase):
conn.get_firmwares.return_value = ["BIOS", "UEFI", "UEFI Secure Boot"]
conn.get_dom_capabilities.return_value = {"cpu_modes": ["host-model"]}
conn.get_instances.return_value = []
+ conn.get_networks.return_value = ["default"]
conn.create_volume.return_value = "/pool/rb-vm.qcow2"
missing = libvirtError("no domain")
missing.get_error_code = lambda: VIR_ERR_NO_DOMAIN
diff --git a/locale/tr/LC_MESSAGES/django.mo b/locale/tr/LC_MESSAGES/django.mo
index 40457431..2855ec63 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 90aea246..9818bba9 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 09:58+0000\n"
+"POT-Creation-Date: 2026-11-12 10:25+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"
@@ -2975,7 +2975,7 @@ msgstr ""
msgid "Clone VM"
msgstr "Sanal makineyi klonla"
-#: instances/jobs.py:637 instances/jobs.py:644 instances/jobs.py:953
+#: instances/jobs.py:637 instances/jobs.py:644 instances/jobs.py:967
msgid "Copying disks"
msgstr "Diskler kopyalanıyor"
@@ -3055,74 +3055,88 @@ msgstr ""
"İmaj zaten mevcut. Lütfen ya makine adını değişin ya da disk alanlarını "
"kontrol edin"
-#: instances/jobs.py:852
+#: instances/jobs.py:844
+msgid "Each network card needs a network"
+msgstr "Her ağ kartının bir ağı olmalı"
+
+#: instances/jobs.py:846 vrtManager/instance.py:2767
+#, python-format
+msgid "This host has no network %(name)s"
+msgstr "Bu sunucuda %(name)s ağı yok"
+
+#: instances/jobs.py:848 vrtManager/instance.py:2769
+#, python-format
+msgid "This host has no network filter %(name)s"
+msgstr "Bu sunucuda %(name)s ağ filtresi yok"
+
+#: instances/jobs.py:864
#, python-format
msgid "MAC address %(mac)s is a NIC's of another VM on this host"
msgstr ""
"%(mac)s MAC adresi bu sunucudaki başka bir sanal makinenin ağ kartının adresi"
-#: instances/jobs.py:859 instances/templates/create_instance_w1.html:60
+#: instances/jobs.py:871 instances/templates/create_instance_w1.html:60
#: instances/templates/create_instance_w2.html:356
msgid "Create VM"
msgstr "Sanal makine oluştur"
-#: instances/jobs.py:883 instances/jobs.py:925 instances/views.py:2519
+#: instances/jobs.py:895 instances/jobs.py:938 instances/views.py:2519
msgid "A virtual machine with this name already exists"
msgstr "Bu isimde bir sanal makine mevcut"
-#: instances/jobs.py:885 instances/jobs.py:921
+#: instances/jobs.py:897 instances/jobs.py:934
msgid "There is an instance with same name. Remove it and try again!"
msgstr "Aynı isimde başka bir sanal makine var. Onu silip yeniden deneyin!"
-#: instances/jobs.py:888
+#: instances/jobs.py:900
msgid "First you need to create or select an image"
msgstr "Öncelikle bir imaj oluşturun ya da mevcut bir imajı seçin"
-#: instances/jobs.py:890
+#: instances/jobs.py:902
msgid "Choose one disk source: a new disk, existing volumes or a template"
msgstr ""
"Tek bir disk kaynağı seçin: yeni bir disk, mevcut birimler ya da bir şablon"
-#: instances/jobs.py:893
+#: instances/jobs.py:905
msgid "Invalid cache mode"
msgstr "Geçersiz önbellek modu"
-#: instances/jobs.py:895
+#: instances/jobs.py:907
#, python-format
msgid "This host offers no CPU mode or model %(mode)s"
msgstr "Bu sunucu %(mode)s CPU modunu veya modelini sunmuyor"
-#: instances/jobs.py:897
+#: instances/jobs.py:909
#, python-format
msgid "A CD-ROM cannot use the %(bus)s bus"
msgstr "CD-ROM %(bus)s veri yolunu kullanamaz"
-#: instances/jobs.py:900
+#: instances/jobs.py:912
msgid "The cloud-init seed is read from a CD-ROM: choose its bus"
msgstr "cloud-init tohumu bir CD-ROM'dan okunur: veri yolunu seçin"
-#: instances/jobs.py:903
+#: instances/jobs.py:915
msgid "The cloud-init seed needs a directory storage pool for the disk"
msgstr "cloud-init tohumu, disk için bir dizin depolama havuzu gerektirir"
-#: instances/jobs.py:906
+#: instances/jobs.py:919
#, python-format
msgid "This host offers no firmware %(firmware)s"
msgstr "Bu sunucu %(firmware)s firmware'ini sunmuyor"
-#: instances/jobs.py:908 vrtManager/instance.py:3116
+#: instances/jobs.py:921 vrtManager/instance.py:3116
msgid "This host offers no TPM 2.0: install swtpm on it"
msgstr "Bu sunucu TPM 2.0 sunmuyor: üzerine swtpm kurun"
-#: instances/jobs.py:973
+#: instances/jobs.py:987
msgid "Writing the cloud-init seed"
msgstr "cloud-init tohumu yazılıyor"
-#: instances/jobs.py:980
+#: instances/jobs.py:994
msgid "Defining the VM"
msgstr "Sanal makine tanımlanıyor"
-#: instances/jobs.py:1022
+#: instances/jobs.py:1036
#, python-format
msgid ""
"The panel failed unexpectedly; its log has the details. Remove these volumes "
@@ -3131,114 +3145,114 @@ msgstr ""
"Panel beklenmedik bir hatayla karşılaştı; ayrıntılar panelin günlüğünde. Bu "
"birimleri elle kaldırın: %(volumes)s"
-#: instances/jobs.py:1026
+#: instances/jobs.py:1040
#, python-format
msgid "%(error)s. Remove these volumes by hand: %(volumes)s"
msgstr "%(error)s. Şu birimleri elle silin: %(volumes)s"
-#: instances/jobs.py:1053
+#: instances/jobs.py:1067
#, python-format
msgid "The instance is already on %(compute)s"
msgstr "Sanal makine zaten %(compute)s üzerinde"
-#: instances/jobs.py:1055
+#: instances/jobs.py:1069
#, python-format
msgid "%(compute)s is not reachable"
msgstr "%(compute)s sunucusuna ulaşılamıyor"
-#: instances/jobs.py:1057
+#: instances/jobs.py:1071
#, python-format
msgid "%(compute)s is the VM's own host under another name"
msgstr "%(compute)s, sanal makinenin kendi sunucusunun başka bir adı"
-#: instances/jobs.py:1114
+#: instances/jobs.py:1128
#, python-format
msgid ""
"The VM migrated, but autostart could not be set on the destination: %(error)s"
msgstr ""
"Sanal makine taşındı, ancak hedefte otomatik başlatma ayarlanamadı: %(error)s"
-#: instances/jobs.py:1121
+#: instances/jobs.py:1135
#, python-format
msgid "The VM migrated, but its NVRAM file stays on the source: %(error)s"
msgstr "Sanal makine taşındı, ancak NVRAM dosyası kaynakta kaldı: %(error)s"
-#: instances/jobs.py:1129
+#: instances/jobs.py:1143
msgid "Migrate VM"
msgstr "Sanal makineyi taşı"
-#: instances/jobs.py:1176
+#: instances/jobs.py:1190
msgid "Migrating the VM"
msgstr "Sanal makine taşınıyor"
-#: instances/jobs.py:1225
+#: instances/jobs.py:1239
msgid "libvirt is still migrating the VM"
msgstr "libvirt sanal makineyi hâlâ taşıyor"
-#: instances/jobs.py:1237
+#: instances/jobs.py:1251
msgid "The VM stayed on the source host"
msgstr "Sanal makine kaynak sunucuda kaldı"
-#: instances/jobs.py:1239
+#: instances/jobs.py:1253
msgid ""
"The VM is on both computes or on neither; check them, then resolve this job."
msgstr ""
"Sanal makine ya iki sunucuda da var ya da hiçbirinde yok; kontrol edin, sonra"
" bu işi çözün."
-#: instances/jobs.py:1258
+#: instances/jobs.py:1272
msgid "Move disk"
msgstr "Diski taşı"
-#: instances/jobs.py:1265
+#: instances/jobs.py:1279
msgid "Choose a disk of the VM"
msgstr "Sanal makinenin bir diskini seçin"
-#: instances/jobs.py:1289
+#: instances/jobs.py:1303
msgid "Copying the disk"
msgstr "Disk kopyalanıyor"
-#: instances/jobs.py:1331
+#: instances/jobs.py:1345
#, python-format
msgid "Another block job runs on %(dev)s; check the VM"
msgstr ""
"%(dev)s üzerinde başka bir blok işi çalışıyor; sanal makineyi kontrol edin"
-#: instances/jobs.py:1337
+#: instances/jobs.py:1351
#, python-format
msgid "The disk stayed in %(path)s; remove %(dest)s if it is there"
msgstr "Disk %(path)s içinde kaldı; varsa %(dest)s dosyasını silin"
-#: instances/jobs.py:1339
+#: instances/jobs.py:1353
#, python-format
msgid "The definitions of %(dev)s name %(paths)s; check the VM"
msgstr "%(dev)s tanımları %(paths)s gösteriyor; sanal makineyi kontrol edin"
-#: instances/jobs.py:1346
+#: instances/jobs.py:1360
#, python-format
msgid "Disk %(path)s was kept: a disk file that stays needs it"
msgstr "%(path)s diski korundu: kalan bir disk dosyası ona ihtiyaç duyuyor"
-#: instances/jobs.py:1347
+#: instances/jobs.py:1361
#, python-format
msgid "The VM is removed, but disk %(path)s was not deleted: %(err)s"
msgstr "Sanal makine kaldırıldı, ancak %(path)s diski silinmedi: %(err)s"
-#: instances/jobs.py:1348
+#: instances/jobs.py:1362
#, python-format
msgid "Disk %(path)s is used by another VM and was kept"
msgstr ""
"%(path)s diski başka bir sanal makine tarafından kullanılıyor ve korundu"
-#: instances/jobs.py:1402
+#: instances/jobs.py:1416
msgid "Delete VM"
msgstr "Sanal makineyi sil"
-#: instances/jobs.py:1432
+#: instances/jobs.py:1446
msgid "Deleting the VM"
msgstr "Sanal makine siliniyor"
-#: instances/jobs.py:1444
+#: instances/jobs.py:1458
msgid "The VM was not deleted; it may have been shut off"
msgstr "Sanal makine silinmedi; kapatılmış olabilir"
@@ -6489,7 +6503,7 @@ msgstr ""
msgid "Select a network interface and a QoS direction"
msgstr "Bir ağ arabirimi ve bir QoS yönü seçin"
-#: instances/views.py:2244 vrtManager/network.py:463
+#: instances/views.py:2244 vrtManager/network.py:470
msgid "QoS rates must be whole numbers"
msgstr "QoS hızları tam sayı olmalıdır"
@@ -7022,19 +7036,23 @@ msgid "The pool name must not contain any special characters"
msgstr "Havuz adı herhangi bir özel karakter içermemelidir"
#: networks/forms.py:59
+msgid "The name must have a character other than '.'"
+msgstr "Adda '.' dışında bir karakter olmalı"
+
+#: networks/forms.py:61
msgid "This host has a network of that name"
msgstr "Bu sunucuda bu adda bir ağ var"
-#: networks/forms.py:72
+#: networks/forms.py:74
msgid "The pool bridge name must not contain any special characters"
msgstr "Havuz köprü adı herhangi bir özel karakter içeremez"
-#: networks/forms.py:83 networks/forms.py:87 networks/forms.py:91
+#: networks/forms.py:85 networks/forms.py:89 networks/forms.py:93
#: storages/forms.py:82
msgid "This field is required."
msgstr "Bu alan gerekli."
-#: networks/forms.py:101
+#: networks/forms.py:103
#, python-format
msgid "Network %(net)s has %(subnet)s"
msgstr "%(net)s ağı %(subnet)s alt ağını kullanıyor"
@@ -9636,16 +9654,6 @@ msgstr ""
msgid "Volume %(name)s already exists in storage pool %(pool)s"
msgstr "%(name)s birimi %(pool)s depolama havuzunda zaten var"
-#: vrtManager/instance.py:2767
-#, python-format
-msgid "This host has no network %(name)s"
-msgstr "Bu sunucuda %(name)s ağı yok"
-
-#: vrtManager/instance.py:2769
-#, python-format
-msgid "This host has no network filter %(name)s"
-msgstr "Bu sunucuda %(name)s ağ filtresi yok"
-
#: vrtManager/instance.py:2806
msgid "A network interface that is a host device is removed in the XML editor"
msgstr "Sunucu aygıtı olan bir ağ arabirimi XML düzenleyicide kaldırılır"
@@ -9748,7 +9756,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/interface.py:35 vrtManager/network.py:194
#, python-format
msgid ""
"%(err)s; rolling the change back failed too, the host's configuration may be "
@@ -9757,12 +9765,21 @@ 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:269
+#: vrtManager/interface.py:260
+#, 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 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
#, python-format
msgid "Stop interface %(iface)s before deleting it"
msgstr "%(iface)s arabirimini silmeden önce durdurun"
-#: vrtManager/interface.py:273
+#: vrtManager/interface.py:279
#, python-format
msgid ""
"Bridge %(iface)s has addresses and several members: give the addresses to one"
@@ -9771,7 +9788,7 @@ msgstr ""
"%(iface)s köprüsünün adresleri ve birden fazla üyesi var: önce adresleri "
"sunucuda üyelerden birine verin"
-#: vrtManager/network.py:300
+#: vrtManager/network.py:306
#, python-format
msgid ""
"Network %(net)s is in use by the running VMs %(vms)s; shut them down or "
@@ -9780,7 +9797,7 @@ msgstr ""
"%(net)s ağı çalışan %(vms)s sanal makineleri tarafından kullanılıyor; önce "
"onları kapatın veya ağ kartlarını kaldırın"
-#: vrtManager/network.py:306
+#: vrtManager/network.py:312
#, python-format
msgid ""
"VMs %(vms)s use network %(net)s and would no longer start; remove their "
@@ -9789,7 +9806,7 @@ msgstr ""
"%(vms)s sanal makineleri %(net)s ağını kullanıyor ve artık başlamaz; önce ağ "
"kartlarını kaldırın"
-#: vrtManager/network.py:315
+#: vrtManager/network.py:321
#, python-format
msgid ""
"Network %(net)s runs with other addresses than it has saved; stop and start "
@@ -9798,117 +9815,117 @@ msgstr ""
"%(net)s ağı kayıtlı olandan farklı adreslerle çalışıyor; önce durdurup "
"başlatın"
-#: vrtManager/network.py:335
+#: vrtManager/network.py:341
#, python-format
msgid "Network %(net)s has no such address"
msgstr "%(net)s ağında böyle bir adres yok"
-#: vrtManager/network.py:340
+#: vrtManager/network.py:346
#, python-format
msgid "The range start %(address)s is not in %(subnet)s"
msgstr "Aralık başlangıcı %(address)s, %(subnet)s içinde değil"
-#: vrtManager/network.py:341
+#: vrtManager/network.py:347
#, python-format
msgid "The range start %(address)s is not in the network"
msgstr "Aralık başlangıcı %(address)s ağın içinde değil"
-#: vrtManager/network.py:342
+#: vrtManager/network.py:348
#, python-format
msgid "The range end %(address)s is not in %(subnet)s"
msgstr "Aralık sonu %(address)s, %(subnet)s içinde değil"
-#: vrtManager/network.py:343
+#: vrtManager/network.py:349
#, python-format
msgid "The range end %(address)s is not in the network"
msgstr "Aralık sonu %(address)s ağın içinde değil"
-#: vrtManager/network.py:344
+#: vrtManager/network.py:350
#, python-format
msgid "The fixed address %(address)s is not in %(subnet)s"
msgstr "Sabit adres %(address)s, %(subnet)s içinde değil"
-#: vrtManager/network.py:345
+#: vrtManager/network.py:351
#, python-format
msgid "The fixed address %(address)s is not in the network"
msgstr "Sabit adres %(address)s ağın içinde değil"
-#: vrtManager/network.py:354
+#: vrtManager/network.py:360
#, python-format
msgid "%(address)s is not an IP address"
msgstr "%(address)s bir IP adresi değil"
-#: vrtManager/network.py:359
+#: vrtManager/network.py:365
#, python-format
msgid "%(address)s is the host's own address on the network"
msgstr "%(address)s sunucunun bu ağdaki kendi adresi"
-#: vrtManager/network.py:362
+#: vrtManager/network.py:368
#, python-format
msgid "%(address)s is not a host address of %(subnet)s"
msgstr "%(address)s, %(subnet)s ağında bir makine adresi değil"
-#: vrtManager/network.py:368
+#: vrtManager/network.py:374
#, python-format
msgid "Stop network %(net)s to change its DHCP range"
msgstr "DHCP aralığını değiştirmek için %(net)s ağını durdurun"
-#: vrtManager/network.py:372
+#: vrtManager/network.py:378
#, python-format
msgid "This address of network %(net)s has no DHCP range"
msgstr "%(net)s ağının bu adresinin DHCP aralığı yok"
-#: vrtManager/network.py:376
+#: vrtManager/network.py:382
#, python-format
msgid "The range starts at %(start)s, after its end %(end)s"
msgstr ""
"Aralık, sonu olan %(end)s adresinden sonra, %(start)s adresinde başlıyor"
-#: vrtManager/network.py:378
+#: vrtManager/network.py:384
#, python-format
msgid "The range takes in %(address)s, the host's own address"
msgstr "Aralık, sunucunun kendi adresi olan %(address)s adresini içeriyor"
-#: vrtManager/network.py:387
+#: vrtManager/network.py:393
#, python-format
msgid "Network %(net)s has no fixed address %(address)s"
msgstr "%(net)s ağında %(address)s sabit adresi yok"
-#: vrtManager/network.py:405
-#, python-format
-msgid "The name %(name)s may have only letters, digits, '.', '_' and '-'"
-msgstr "%(name)s adında yalnızca harf, rakam, '.', '_' ve '-' olabilir"
-
-#: vrtManager/network.py:414
+#: vrtManager/network.py:418
#, python-format
msgid "The fixed address %(original)s has changed meanwhile; reload the page"
msgstr "%(original)s sabit adresi bu arada değişti; sayfayı yeniden yükleyin"
-#: vrtManager/network.py:419
+#: vrtManager/network.py:421
+#, python-format
+msgid "The name %(name)s may have only letters, digits, '.', '_' and '-'"
+msgstr "%(name)s adında yalnızca harf, rakam, '.', '_' ve '-' olabilir"
+
+#: vrtManager/network.py:426
#, python-format
msgid "%(address)s is another entry's fixed address"
msgstr "%(address)s başka bir kaydın sabit adresi"
-#: vrtManager/network.py:421
+#: vrtManager/network.py:428
#, python-format
msgid "%(mac_duid)s has another fixed address, %(other)s"
msgstr "%(mac_duid)s için başka bir sabit adres var: %(other)s"
-#: vrtManager/network.py:423
+#: vrtManager/network.py:430
#, python-format
msgid "The name %(name)s has another fixed address, %(other)s"
msgstr "%(name)s adı için başka bir sabit adres var: %(other)s"
-#: vrtManager/network.py:459
+#: vrtManager/network.py:466
msgid "Direction must be inbound or outbound"
msgstr "Yön gelen ya da giden olmalı"
-#: vrtManager/network.py:486
+#: vrtManager/network.py:493
#, python-format
msgid "The XML must define network %(net)s"
msgstr "XML, %(net)s ağını tanımlamalıdır"
-#: vrtManager/network.py:488
+#: vrtManager/network.py:495
msgid "The XML must keep the network's UUID"
msgstr "XML, ağın UUID değerini korumalıdır"
diff --git a/locale/zh/LC_MESSAGES/django.mo b/locale/zh/LC_MESSAGES/django.mo
index e7761fff..2c1ff52a 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 0e325ac9..716ab893 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 09:58+0000\n"
+"POT-Creation-Date: 2026-11-12 10:25+0000\n"
"PO-Revision-Date: \n"
"Last-Translator: \n"
"Language-Team: \n"
@@ -2856,7 +2856,7 @@ msgstr "无法解冻客户机的文件系统(%(error)s);请用以下命令
msgid "Clone VM"
msgstr "克隆虚拟机"
-#: instances/jobs.py:637 instances/jobs.py:644 instances/jobs.py:953
+#: instances/jobs.py:637 instances/jobs.py:644 instances/jobs.py:967
msgid "Copying disks"
msgstr "正在复制磁盘"
@@ -2922,181 +2922,195 @@ msgstr "磁盘已复制,但无法定义克隆:%(error)s;请检查这些卷
msgid "Image has already exist. Please check volumes or change instance name"
msgstr "镜像已存在。请检查卷或更改虚拟机名称"
-#: instances/jobs.py:852
+#: instances/jobs.py:844
+msgid "Each network card needs a network"
+msgstr "每个网卡都需要一个网络"
+
+#: instances/jobs.py:846 vrtManager/instance.py:2767
+#, python-format
+msgid "This host has no network %(name)s"
+msgstr "此主机没有网络 %(name)s"
+
+#: instances/jobs.py:848 vrtManager/instance.py:2769
+#, python-format
+msgid "This host has no network filter %(name)s"
+msgstr "此主机没有网络过滤器 %(name)s"
+
+#: instances/jobs.py:864
#, python-format
msgid "MAC address %(mac)s is a NIC's of another VM on this host"
msgstr "MAC 地址 %(mac)s 已属于此主机上另一台虚拟机的网卡"
-#: instances/jobs.py:859 instances/templates/create_instance_w1.html:60
+#: instances/jobs.py:871 instances/templates/create_instance_w1.html:60
#: instances/templates/create_instance_w2.html:356
msgid "Create VM"
msgstr "创建虚拟机"
-#: instances/jobs.py:883 instances/jobs.py:925 instances/views.py:2519
+#: instances/jobs.py:895 instances/jobs.py:938 instances/views.py:2519
msgid "A virtual machine with this name already exists"
msgstr "同名虚拟机已存在"
-#: instances/jobs.py:885 instances/jobs.py:921
+#: instances/jobs.py:897 instances/jobs.py:934
msgid "There is an instance with same name. Remove it and try again!"
msgstr "已存在同名虚拟机。请删除后重试!"
-#: instances/jobs.py:888
+#: instances/jobs.py:900
msgid "First you need to create or select an image"
msgstr "请先创建或选择一个镜像"
-#: instances/jobs.py:890
+#: instances/jobs.py:902
msgid "Choose one disk source: a new disk, existing volumes or a template"
msgstr "请选择一种磁盘来源:新磁盘、现有卷或模板"
-#: instances/jobs.py:893
+#: instances/jobs.py:905
msgid "Invalid cache mode"
msgstr "无效的缓存模式"
-#: instances/jobs.py:895
+#: instances/jobs.py:907
#, python-format
msgid "This host offers no CPU mode or model %(mode)s"
msgstr "此主机不提供 CPU 模式或型号 %(mode)s"
-#: instances/jobs.py:897
+#: instances/jobs.py:909
#, python-format
msgid "A CD-ROM cannot use the %(bus)s bus"
msgstr "CD-ROM 不能使用 %(bus)s 总线"
-#: instances/jobs.py:900
+#: instances/jobs.py:912
msgid "The cloud-init seed is read from a CD-ROM: choose its bus"
msgstr "cloud-init 种子从 CD-ROM 读取:请选择其总线"
-#: instances/jobs.py:903
+#: instances/jobs.py:915
msgid "The cloud-init seed needs a directory storage pool for the disk"
msgstr "cloud-init 种子需要为磁盘使用目录类型的存储池"
-#: instances/jobs.py:906
+#: instances/jobs.py:919
#, python-format
msgid "This host offers no firmware %(firmware)s"
msgstr "此主机不提供固件 %(firmware)s"
-#: instances/jobs.py:908 vrtManager/instance.py:3116
+#: instances/jobs.py:921 vrtManager/instance.py:3116
msgid "This host offers no TPM 2.0: install swtpm on it"
msgstr "此主机不提供 TPM 2.0:请在主机上安装 swtpm"
-#: instances/jobs.py:973
+#: instances/jobs.py:987
msgid "Writing the cloud-init seed"
msgstr "正在写入 cloud-init 种子"
-#: instances/jobs.py:980
+#: instances/jobs.py:994
msgid "Defining the VM"
msgstr "正在定义虚拟机"
-#: instances/jobs.py:1022
+#: instances/jobs.py:1036
#, python-format
msgid ""
"The panel failed unexpectedly; its log has the details. Remove these volumes "
"by hand: %(volumes)s"
msgstr "面板发生意外错误;详细信息见面板日志。请手动删除这些卷:%(volumes)s"
-#: instances/jobs.py:1026
+#: instances/jobs.py:1040
#, python-format
msgid "%(error)s. Remove these volumes by hand: %(volumes)s"
msgstr "%(error)s。请手动删除这些卷:%(volumes)s"
-#: instances/jobs.py:1053
+#: instances/jobs.py:1067
#, python-format
msgid "The instance is already on %(compute)s"
msgstr "虚拟机已在 %(compute)s 上"
-#: instances/jobs.py:1055
+#: instances/jobs.py:1069
#, python-format
msgid "%(compute)s is not reachable"
msgstr "无法连接 %(compute)s"
-#: instances/jobs.py:1057
+#: instances/jobs.py:1071
#, python-format
msgid "%(compute)s is the VM's own host under another name"
msgstr "%(compute)s 是该虚拟机所在主机的另一个名称"
-#: instances/jobs.py:1114
+#: instances/jobs.py:1128
#, python-format
msgid ""
"The VM migrated, but autostart could not be set on the destination: %(error)s"
msgstr "虚拟机已迁移,但无法在目标主机上设置自动启动:%(error)s"
-#: instances/jobs.py:1121
+#: instances/jobs.py:1135
#, python-format
msgid "The VM migrated, but its NVRAM file stays on the source: %(error)s"
msgstr "虚拟机已迁移,但其 NVRAM 文件仍留在源主机上:%(error)s"
-#: instances/jobs.py:1129
+#: instances/jobs.py:1143
msgid "Migrate VM"
msgstr "迁移虚拟机"
-#: instances/jobs.py:1176
+#: instances/jobs.py:1190
msgid "Migrating the VM"
msgstr "正在迁移虚拟机"
-#: instances/jobs.py:1225
+#: instances/jobs.py:1239
msgid "libvirt is still migrating the VM"
msgstr "libvirt 仍在迁移虚拟机"
-#: instances/jobs.py:1237
+#: instances/jobs.py:1251
msgid "The VM stayed on the source host"
msgstr "虚拟机留在了源主机上"
-#: instances/jobs.py:1239
+#: instances/jobs.py:1253
msgid ""
"The VM is on both computes or on neither; check them, then resolve this job."
msgstr "虚拟机同时位于两个计算节点上,或都不在;请检查后处理此任务。"
-#: instances/jobs.py:1258
+#: instances/jobs.py:1272
msgid "Move disk"
msgstr "移动磁盘"
-#: instances/jobs.py:1265
+#: instances/jobs.py:1279
msgid "Choose a disk of the VM"
msgstr "请选择虚拟机的一个磁盘"
-#: instances/jobs.py:1289
+#: instances/jobs.py:1303
msgid "Copying the disk"
msgstr "正在复制磁盘"
-#: instances/jobs.py:1331
+#: instances/jobs.py:1345
#, python-format
msgid "Another block job runs on %(dev)s; check the VM"
msgstr "%(dev)s 上正在运行另一个块任务;请检查虚拟机"
-#: instances/jobs.py:1337
+#: instances/jobs.py:1351
#, python-format
msgid "The disk stayed in %(path)s; remove %(dest)s if it is there"
msgstr "磁盘仍在 %(path)s;如果 %(dest)s 存在,请将其删除"
-#: instances/jobs.py:1339
+#: instances/jobs.py:1353
#, python-format
msgid "The definitions of %(dev)s name %(paths)s; check the VM"
msgstr "%(dev)s 的定义指向 %(paths)s;请检查虚拟机"
-#: instances/jobs.py:1346
+#: instances/jobs.py:1360
#, python-format
msgid "Disk %(path)s was kept: a disk file that stays needs it"
msgstr "磁盘 %(path)s 已保留:某个保留的磁盘文件依赖它"
-#: instances/jobs.py:1347
+#: instances/jobs.py:1361
#, python-format
msgid "The VM is removed, but disk %(path)s was not deleted: %(err)s"
msgstr "虚拟机已删除,但磁盘 %(path)s 未被删除:%(err)s"
-#: instances/jobs.py:1348
+#: instances/jobs.py:1362
#, python-format
msgid "Disk %(path)s is used by another VM and was kept"
msgstr "磁盘 %(path)s 正被另一台虚拟机使用,已保留"
-#: instances/jobs.py:1402
+#: instances/jobs.py:1416
msgid "Delete VM"
msgstr "删除虚拟机"
-#: instances/jobs.py:1432
+#: instances/jobs.py:1446
msgid "Deleting the VM"
msgstr "正在删除虚拟机"
-#: instances/jobs.py:1444
+#: instances/jobs.py:1458
msgid "The VM was not deleted; it may have been shut off"
msgstr "虚拟机未被删除;它可能已被关闭"
@@ -6126,7 +6140,7 @@ msgstr "已请求移除 PCI 设备 %(address)s:客户机尚未释放它;在
msgid "Select a network interface and a QoS direction"
msgstr "请选择网络接口和 QoS 方向"
-#: instances/views.py:2244 vrtManager/network.py:463
+#: instances/views.py:2244 vrtManager/network.py:470
msgid "QoS rates must be whole numbers"
msgstr "QoS 速率必须为整数"
@@ -6632,19 +6646,23 @@ msgid "The pool name must not contain any special characters"
msgstr "地址池名称不能包含特殊字符"
#: networks/forms.py:59
+msgid "The name must have a character other than '.'"
+msgstr "名称必须包含 '.' 以外的字符"
+
+#: networks/forms.py:61
msgid "This host has a network of that name"
msgstr "此主机已有同名网络"
-#: networks/forms.py:72
+#: networks/forms.py:74
msgid "The pool bridge name must not contain any special characters"
msgstr "地址池网桥名称不能包含特殊字符"
-#: networks/forms.py:83 networks/forms.py:87 networks/forms.py:91
+#: networks/forms.py:85 networks/forms.py:89 networks/forms.py:93
#: storages/forms.py:82
msgid "This field is required."
msgstr "此字段为必填项。"
-#: networks/forms.py:101
+#: networks/forms.py:103
#, python-format
msgid "Network %(net)s has %(subnet)s"
msgstr "网络 %(net)s 已使用 %(subnet)s"
@@ -9074,16 +9092,6 @@ msgstr ""
msgid "Volume %(name)s already exists in storage pool %(pool)s"
msgstr "卷 %(name)s 已存在于存储池 %(pool)s 中"
-#: vrtManager/instance.py:2767
-#, python-format
-msgid "This host has no network %(name)s"
-msgstr "此主机没有网络 %(name)s"
-
-#: vrtManager/instance.py:2769
-#, python-format
-msgid "This host has no network filter %(name)s"
-msgstr "此主机没有网络过滤器 %(name)s"
-
#: vrtManager/instance.py:2806
msgid "A network interface that is a host device is removed in the XML editor"
msgstr "作为主机设备的网络接口需在 XML 编辑器中删除"
@@ -9179,156 +9187,163 @@ msgstr "未知的崩溃操作 %(action)s"
msgid "Network interface %(mac)s is not in the definition"
msgstr "网络接口 %(mac)s 不在定义中"
-#: vrtManager/interface.py:35
+#: vrtManager/interface.py:35 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:269
+#: vrtManager/interface.py:260
+#, 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
#, python-format
msgid "Stop interface %(iface)s before deleting it"
msgstr "删除接口 %(iface)s 前请先停止它"
-#: vrtManager/interface.py:273
+#: vrtManager/interface.py:279
#, python-format
msgid ""
"Bridge %(iface)s has addresses and several members: give the addresses to one"
" of them on the host first"
msgstr "网桥 %(iface)s 有地址和多个成员:请先在主机上把地址分配给其中一个成员"
-#: vrtManager/network.py:300
+#: vrtManager/network.py:306
#, python-format
msgid ""
"Network %(net)s is in use by the running VMs %(vms)s; shut them down or "
"remove their network cards first"
msgstr "网络 %(net)s 正被运行中的虚拟机 %(vms)s 使用;请先关闭它们或移除其网卡"
-#: vrtManager/network.py:306
+#: vrtManager/network.py:312
#, python-format
msgid ""
"VMs %(vms)s use network %(net)s and would no longer start; remove their "
"network cards first"
msgstr "虚拟机 %(vms)s 使用网络 %(net)s,将无法再启动;请先移除其网卡"
-#: vrtManager/network.py:315
+#: vrtManager/network.py:321
#, python-format
msgid ""
"Network %(net)s runs with other addresses than it has saved; stop and start "
"it first"
msgstr "网络 %(net)s 运行时的地址与其保存的地址不同;请先停止再启动它"
-#: vrtManager/network.py:335
+#: vrtManager/network.py:341
#, python-format
msgid "Network %(net)s has no such address"
msgstr "网络 %(net)s 没有此地址"
-#: vrtManager/network.py:340
+#: vrtManager/network.py:346
#, python-format
msgid "The range start %(address)s is not in %(subnet)s"
msgstr "范围起始 %(address)s 不在 %(subnet)s 中"
-#: vrtManager/network.py:341
+#: vrtManager/network.py:347
#, python-format
msgid "The range start %(address)s is not in the network"
msgstr "范围起始 %(address)s 不在网络中"
-#: vrtManager/network.py:342
+#: vrtManager/network.py:348
#, python-format
msgid "The range end %(address)s is not in %(subnet)s"
msgstr "范围结束 %(address)s 不在 %(subnet)s 中"
-#: vrtManager/network.py:343
+#: vrtManager/network.py:349
#, python-format
msgid "The range end %(address)s is not in the network"
msgstr "范围结束 %(address)s 不在网络中"
-#: vrtManager/network.py:344
+#: vrtManager/network.py:350
#, python-format
msgid "The fixed address %(address)s is not in %(subnet)s"
msgstr "固定地址 %(address)s 不在 %(subnet)s 中"
-#: vrtManager/network.py:345
+#: vrtManager/network.py:351
#, python-format
msgid "The fixed address %(address)s is not in the network"
msgstr "固定地址 %(address)s 不在网络中"
-#: vrtManager/network.py:354
+#: vrtManager/network.py:360
#, python-format
msgid "%(address)s is not an IP address"
msgstr "%(address)s 不是 IP 地址"
-#: vrtManager/network.py:359
+#: vrtManager/network.py:365
#, python-format
msgid "%(address)s is the host's own address on the network"
msgstr "%(address)s 是主机自己在该网络上的地址"
-#: vrtManager/network.py:362
+#: vrtManager/network.py:368
#, python-format
msgid "%(address)s is not a host address of %(subnet)s"
msgstr "%(address)s 不是 %(subnet)s 中的主机地址"
-#: vrtManager/network.py:368
+#: vrtManager/network.py:374
#, python-format
msgid "Stop network %(net)s to change its DHCP range"
msgstr "请停止网络 %(net)s 后再更改其 DHCP 范围"
-#: vrtManager/network.py:372
+#: vrtManager/network.py:378
#, python-format
msgid "This address of network %(net)s has no DHCP range"
msgstr "网络 %(net)s 的此地址没有 DHCP 范围"
-#: vrtManager/network.py:376
+#: vrtManager/network.py:382
#, python-format
msgid "The range starts at %(start)s, after its end %(end)s"
msgstr "范围起始 %(start)s 在其结束 %(end)s 之后"
-#: vrtManager/network.py:378
+#: vrtManager/network.py:384
#, python-format
msgid "The range takes in %(address)s, the host's own address"
msgstr "范围包含主机自己的地址 %(address)s"
-#: vrtManager/network.py:387
+#: vrtManager/network.py:393
#, python-format
msgid "Network %(net)s has no fixed address %(address)s"
msgstr "网络 %(net)s 没有固定地址 %(address)s"
-#: vrtManager/network.py:405
-#, python-format
-msgid "The name %(name)s may have only letters, digits, '.', '_' and '-'"
-msgstr "名称 %(name)s 只能包含字母、数字、'.'、'_' 和 '-'"
-
-#: vrtManager/network.py:414
+#: vrtManager/network.py:418
#, python-format
msgid "The fixed address %(original)s has changed meanwhile; reload the page"
msgstr "固定地址 %(original)s 在此期间已更改;请重新加载页面"
-#: vrtManager/network.py:419
+#: vrtManager/network.py:421
+#, python-format
+msgid "The name %(name)s may have only letters, digits, '.', '_' and '-'"
+msgstr "名称 %(name)s 只能包含字母、数字、'.'、'_' 和 '-'"
+
+#: vrtManager/network.py:426
#, python-format
msgid "%(address)s is another entry's fixed address"
msgstr "%(address)s 是另一条目的固定地址"
-#: vrtManager/network.py:421
+#: vrtManager/network.py:428
#, python-format
msgid "%(mac_duid)s has another fixed address, %(other)s"
msgstr "%(mac_duid)s 已有另一个固定地址 %(other)s"
-#: vrtManager/network.py:423
+#: vrtManager/network.py:430
#, python-format
msgid "The name %(name)s has another fixed address, %(other)s"
msgstr "名称 %(name)s 已有另一个固定地址 %(other)s"
-#: vrtManager/network.py:459
+#: vrtManager/network.py:466
msgid "Direction must be inbound or outbound"
msgstr "方向必须是入站或出站"
-#: vrtManager/network.py:486
+#: vrtManager/network.py:493
#, python-format
msgid "The XML must define network %(net)s"
msgstr "XML 必须定义网络 %(net)s"
-#: vrtManager/network.py:488
+#: vrtManager/network.py:495
msgid "The XML must keep the network's UUID"
msgstr "XML 必须保留网络的 UUID"
diff --git a/networks/forms.py b/networks/forms.py
index 002f2f1f..de6c34b1 100644
--- a/networks/forms.py
+++ b/networks/forms.py
@@ -55,6 +55,8 @@ class AddNetPool(forms.Form):
raise forms.ValidationError(
_("The pool name must not contain any special characters")
)
+ if not name.strip("."): # "." and ".." would be no page address of their own
+ raise forms.ValidationError(_("The name must have a character other than '.'"))
if any(net["name"] == name for net in self.networks):
raise forms.ValidationError(_("This host has a network of that name"), code="taken")
return name
diff --git a/networks/tests/test_add_net_pool_form.py b/networks/tests/test_add_net_pool_form.py
index 872ef2a9..835725ca 100644
--- a/networks/tests/test_add_net_pool_form.py
+++ b/networks/tests/test_add_net_pool_form.py
@@ -71,3 +71,12 @@ class ModeTests(SimpleTestCase):
self.assertEqual(errors(forward="nat", subnet="192.0.2.0/24"), [])
f = AddNetPool({"name": "default", "forward": "none"}, networks=NETWORKS)
self.assertTrue(f.has_error("name", "taken"))
+
+
+class NameTests(SimpleTestCase):
+ def test_a_name_of_dots_only_is_refused(self):
+ # its page address /network/../ would be another page
+ for name in (".", "..", "..."):
+ with self.subTest(name=name):
+ self.assertIn("other than '.'", form(name=name, subnet="192.0.2.0/24").errors["name"][0])
+ self.assertTrue(form(name=".lab", subnet="192.0.2.0/24").is_valid())
diff --git a/vrtManager/interface.py b/vrtManager/interface.py
index 48a5bcc7..4a40a77f 100644
--- a/vrtManager/interface.py
+++ b/vrtManager/interface.py
@@ -234,9 +234,10 @@ class wvmInterface(wvmConnect):
return info
def get_vms(self, networks=()):
- """The running VMs' network cards on this bridge, directly or through
- the libvirt networks of networks (which use it): VM, tap device and
- the VM's MAC. One listing, one XML read per running VM."""
+ """The running VMs' network cards on this interface, directly (a
+ bridge's, or a macvtap card's) or through the libvirt networks of
+ networks (which use it): VM, tap device and the VM's MAC. One
+ listing, one XML read per running VM."""
name = self.iface.name()
cards = []
for dom in self.wvm.listAllDomains(VIR_CONNECT_LIST_DOMAINS_ACTIVE):
@@ -248,11 +249,16 @@ class wvmInterface(wvmConnect):
continue
for card in tree.findall("devices/interface"):
source = card.find("source")
- if source is not None and (source.get("bridge") == name or source.get("network") in networks):
+ if source is not None and (name in (source.get("bridge"), source.get("dev")) or source.get("network") in networks):
cards.append({"vm": dom.name(), "tap": attribute(card, "target", "dev"), "mac": attribute(card, "mac", "address")})
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."""
+ name = self.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})))
self.iface.destroy()
def start_iface(self):
diff --git a/vrtManager/network.py b/vrtManager/network.py
index ffc83638..299a59b6 100644
--- a/vrtManager/network.py
+++ b/vrtManager/network.py
@@ -184,10 +184,16 @@ class wvmNetworks(wvmConnect):
net = self.wvm.networkDefineXML(xml)
try:
net.create()
- except libvirtError: # e.g. the subnet is in use: the name stays free for another try
- net.undefine()
+ net.setAutostart(1)
+ except libvirtError as err: # e.g. the subnet is in use: the name stays free for another try
+ try:
+ if net.isActive():
+ net.destroy()
+ net.undefine()
+ except libvirtError as rollback_err:
+ raise util.OperationError(gettext_noop("%(err)s; rolling the change back failed too, the host's configuration may be changed: %(rollback_err)s"),
+ err=err, rollback_err=rollback_err) from err
raise
- net.setAutostart(1)
class wvmNetwork(wvmConnect):
diff --git a/vrtManager/tests/test_interface_reads.py b/vrtManager/tests/test_interface_reads.py
index 05ee0c29..57779d14 100644
--- a/vrtManager/tests/test_interface_reads.py
+++ b/vrtManager/tests/test_interface_reads.py
@@ -117,3 +117,22 @@ class BridgeUseTests(SimpleTestCase):
{"vm": "db", "tap": "vnet7", "mac": "52:54:00:00:00:02"},
{"vm": "web", "tap": "vnet3", "mac": "52:54:00:00:00:01"},
])
+
+ def test_an_interface_a_running_vm_uses_is_not_stopped(self):
+ # a macvtap card on it, or a card on a network that uses it: stopping it would cut the VM off
+ from vrtManager.util import OperationError
+
+ for cards, nets in (("", []),
+ ("",
+ [MagicMock(**{"name.return_value": "direct", "XMLDesc.return_value":
+ ""})])):
+ dom = MagicMock(**{"name.return_value": "web", "XMLDesc.return_value": f"{cards}"})
+ conn = wvmInterface.__new__(wvmInterface)
+ 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"):
+ conn.stop_iface()
+ conn.iface.destroy.assert_not_called()
+ conn.wvm.listAllDomains.return_value = []
+ conn.stop_iface()
+ conn.iface.destroy.assert_called_once()
diff --git a/vrtManager/tests/test_network.py b/vrtManager/tests/test_network.py
index d86659e0..f3d4b9e7 100644
--- a/vrtManager/tests/test_network.py
+++ b/vrtManager/tests/test_network.py
@@ -192,6 +192,22 @@ class NetworkChangeTests(SimpleTestCase):
"n1", "nat", True, gateway, mask, dhcp, False, None, None, None, "", False)
self.assertNotIn("n1", self.conn.listDefinedNetworks() + self.conn.listNetworks())
+ def test_a_rollback_that_fails_is_said_with_the_first_error(self):
+ gateway, mask, dhcp = network_size("192.0.2.0/24", True)
+ with patch.object(libvirt.virNetwork, "setAutostart", side_effect=libvirt.libvirtError("cannot create symlink")), \
+ patch.object(libvirt.virNetwork, "destroy", side_effect=libvirt.libvirtError("device busy")):
+ with self.assertRaisesRegex(OperationError, "cannot create symlink; rolling the change back failed too.*device busy"):
+ wvmNetworks("localhost", "", "", 4).create_network(
+ "n1", "nat", True, gateway, mask, dhcp, False, None, None, None, "", False)
+
+ def test_a_network_whose_autostart_fails_is_not_left_running(self):
+ gateway, mask, dhcp = network_size("192.0.2.0/24", True)
+ with patch.object(libvirt.virNetwork, "setAutostart", side_effect=libvirt.libvirtError("cannot create symlink")):
+ with self.assertRaises(libvirt.libvirtError):
+ wvmNetworks("localhost", "", "", 4).create_network(
+ "n1", "nat", True, gateway, mask, dhcp, False, None, None, None, "", False)
+ self.assertNotIn("n1", self.conn.listDefinedNetworks() + self.conn.listNetworks())
+
class LeasesTests(SimpleTestCase):
def network(self, leases, active=True):