all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
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	[thread overview]
Message-ID: <20261118110705.595989-15-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20261118110705.595989-1-t.lamprecht@proxmox.com>

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 <t.lamprecht@proxmox.com>
---
 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





  parent reply	other threads:[~2026-11-18 11:08 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-18 11:05 [PATCH guest-common,ha-manager,manager,docs 0/15] cluster resource scheduling for all guests Thomas Lamprecht
2026-11-18 11:05 ` [PATCH guest-common 01/15] scheduling: add cluster resource scheduling library Thomas Lamprecht
2026-11-18 11:05 ` [PATCH ha-manager 02/15] helpers: block both locations of a migrating negative affinity partner Thomas Lamprecht
2026-11-18 11:05 ` [PATCH ha-manager 03/15] usage: static: count services per node again for scoring fallback Thomas Lamprecht
2026-11-18 11:05 ` [PATCH ha-manager 04/15] config: allow getting motion info of many resources at once Thomas Lamprecht
2026-11-18 11:05 ` [PATCH ha-manager 05/15] env: pve2: delegate cluster stat gathering to scheduling library Thomas Lamprecht
2026-11-18 11:05 ` [PATCH ha-manager 06/15] usage: share one scheduler base between static and dynamic Thomas Lamprecht
2026-11-18 11:05 ` [PATCH manager 07/15] ui: bulk action: translate error title and CT restart warning Thomas Lamprecht
2026-11-18 11:05 ` [PATCH manager 08/15] ui: bulk migrate: show CT restart warning for cluster-wide migration Thomas Lamprecht
2026-11-18 11:05 ` [PATCH manager 09/15] ui: migrate: recheck preconditions if the target changed meanwhile Thomas Lamprecht
2026-11-18 11:05 ` [PATCH manager 10/15] api: cluster: add resource scheduling endpoints Thomas Lamprecht
2026-11-18 11:05 ` [PATCH manager 11/15] ui: migrate: sort target nodes by scheduler recommendation Thomas Lamprecht
2026-11-18 11:05 ` [PATCH manager 12/15] api: bulk migrate: allow a per-guest target node mapping Thomas Lamprecht
2026-11-18 11:05 ` [PATCH manager 13/15] ui: bulk migrate: support per-guest target nodes Thomas Lamprecht
2026-11-18 11:05 ` Thomas Lamprecht [this message]
2026-11-18 11:05 ` [PATCH docs 15/15] pvecm: document balancing the cluster load with migrations Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261118110705.595989-15-t.lamprecht@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal