diff --git a/computes/templates/computes/bulk_migrate.html b/computes/templates/computes/bulk_migrate.html index 1b144b46..811748b6 100644 --- a/computes/templates/computes/bulk_migrate.html +++ b/computes/templates/computes/bulk_migrate.html @@ -52,7 +52,13 @@ {% else %} {{ target.name }} {% endif %} -
+ {% if tags %}{# bulk_migrate.js ticks the VMs with the tag chosen #} + + {% endif %} +
@@ -75,11 +81,11 @@ {% if spreading %} - {% if instance.target %}{% endif %} {% else %} - {% endif %} diff --git a/computes/tests/test_bulk_migrate.py b/computes/tests/test_bulk_migrate.py index 66c38d90..0a08ae06 100644 --- a/computes/tests/test_bulk_migrate.py +++ b/computes/tests/test_bulk_migrate.py @@ -61,6 +61,14 @@ class BulkMigratePageTests(TestCase): self.assertIsNone(off.get("checked")) self.assertIsNotNone(off.get("data-shut-off")) + def test_the_vms_tags_choose_them(self): + from computes.models import Tag + self.vms["ev-run"].tags.add(Tag.objects.create(name="prod"), Tag.objects.create(name="web")) + page = self.page() + self.assertEqual(page.xpath("//select[@id='bulk-migrate-tag']/option/@value"), ["", "prod", "web"]) + self.assertEqual(self.box(page, "ev-run").get("data-tags"), "prod web") + self.assertEqual(self.box(page, "ev-off").get("data-tags"), "") + def test_a_vm_with_a_disk_the_hosts_do_not_share_is_refused(self): page = self.page() local = self.box(page, "ev-local") diff --git a/computes/tests/test_bulk_migrate_js.py b/computes/tests/test_bulk_migrate_js.py index 02d5b0a2..0ab34e15 100644 --- a/computes/tests/test_bulk_migrate_js.py +++ b/computes/tests/test_bulk_migrate_js.py @@ -1,7 +1,7 @@ """The Bulk Migrate page's script (static/js/bulk_migrate.js): another destination reloads the list; the header box ticks or unticks every VM that can migrate, "Also migrate the shut-off VMs" only the shut-off ones; a -refused VM stays unticked. The button counts the ticked VMs. Spread over the +refused VM stays unticked; a tag chosen ticks the VMs with it. The button counts the ticked VMs. Spread over the hosts, every change reloads the list.""" import json @@ -15,9 +15,9 @@ SCRIPT = Path(__file__).resolve().parents[2] / "static" / "js" / "bulk_migrate.j RUN = """ const vm = require("vm"); const boxes = [ - {name: "run", checked: true, disabled: false, shutOff: false}, - {name: "off", checked: false, disabled: false, shutOff: true}, - {name: "refused", checked: false, disabled: true, shutOff: false}, + {name: "run", checked: true, disabled: false, shutOff: false, dataset: {tags: "web"}}, + {name: "off", checked: false, disabled: false, shutOff: true, dataset: {tags: "prod web"}}, + {name: "refused", checked: false, disabled: true, shutOff: false, dataset: {tags: "prod"}}, ]; const handlers = {}; const box = (id) => ({id, addEventListener: (name, fn) => { handlers[id] = fn; }}); @@ -29,6 +29,7 @@ const choose = { querySelectorAll: () => [{remove: () => { shownRemoved += 1; }}], }; const ids = {"bulk-migrate-all": box("bulk-migrate-all"), "bulk-migrate-shut-off": box("bulk-migrate-shut-off"), + "bulk-migrate-tag": box("bulk-migrate-tag"), "bulk-migrate-target": box("bulk-migrate-target"), "bulk-migrate-submit": button, "bulk-migrate-count": counter, "bulk-migrate-choose": choose}; const selectors = { @@ -72,6 +73,11 @@ class BulkMigrateScriptTests(unittest.TestCase): result = self.run_script([["bulk-migrate-shut-off", True], ["bulk-migrate-shut-off", False]]) self.assertEqual(result["seen"], [["run", "off"], ["run"]]) + def test_a_tag_ticks_the_vms_with_it_that_can_migrate_and_only_them(self): + result = self.run_script([["bulk-migrate-tag", False, "prod"], ["bulk-migrate-tag", False, ""], + ["bulk-migrate-tag", False, "web"]]) + self.assertEqual(result["seen"], [["off"], ["off"], ["run", "off"]]) # "": the ticks stay + def test_the_button_counts_the_ticked_vms_and_is_off_without_one(self): self.assertEqual(self.run_script([["bulk-migrate-all", False], ["bulk-migrate-all", True]])["counts"], [[1, False], [0, True], [2, False]]) diff --git a/computes/views.py b/computes/views.py index 8d45cb76..6cba58b8 100644 --- a/computes/views.py +++ b/computes/views.py @@ -326,14 +326,15 @@ def bulk_migrate(request, compute_id): reach = Reach(request) spreading = len(targets) > 1 and request.GET.get("target", "spread") == "spread" utils.refresh_instance_database(compute) - instances = list(Instance.objects.filter(compute=compute).order_by("name")) + instances = list(Instance.objects.filter(compute=compute).order_by("name").prefetch_related("tags")) read_list_rows(instances, [compute]) + tags = sorted({tag.name for instance in instances for tag in instance.tags.all()}) if not spreading: target = next((t for t in targets if str(t.pk) == request.GET.get("target")), targets[0] if targets else None) for instance in instances if target else (): instance.refusal = reach.refusal(instance, target) return render(request, "computes/bulk_migrate.html", - {"compute": compute, "targets": targets, "target": target, "instances": instances, + {"compute": compute, "targets": targets, "target": target, "instances": instances, "tags": tags, "parallel": range(1, parallel_limit() + 1), "entering": entering}) # the other hosts' loads: the VMs of this one are read above, also when its capacity cannot be @@ -360,6 +361,7 @@ def bulk_migrate(request, compute_id): going = [instance for instance in instances if instance.target] return render(request, "computes/bulk_migrate.html", {"compute": compute, "targets": targets, "spreading": True, "instances": instances, "entering": entering, + "tags": tags, "all_ticked": len(going) == len([instance for instance in instances if not instance.refusal]), "shut_off_ticked": any(instance.info[0] == 5 for instance in going), "unreachable": [host for host in targets if host.pk not in others], diff --git a/locale/tr/LC_MESSAGES/django.mo b/locale/tr/LC_MESSAGES/django.mo index 3eb3b69b..434d2175 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 55887e29..83b1cfc6 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-18 17:53+0000\n" +"POT-Creation-Date: 2026-11-18 18:18+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" @@ -66,7 +66,7 @@ msgstr "Geçersiz anahtar" #: accounts/forms.py:95 computes/templates/computes/balance.html:61 #: computes/templates/computes/balance.html:108 -#: computes/templates/computes/bulk_migrate.html:65 +#: computes/templates/computes/bulk_migrate.html:71 #: computes/templates/computes/instances.html:53 #: instances/templates/add_instance_volume.html:39 #: instances/templates/allinstances_index_grouped.html:11 @@ -798,7 +798,7 @@ msgid "vCPUs" msgstr "vCPU" #: admin/forms.py:222 computes/templates/computes/balance.html:62 -#: computes/templates/computes/bulk_migrate.html:67 +#: computes/templates/computes/bulk_migrate.html:73 #: computes/templates/computes/instances.html:57 #: computes/templates/computes/list.html:63 #: computes/templates/overview.html:110 computes/templates/overview.html:194 @@ -2306,7 +2306,7 @@ msgstr[0] "Önerilen taşımalar (%(counter)s)" msgstr[1] "Önerilen taşımalar (%(counter)s)" #: computes/templates/computes/balance.html:60 -#: computes/templates/computes/bulk_migrate.html:64 +#: computes/templates/computes/bulk_migrate.html:70 msgid "Select all" msgstr "Tümünü seç" @@ -2315,7 +2315,7 @@ msgid "Migration" msgstr "Taşıma" #: computes/templates/computes/balance.html:85 -#: computes/templates/computes/bulk_migrate.html:99 +#: computes/templates/computes/bulk_migrate.html:105 msgid "Migrations at once" msgstr "Aynı anda taşıma" @@ -2353,7 +2353,7 @@ msgid "Let it move" msgstr "Taşınabilsin" #: computes/templates/computes/balance.html:110 -#: computes/templates/computes/bulk_migrate.html:70 +#: computes/templates/computes/bulk_migrate.html:76 msgid "Why" msgstr "Neden" @@ -2403,7 +2403,7 @@ msgid "The host has no VMs." msgstr "Bu sunucuda sanal makine yok." #: computes/templates/computes/bulk_migrate.html:48 -#: computes/templates/computes/bulk_migrate.html:69 +#: computes/templates/computes/bulk_migrate.html:75 msgid "Destination" msgstr "Hedef" @@ -2411,41 +2411,46 @@ msgstr "Hedef" msgid "Spread over the other hosts" msgstr "Diğer sunuculara dağıt" +#: computes/templates/computes/bulk_migrate.html:56 #: computes/templates/computes/bulk_migrate.html:57 +msgid "Choose by tag" +msgstr "Etikete göre seç" + +#: computes/templates/computes/bulk_migrate.html:63 msgid "Also migrate the shut-off VMs" msgstr "Kapalı sanal makineleri de taşı" -#: computes/templates/computes/bulk_migrate.html:66 +#: computes/templates/computes/bulk_migrate.html:72 #: computes/templates/computes/instances.html:55 #: instances/templates/allinstances_index_grouped.html:12 #: instances/templates/allinstances_index_nongrouped.html:10 msgid "Status" msgstr "Durum" -#: computes/templates/computes/bulk_migrate.html:104 +#: computes/templates/computes/bulk_migrate.html:110 #, python-format msgid "Put %(source)s in maintenance and migrate the chosen VMs?" msgstr "%(source)s bakıma alınsın ve seçilen sanal makineler taşınsın mı?" -#: computes/templates/computes/bulk_migrate.html:106 +#: computes/templates/computes/bulk_migrate.html:112 #, python-format msgid "Migrate the chosen VMs from %(source)s to the hosts shown?" msgstr "" "Seçilen sanal makineler %(source)s sunucusundan gösterilen sunuculara " "taşınsın mı?" -#: computes/templates/computes/bulk_migrate.html:108 +#: computes/templates/computes/bulk_migrate.html:114 #, python-format msgid "Migrate the chosen VMs from %(source)s to %(dest)s?" msgstr "" "Seçilen sanal makineler %(source)s sunucusundan %(dest)s sunucusuna taşınsın " "mı?" -#: computes/templates/computes/bulk_migrate.html:111 +#: computes/templates/computes/bulk_migrate.html:117 msgid "Migrate and put in maintenance" msgstr "Taşı ve bakıma al" -#: computes/templates/computes/bulk_migrate.html:111 +#: computes/templates/computes/bulk_migrate.html:117 msgid "Migrate the chosen VMs" msgstr "Seçilen sanal makineleri taşı" @@ -3008,16 +3013,16 @@ msgstr "" msgid "The host did not answer within %(seconds)s seconds" msgstr "Sunucu %(seconds)s saniye içinde yanıt vermedi" -#: computes/views.py:359 +#: computes/views.py:360 msgid "No other host has room for it" msgstr "Başka hiçbir sunucuda ona yer yok" -#: computes/views.py:437 +#: computes/views.py:439 #, python-format msgid "The host was saved, but the panel cannot connect to it: %(error)s" msgstr "Sunucu kaydedildi, ancak panel ona bağlanamıyor: %(error)s" -#: computes/views.py:510 +#: computes/views.py:512 #, python-format msgid "" "Its VMs keep running on the host and leave the panel; their owners are kept " diff --git a/locale/zh/LC_MESSAGES/django.mo b/locale/zh/LC_MESSAGES/django.mo index e228e7e5..b6a50681 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 f84aca22..db7bb187 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-18 17:53+0000\n" +"POT-Creation-Date: 2026-11-18 18:18+0000\n" "PO-Revision-Date: \n" "Last-Translator: \n" "Language-Team: \n" @@ -63,7 +63,7 @@ msgstr "无效的密钥" #: accounts/forms.py:95 computes/templates/computes/balance.html:61 #: computes/templates/computes/balance.html:108 -#: computes/templates/computes/bulk_migrate.html:65 +#: computes/templates/computes/bulk_migrate.html:71 #: computes/templates/computes/instances.html:53 #: instances/templates/add_instance_volume.html:39 #: instances/templates/allinstances_index_grouped.html:11 @@ -772,7 +772,7 @@ msgid "vCPUs" msgstr "vCPU" #: admin/forms.py:222 computes/templates/computes/balance.html:62 -#: computes/templates/computes/bulk_migrate.html:67 +#: computes/templates/computes/bulk_migrate.html:73 #: computes/templates/computes/instances.html:57 #: computes/templates/computes/list.html:63 #: computes/templates/overview.html:110 computes/templates/overview.html:194 @@ -2208,7 +2208,7 @@ msgid_plural "Proposed migrations (%(counter)s)" msgstr[0] "建议的迁移(%(counter)s)" #: computes/templates/computes/balance.html:60 -#: computes/templates/computes/bulk_migrate.html:64 +#: computes/templates/computes/bulk_migrate.html:70 msgid "Select all" msgstr "全选" @@ -2217,7 +2217,7 @@ msgid "Migration" msgstr "迁移" #: computes/templates/computes/balance.html:85 -#: computes/templates/computes/bulk_migrate.html:99 +#: computes/templates/computes/bulk_migrate.html:105 msgid "Migrations at once" msgstr "同时迁移数" @@ -2252,7 +2252,7 @@ msgid "Let it move" msgstr "允许迁移" #: computes/templates/computes/balance.html:110 -#: computes/templates/computes/bulk_migrate.html:70 +#: computes/templates/computes/bulk_migrate.html:76 msgid "Why" msgstr "原因" @@ -2299,7 +2299,7 @@ msgid "The host has no VMs." msgstr "此主机没有虚拟机。" #: computes/templates/computes/bulk_migrate.html:48 -#: computes/templates/computes/bulk_migrate.html:69 +#: computes/templates/computes/bulk_migrate.html:75 msgid "Destination" msgstr "目标主机" @@ -2307,37 +2307,42 @@ msgstr "目标主机" msgid "Spread over the other hosts" msgstr "分散到其他主机" +#: computes/templates/computes/bulk_migrate.html:56 #: computes/templates/computes/bulk_migrate.html:57 +msgid "Choose by tag" +msgstr "按标签选择" + +#: computes/templates/computes/bulk_migrate.html:63 msgid "Also migrate the shut-off VMs" msgstr "同时迁移已关机的虚拟机" -#: computes/templates/computes/bulk_migrate.html:66 +#: computes/templates/computes/bulk_migrate.html:72 #: computes/templates/computes/instances.html:55 #: instances/templates/allinstances_index_grouped.html:12 #: instances/templates/allinstances_index_nongrouped.html:10 msgid "Status" msgstr "状态" -#: computes/templates/computes/bulk_migrate.html:104 +#: computes/templates/computes/bulk_migrate.html:110 #, python-format msgid "Put %(source)s in maintenance and migrate the chosen VMs?" msgstr "将 %(source)s 置于维护状态并迁移所选虚拟机?" -#: computes/templates/computes/bulk_migrate.html:106 +#: computes/templates/computes/bulk_migrate.html:112 #, python-format msgid "Migrate the chosen VMs from %(source)s to the hosts shown?" msgstr "将所选虚拟机从 %(source)s 迁移到所示主机?" -#: computes/templates/computes/bulk_migrate.html:108 +#: computes/templates/computes/bulk_migrate.html:114 #, python-format msgid "Migrate the chosen VMs from %(source)s to %(dest)s?" msgstr "将选中的虚拟机从 %(source)s 迁移到 %(dest)s?" -#: computes/templates/computes/bulk_migrate.html:111 +#: computes/templates/computes/bulk_migrate.html:117 msgid "Migrate and put in maintenance" msgstr "迁移并进入维护" -#: computes/templates/computes/bulk_migrate.html:111 +#: computes/templates/computes/bulk_migrate.html:117 msgid "Migrate the chosen VMs" msgstr "迁移所选虚拟机" @@ -2867,16 +2872,16 @@ msgstr "请输入主机 /etc/default/webvirt-gstfsd 中 GSTFSD_KEY 的 64 个十 msgid "The host did not answer within %(seconds)s seconds" msgstr "主机未在 %(seconds)s 秒内响应" -#: computes/views.py:359 +#: computes/views.py:360 msgid "No other host has room for it" msgstr "没有其他主机能容纳它" -#: computes/views.py:437 +#: computes/views.py:439 #, python-format msgid "The host was saved, but the panel cannot connect to it: %(error)s" msgstr "主机已保存,但面板无法连接到它:%(error)s" -#: computes/views.py:510 +#: computes/views.py:512 #, python-format msgid "" "Its VMs keep running on the host and leave the panel; their owners are kept " diff --git a/static/js/bulk_migrate.js b/static/js/bulk_migrate.js index bd88f0db..d376362a 100644 --- a/static/js/bulk_migrate.js +++ b/static/js/bulk_migrate.js @@ -1,6 +1,7 @@ // The Bulk Migrate page: another destination reloads the list; the header // box ticks or unticks every VM that can migrate, "Also migrate the -// shut-off VMs" the shut-off ones. Spread over the hosts, a change reloads +// shut-off VMs" the shut-off ones, a tag chosen those with it (data-tags) +// and no others. Spread over the hosts, a change reloads // the list too: where each VM goes depends on the others. The Migrate // button counts the ticked VMs and is off while none is. const choose = document.getElementById("bulk-migrate-choose"); @@ -32,6 +33,14 @@ document.getElementById("bulk-migrate-all")?.addEventListener("change", function document.getElementById("bulk-migrate-shut-off")?.addEventListener("change", function (event) { tick(".bulk-migrate-vm[data-shut-off]:not(:disabled)", event.target.checked); }); +document.getElementById("bulk-migrate-tag")?.addEventListener("change", function (event) { + const tag = event.target.value; + if (tag) { + document.querySelectorAll(".bulk-migrate-vm:not(:disabled)").forEach(function (box) { + box.checked = (box.dataset.tags || "").split(" ").includes(tag); + }); + } +}); document.addEventListener("change", function (event) { if (spreading && event.target.id !== "bulk-migrate-parallel" && event.target.id !== "bulk-migrate-target") { choose.submit();