From: Thomas Lamprecht <t.lamprecht@proxmox.com>
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 [thread overview]
Message-ID: <20261118110705.595989-14-t.lamprecht@proxmox.com> (raw)
In-Reply-To: <20261118110705.595989-1-t.lamprecht@proxmox.com>
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 <t.lamprecht@proxmox.com>
---
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
next prev parent reply other threads:[~2026-11-18 11:09 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 ` Thomas Lamprecht [this message]
2026-11-18 11:05 ` [PATCH manager 14/15] ui: dc: add a Rebalance Guests bulk action Thomas Lamprecht
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-14-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox