From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id BB6C41FF0C0 for ; Wed, 18 Nov 2026 12:09:00 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 53F942196D; Wed, 18 Nov 2026 12:07:48 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH manager 13/15] ui: bulk migrate: support per-guest target nodes Date: Wed, 18 Nov 2026 12:05:20 +0100 Message-ID: <20261118110705.595989-14-t.lamprecht@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261118110705.595989-1-t.lamprecht@proxmox.com> References: <20261118110705.595989-1-t.lamprecht@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1795000031016 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.175 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: SURXE5G7HIP72SERRDMNHAGEQ33JF2ZN X-Message-ID-Hash: SURXE5G7HIP72SERRDMNHAGEQ33JF2ZN X-MailFrom: t.lamprecht@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Add a Target column to the guest list of the Datacenter bulk migrate dialog, to migrate guests to different nodes in one go, and a Suggest Migrations button that fills it from a rebalance proposal for the selected guests, or all listed guests if none are selected. Only the guests that the proposal moves stay selected, as the others would otherwise be migrated to the default target node. They are listed first, so that a proposal stays together in a long guest list. Signed-off-by: Thomas Lamprecht --- www/manager6/Makefile | 1 + www/manager6/form/VMSelectorWithTarget.js | 173 ++++++++++++++++++++++ www/manager6/window/BulkAction.js | 143 +++++++++++++++++- 3 files changed, 314 insertions(+), 3 deletions(-) create mode 100644 www/manager6/form/VMSelectorWithTarget.js diff --git a/www/manager6/Makefile b/www/manager6/Makefile index e8e2bd0b4..299a809e1 100644 --- a/www/manager6/Makefile +++ b/www/manager6/Makefile @@ -87,6 +87,7 @@ JSSRC= \ form/VLanField.js \ form/VMCPUFlagSelector.js \ form/VMSelector.js \ + form/VMSelectorWithTarget.js \ form/VNCKeyboardSelector.js \ form/ViewSelector.js \ form/iScsiProviderSelector.js \ diff --git a/www/manager6/form/VMSelectorWithTarget.js b/www/manager6/form/VMSelectorWithTarget.js new file mode 100644 index 000000000..ad09221d5 --- /dev/null +++ b/www/manager6/form/VMSelectorWithTarget.js @@ -0,0 +1,173 @@ +// A VMSelector with an extra, editable per-guest target node column, for bulk migrations that send +// different guests to different nodes. The per-guest targets are held in a vmid-keyed map, not on +// the records, so they survive store filtering and refreshes. +Ext.define('PVE.form.VMSelectorWithTarget', { + extend: 'PVE.form.VMSelector', + alias: 'widget.pveVMSelectorWithTarget', + + // the extra Target column would otherwise push the grid past the dialog width + forceFit: true, + + // Returns the target node used for guests without a per-guest target. + getDefaultTarget: () => undefined, + + targetOverrides: null, + + setTargetOverride: function (vmid, node) { + let me = this; + if (node) { + me.targetOverrides[vmid] = node; + } else { + delete me.targetOverrides[vmid]; + } + me.updateTargetWidgets(); + me.validate(); + me.fireEvent('targetchange', me); + }, + + // Replace all per-guest targets with the given vmid to node map. + setTargetOverrides: function (map) { + let me = this; + me.targetOverrides = { ...map }; + me.updateTargetWidgets(); + me.validate(); + }, + + // Only the rows of selected guests show their target, so the column stays quiet for the + // guests that are not migrated. + updateTargetWidget: function (combo, record) { + let me = this; + let override = me.targetOverrides[record.data.vmid]; + combo.setValue(override ?? null); + combo.getTrigger('clear').setVisible(!!override); + + let emptyText = ''; + if (me.getSelectionModel().isSelected(record)) { + let defaultTarget = me.getDefaultTarget(); + emptyText = defaultTarget + ? `${Proxmox.Utils.defaultText} (${defaultTarget})` + : Proxmox.Utils.defaultText; + } + combo.setEmptyText(emptyText); + }, + + updateTargetWidgets: function () { + let me = this; + Ext.suspendLayouts(); + for (const combo of me.query('combobox')) { + let record = combo.getWidgetRecord?.(); + if (record) { + me.updateTargetWidget(combo, record); + } + } + Ext.resumeLayouts(true); + }, + + // The selected guests' per-guest targets as a list of 'vmid:node' pairs. + getTargetMap: function () { + let me = this; + return me + .getValue() + .filter((vmid) => me.targetOverrides[vmid]) + .map((vmid) => `${vmid}:${me.targetOverrides[vmid]}`) + .join(','); + }, + + // rows without a per-guest target show the default target + onDefaultTargetChange: function () { + let me = this; + me.updateTargetWidgets(); + }, + + initComponent: function () { + let me = this; + + me.targetOverrides = {}; + + // one node store shared by all per-row combos; online-only, like the default target field + me.nodeStore = Ext.create('Ext.data.Store', { + fields: ['node', 'status'], + proxy: { type: 'proxmox', url: '/api2/json/nodes' }, + sorters: 'node', + filters: [{ filterFn: (rec) => rec.data.status === 'online' }], + autoLoad: true, + }); + + let targetColumn = { + header: gettext('Target'), + // No dataIndex: the target is not a model field. Binding one would make the + // widgetcolumn reset the combo to the empty field value on every store update, while + // onWidgetAttach must stay the only source of the combo's value. + width: 160, + sortable: false, + hideable: false, + menuDisabled: true, + tooltip: gettext("Overrides the 'Target node' for this guest"), + xtype: 'widgetcolumn', + // rows are recycled, so restore this row's target on every (re)attach + onWidgetAttach: (column, combo, record) => me.updateTargetWidget(combo, record), + widget: { + xtype: 'combobox', + store: me.nodeStore, + valueField: 'node', + displayField: 'node', + editable: false, + queryMode: 'local', + triggers: { + clear: { + cls: 'pmx-clear-trigger', + hidden: true, + handler: function (combo) { + let record = combo.getWidgetRecord(); + if (record) { + me.setTargetOverride(record.data.vmid, null); + } + }, + }, + }, + listeners: { + // Only an explicit pick updates the map. Row recycling and store updates fire + // 'change' but not 'select', so they cannot overwrite another row's target. + select: function (combo) { + let record = combo.getWidgetRecord(); + if (!record) { + return; + } + me.targetOverrides[record.data.vmid] = combo.getValue(); + // picking a target for a guest expresses the intent to migrate it + me.getSelectionModel().select(record, true); + me.updateTargetWidget(combo, record); + me.validate(); + me.fireEvent('targetchange', me); + }, + }, + }, + }; + + // HA state is a short value, so narrow it. Copy the configs, as the declaration is shared. + me.columnsDeclaration = me.columnsDeclaration.flatMap((column) => { + if (column.dataIndex === 'hastate') { + let narrowed = { ...column, width: 90 }; + delete narrowed.flex; + return [narrowed]; + } + if (column.dataIndex === 'node') { + return [{ ...column, width: 120 }, targetColumn]; + } + return [column]; + }); + + me.callParent(); + + me.on('selectionchange', me.updateTargetWidgets, me); + }, + + doDestroy: function () { + let me = this; + + me.callParent(); + + // the node store is shared across rows and not destroyed by the combos + me.nodeStore = Ext.destroy(me.nodeStore); + }, +}); diff --git a/www/manager6/window/BulkAction.js b/www/manager6/window/BulkAction.js index 3f8ad5674..c81784948 100644 --- a/www/manager6/window/BulkAction.js +++ b/www/manager6/window/BulkAction.js @@ -31,6 +31,13 @@ Ext.define('PVE.window.BulkAction', { params.vms = params.vms.split(/[,; ]/); } + if (me.action === 'migrate') { + let targetMap = me.down('#vms').getTargetMap(); + if (targetMap) { + params['target-map'] = targetMap; + } + } + Proxmox.Utils.API2Request({ params: params, url, @@ -63,6 +70,11 @@ Ext.define('PVE.window.BulkAction', { throw 'no title specified'; } + // the guest grid of the cluster-wide migration has an extra per-guest Target column + if (me.action === 'migrate') { + me.width = 1100; + } + let items = []; if (me.action === 'migrateall' || me.action === 'migrate') { let disallowedNodes = []; @@ -77,11 +89,15 @@ Ext.define('PVE.window.BulkAction', { { flex: 1, xtype: 'pveNodeSelector', + itemId: 'defaultTarget', name: 'target', disallowedNodes, fieldLabel: gettext('Target node'), labelWidth: 200, allowBlank: false, + listeners: { + change: () => me.down('#vms')?.onDefaultTargetChange?.(), + }, onlineValidator: true, padding: '0 10 0 0', }, @@ -506,7 +522,20 @@ Ext.define('PVE.window.BulkAction', { ], }); - items.push({ + // The status describes the last proposal, so show it only while the selected guests and + // their targets match that proposal. + let proposedMigrations = null; + let updateSummary = function () { + let grid = me.down('#vms'); + let current = grid + .getValue() + .map((vmid) => `${vmid}:${grid.targetOverrides[vmid] ?? ''}`) + .sort() + .join(); + me.down('#rebalanceSummary').setVisible(current === proposedMigrations); + }; + + let selector = { xtype: 'vmselector', itemId: 'vms', name: 'vms', @@ -524,7 +553,18 @@ Ext.define('PVE.window.BulkAction', { } }, }, - }); + }; + if (me.action === 'migrate') { + Ext.apply(selector, { + xtype: 'pveVMSelectorWithTarget', + getDefaultTarget: () => me.down('#defaultTarget')?.getValue(), + }); + Ext.apply(selector.listeners, { + change: updateSummary, + targetchange: updateSummary, + }); + } + items.push(selector); me.formPanel = Ext.create('Ext.form.Panel', { bodyPadding: 10, @@ -549,9 +589,106 @@ Ext.define('PVE.window.BulkAction', { }, }); + // Fill the per-guest targets from a rebalance proposal for the selected guests, or for all + // listed guests if none are selected. Only the guests the proposal moves stay selected, as + // the others would otherwise be migrated to the default target node. + let suggestTargets = function () { + let grid = me.down('#vms'); + let store = grid.getStore(); + let guests = grid.getValue(); + if (!guests.length && store.isLoaded()) { + guests = store.getRange().map((record) => record.data.vmid); + if (!guests.length) { + return; // the filters hide all guests + } + } + let params = {}; + // Without a list, the API considers all guests the user may migrate, while a list + // needs that permission on every guest in it. + let total = (store.getData().getSource() ?? store.getData()).getCount(); + if (guests.length && guests.length < total) { + params.vms = guests.join(','); + } + + Proxmox.Utils.API2Request({ + url: '/cluster/resource-scheduling/rebalance-plan', + method: 'POST', + params, + waitMsgTarget: me, + failure: function (response) { + if (!me.destroyed) { + Ext.Msg.alert(gettext('Error'), response.htmlStatus); + } + }, + success: function ({ result }) { + if (me.destroyed) { + return; + } + // apply even an empty proposal, so a previous one does not stay ready to submit + let { moves, imbalance } = result.data; + proposedMigrations = moves + .map((move) => `${move.vmid}:${move.target}`) + .sort() + .join(); + let before = `${(imbalance.before * 100).toFixed(1)}%`; + let after = `${(imbalance.after * 100).toFixed(1)}%`; + me.down('#rebalanceSummary').setHtml( + moves.length + ? Ext.String.format( + gettext( + 'Cluster imbalance: {0} now, {1} expected after migration', + ), + before, + after, + ) + : Ext.String.format( + gettext( + 'Cluster imbalance: {0} now, no migration would noticeably lower it', + ), + before, + ), + ); + grid.setTargetOverrides( + Object.fromEntries(moves.map((move) => [move.vmid, move.target])), + ); + grid.setValue(moves.map((move) => move.vmid)); + // show the proposed guests together, not scattered over a long guest list + let proposed = new Set(moves.map((move) => move.vmid)); + store.sort([ + { + sorterFn: (a, b) => + proposed.has(b.data.vmid) - proposed.has(a.data.vmid), + }, + { property: 'vmid' }, + ]); + grid.getView().setScrollY(0); + updateSummary(); + }, + }); + }; + + let buttons = [submitBtn]; + if (me.action === 'migrate') { + buttons.unshift( + { + text: gettext('Suggest Migrations'), + tooltip: gettext( + 'Propose migrations that balance the cluster load, for the selected guests or, if none are selected, all listed guests. The proposal replaces the selection and the per-guest targets.', + ), + handler: suggestTargets, + }, + { + xtype: 'tbtext', + itemId: 'rebalanceSummary', + hidden: true, + }, + '->', + ); + } + Ext.apply(me, { items: [me.formPanel], - buttons: [submitBtn], + buttons, }); me.callParent(); -- 2.47.3