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 4A4711FF0C0 for ; Wed, 18 Nov 2026 12:08:42 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 8269B2194E; Wed, 18 Nov 2026 12:07:40 +0100 (CET) From: Thomas Lamprecht To: pve-devel@lists.proxmox.com Subject: [PATCH manager 14/15] ui: dc: add a Rebalance Guests bulk action Date: Wed, 18 Nov 2026 12:05:21 +0100 Message-ID: <20261118110705.595989-15-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: 1795000031077 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.125 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) PROLO_LEO1 0.1 Meta Catches all Leo drug variations so far 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: JZVDAG4NAU3YNRZ6HIUAJHKTMUO5RYNS X-Message-ID-Hash: JZVDAG4NAU3YNRZ6HIUAJHKTMUO5RYNS 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 Rebalance Guests entry to the Datacenter bulk actions. It opens the bulk migrate dialog with the guests and target nodes of a rebalance proposal for all guests the user may migrate, so the proposed migrations can be reviewed and adjusted before starting them. The tag and pool menus do not offer it, as it considers all guests. In this mode, the dialog starts without a default target node, so a guest added to the selection needs its own target instead of being migrated to a node that nobody picked. Signed-off-by: Thomas Lamprecht --- www/manager6/dc/CmdMenu.js | 21 +++++++++++ www/manager6/dc/Config.js | 16 +++++++++ www/manager6/form/VMSelectorWithTarget.js | 43 +++++++++++++++++++---- www/manager6/window/BulkAction.js | 20 ++++++++++- 4 files changed, 92 insertions(+), 8 deletions(-) diff --git a/www/manager6/dc/CmdMenu.js b/www/manager6/dc/CmdMenu.js index a8df24104..1ca035262 100644 --- a/www/manager6/dc/CmdMenu.js +++ b/www/manager6/dc/CmdMenu.js @@ -71,6 +71,21 @@ Ext.define('PVE.dc.CmdMenu', { }); }, }, + { + text: gettext('Rebalance Guests'), + itemId: 'rebalance', + iconCls: 'fa fa-fw fa-balance-scale', + handler: function () { + Ext.create('PVE.window.BulkAction', { + autoShow: true, + vmsAsArray: true, + title: gettext('Rebalance Guests'), + btnText: gettext('Migrate'), + action: 'migrate', + rebalance: true, + }); + }, + }, ], initComponent: function () { @@ -90,6 +105,7 @@ Ext.define('PVE.dc.CmdMenu', { if (!caps.vms['VM.Migrate']) { me.getComponent('bulkmigrate').setDisabled(true); + me.getComponent('rebalance').setDisabled(true); } if (!caps.vms['VM.PowerMgmt']) { me.getComponent('bulkstart').setDisabled(true); @@ -98,6 +114,11 @@ Ext.define('PVE.dc.CmdMenu', { } if (PVE.Utils.isStandaloneNode()) { me.getComponent('bulkmigrate').setVisible(false); + me.getComponent('rebalance').setVisible(false); + } + // a rebalance considers all guests, not only those a tag or pool menu preselects + if (Object.keys(me.extraHandlerArgs).length) { + me.getComponent('rebalance').setVisible(false); } }, }); diff --git a/www/manager6/dc/Config.js b/www/manager6/dc/Config.js index 83c48c3d6..655e22207 100644 --- a/www/manager6/dc/Config.js +++ b/www/manager6/dc/Config.js @@ -78,6 +78,22 @@ Ext.define('PVE.dc.Config', { }); }, }, + { + text: gettext('Rebalance Guests'), + iconCls: 'fa fa-fw fa-balance-scale', + disabled: !caps.vms['VM.Migrate'], + hidden: PVE.Utils.isStandaloneNode(), + handler: function () { + Ext.create('PVE.window.BulkAction', { + autoShow: true, + vmsAsArray: true, + title: gettext('Rebalance Guests'), + btnText: gettext('Migrate'), + action: 'migrate', + rebalance: true, + }); + }, + }, ], }), }); diff --git a/www/manager6/form/VMSelectorWithTarget.js b/www/manager6/form/VMSelectorWithTarget.js index ad09221d5..a4cc3a3da 100644 --- a/www/manager6/form/VMSelectorWithTarget.js +++ b/www/manager6/form/VMSelectorWithTarget.js @@ -8,7 +8,8 @@ Ext.define('PVE.form.VMSelectorWithTarget', { // 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. + // Returns the target node used for guests without a per-guest target, if any. Without one, + // every selected guest needs a per-guest target. getDefaultTarget: () => undefined, targetOverrides: null, @@ -33,22 +34,28 @@ Ext.define('PVE.form.VMSelectorWithTarget', { me.validate(); }, - // Only the rows of selected guests show their target, so the column stays quiet for the - // guests that are not migrated. + // Only the rows of selected guests show their target or that it is missing, 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 selected = me.getSelectionModel().isSelected(record); + let defaultTarget = me.getDefaultTarget(); let emptyText = ''; - if (me.getSelectionModel().isSelected(record)) { - let defaultTarget = me.getDefaultTarget(); + if (selected) { emptyText = defaultTarget ? `${Proxmox.Utils.defaultText} (${defaultTarget})` - : Proxmox.Utils.defaultText; + : gettext('Select node'); } combo.setEmptyText(emptyText); + if (selected && !override && !defaultTarget) { + combo.markInvalid(gettext('Select a target node for this guest')); + } else { + combo.clearInvalid(); + } }, updateTargetWidgets: function () { @@ -73,10 +80,29 @@ Ext.define('PVE.form.VMSelectorWithTarget', { .join(','); }, - // rows without a per-guest target show the default target + // The default target decides whether a guest without a per-guest target is valid and what + // its row shows. onDefaultTargetChange: function () { let me = this; me.updateTargetWidgets(); + me.validate(); + }, + + getErrors: function (value) { + let me = this; + let errors = me.callParent([value]); + if (errors.length || me.isDisabled() || me.getDefaultTarget()) { + return errors; + } + + let missing = me.getValue().filter((vmid) => !me.targetOverrides[vmid]); + if (missing.length) { + me.addBodyCls(['x-form-trigger-wrap-default', 'x-form-trigger-wrap-invalid']); + return [ + Ext.String.format(gettext('No target node for guests: {0}'), missing.join(', ')), + ]; + } + return errors; }, initComponent: function () { @@ -113,6 +139,9 @@ Ext.define('PVE.form.VMSelectorWithTarget', { displayField: 'node', editable: false, queryMode: 'local', + // the row's validity depends on the selection, see updateTargetWidget + validateOnChange: false, + validateOnBlur: false, triggers: { clear: { cls: 'pmx-clear-trigger', diff --git a/www/manager6/window/BulkAction.js b/www/manager6/window/BulkAction.js index c81784948..44b33179a 100644 --- a/www/manager6/window/BulkAction.js +++ b/www/manager6/window/BulkAction.js @@ -17,6 +17,10 @@ Ext.define('PVE.window.BulkAction', { // necessary for the cluster-wide api call vmsAsArray: false, + // For the cluster-wide 'migrate' action: start with the guests and per-guest targets of a + // rebalance proposal instead of all guests and a single target node. + rebalance: false, + submit: function (params) { let me = this; @@ -36,6 +40,10 @@ Ext.define('PVE.window.BulkAction', { if (targetMap) { params['target-map'] = targetMap; } + // in rebalance mode the default target is optional + if (!params.target) { + delete params.target; + } } Proxmox.Utils.API2Request({ @@ -94,7 +102,12 @@ Ext.define('PVE.window.BulkAction', { disallowedNodes, fieldLabel: gettext('Target node'), labelWidth: 200, - allowBlank: false, + // in rebalance mode every proposed guest has its own target, and an + // automatically picked default would silently apply to any guest the + // user adds to the selection + allowBlank: me.rebalance, + autoSelect: !me.rebalance, + emptyText: me.rebalance ? gettext('Per-guest targets only') : undefined, listeners: { change: () => me.down('#vms')?.onDefaultTargetChange?.(), }, @@ -557,6 +570,7 @@ Ext.define('PVE.window.BulkAction', { if (me.action === 'migrate') { Ext.apply(selector, { xtype: 'pveVMSelectorWithTarget', + selectAll: !me.rebalance, getDefaultTarget: () => me.down('#defaultTarget')?.getValue(), }); Ext.apply(selector.listeners, { @@ -707,5 +721,9 @@ Ext.define('PVE.window.BulkAction', { form.isValid(); filterChange(); + + if (me.rebalance) { + me.on('show', suggestTargets, me, { single: true }); + } }, }); -- 2.47.3