public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager v4 3/3] ui: add bulk actions to the datacenter level
Date: Fri, 14 Nov 2025 15:59:20 +0100	[thread overview]
Message-ID: <20251114145927.3766668-6-d.csapak@proxmox.com> (raw)
In-Reply-To: <20251114145927.3766668-1-d.csapak@proxmox.com>

reuse the BulkAction window as much as possible. There are only a few
adaptions needed:
* the api call endpoinst are slightly different:
  (e.g. start vs startall)
* we have to handle a missing nodename
* some parameters are different:
  - start does not have a 'force'
  - migrate needs the 'online' parameter
  - the 'vms' list is expected to be an array for the new api calls

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 www/manager6/dc/Config.js         | 68 +++++++++++++++++++++++++++++++
 www/manager6/window/BulkAction.js | 50 +++++++++++++++++++----
 2 files changed, 109 insertions(+), 9 deletions(-)

diff --git a/www/manager6/dc/Config.js b/www/manager6/dc/Config.js
index 60fea4b6..b5e27a21 100644
--- a/www/manager6/dc/Config.js
+++ b/www/manager6/dc/Config.js
@@ -15,9 +15,77 @@ Ext.define('PVE.dc.Config', {
 
         me.items = [];
 
+        let actionBtn = Ext.create('Ext.Button', {
+            text: gettext('Bulk Actions'),
+            iconCls: 'fa fa-fw fa-ellipsis-v',
+            disabled: !caps.vms['VM.PowerMgmt'] && !caps.vms['VM.Migrate'],
+            menu: new Ext.menu.Menu({
+                items: [
+                    {
+                        text: gettext('Bulk Start'),
+                        iconCls: 'fa fa-fw fa-play',
+                        disabled: !caps.vms['VM.PowerMgmt'],
+                        handler: function () {
+                            Ext.create('PVE.window.BulkAction', {
+                                autoShow: true,
+                                vmsAsArray: true,
+                                title: gettext('Bulk Start'),
+                                btnText: gettext('Start'),
+                                action: 'start',
+                            });
+                        },
+                    },
+                    {
+                        text: gettext('Bulk Shutdown'),
+                        iconCls: 'fa fa-fw fa-stop',
+                        disabled: !caps.vms['VM.PowerMgmt'],
+                        handler: function () {
+                            Ext.create('PVE.window.BulkAction', {
+                                autoShow: true,
+                                vmsAsArray: true,
+                                title: gettext('Bulk Shutdown'),
+                                btnText: gettext('Shutdown'),
+                                action: 'shutdown',
+                            });
+                        },
+                    },
+                    {
+                        text: gettext('Bulk Suspend'),
+                        iconCls: 'fa fa-fw fa-download',
+                        disabled: !caps.vms['VM.PowerMgmt'],
+                        handler: function () {
+                            Ext.create('PVE.window.BulkAction', {
+                                autoShow: true,
+                                vmsAsArray: true,
+                                title: gettext('Bulk Suspend'),
+                                btnText: gettext('Suspend'),
+                                action: 'suspend',
+                            });
+                        },
+                    },
+                    {
+                        text: gettext('Bulk Migrate'),
+                        iconCls: 'fa fa-fw fa-send-o',
+                        disabled: !caps.vms['VM.Migrate'],
+                        hidden: PVE.Utils.isStandaloneNode(),
+                        handler: function () {
+                            Ext.create('PVE.window.BulkAction', {
+                                autoShow: true,
+                                vmsAsArray: true,
+                                title: gettext('Bulk Migrate'),
+                                btnText: gettext('Migrate'),
+                                action: 'migrate',
+                            });
+                        },
+                    },
+                ],
+            }),
+        });
+
         Ext.apply(me, {
             title: gettext('Datacenter'),
             hstateid: 'dctab',
+            tbar: [actionBtn],
         });
 
         if (caps.dc['Sys.Audit']) {
diff --git a/www/manager6/window/BulkAction.js b/www/manager6/window/BulkAction.js
index 0223740f..b2d82bd3 100644
--- a/www/manager6/window/BulkAction.js
+++ b/www/manager6/window/BulkAction.js
@@ -13,12 +13,27 @@ Ext.define('PVE.window.BulkAction', {
     // the action to set, currently there are: `startall`, `migrateall`, `stopall`, `suspendall`
     action: undefined,
 
+    // if set to true, the 'vms' parameter will be sent as an array'
+    // necessary for the cluster-wide api call
+    vmsAsArray: false,
+
     submit: function (params) {
         let me = this;
 
+        let url;
+        if (me.nodename) {
+            url = `/nodes/${me.nodename}/${me.action}`;
+        } else {
+            url = `/cluster/bulk-action/guest/${me.action}`;
+        }
+
+        if (me.vmsAsArray) {
+            params.vms = params.vms.split(/[,; ]/);
+        }
+
         Proxmox.Utils.API2Request({
             params: params,
-            url: `/nodes/${me.nodename}/${me.action}`,
+            url,
             waitMsgTarget: me,
             method: 'POST',
             failure: (response) => Ext.Msg.alert('Error', response.htmlStatus),
@@ -38,9 +53,6 @@ Ext.define('PVE.window.BulkAction', {
     initComponent: function () {
         let me = this;
 
-        if (!me.nodename) {
-            throw 'no node name specified';
-        }
         if (!me.action) {
             throw 'no action specified';
         }
@@ -52,7 +64,11 @@ Ext.define('PVE.window.BulkAction', {
         }
 
         let items = [];
-        if (me.action === 'migrateall') {
+        if (me.action === 'migrateall' || me.action === 'migrate') {
+            let disallowedNodes = [];
+            if (me.nodename) {
+                disallowedNodes.push(me.nodename);
+            }
             items.push(
                 {
                     xtype: 'fieldcontainer',
@@ -62,7 +78,7 @@ Ext.define('PVE.window.BulkAction', {
                             flex: 1,
                             xtype: 'pveNodeSelector',
                             name: 'target',
-                            disallowedNodes: [me.nodename],
+                            disallowedNodes,
                             fieldLabel: gettext('Target node'),
                             labelWidth: 200,
                             allowBlank: false,
@@ -106,13 +122,20 @@ Ext.define('PVE.window.BulkAction', {
                     ],
                 },
             );
+            if (me.action === 'migrate') {
+                items.push({
+                    xtype: 'hiddenfield',
+                    name: 'online',
+                    value: 1,
+                });
+            }
         } else if (me.action === 'startall') {
             items.push({
                 xtype: 'hiddenfield',
                 name: 'force',
                 value: 1,
             });
-        } else if (me.action === 'stopall') {
+        } else if (me.action === 'stopall' || me.action === 'shutdown') {
             items.push({
                 xtype: 'fieldcontainer',
                 layout: 'hbox',
@@ -152,8 +175,17 @@ Ext.define('PVE.window.BulkAction', {
             me.down('#lxcwarning').setVisible(showWarning);
         };
 
-        let defaultStatus =
-            me.action === 'migrateall' ? '' : me.action === 'startall' ? 'stopped' : 'running';
+        let defaulStatusMap = {
+            migrateall: '',
+            migrate: '',
+            startall: 'stopped',
+            start: 'stopped',
+            stopall: 'running',
+            shutdown: 'running',
+            suspendall: 'running',
+            suspend: 'running',
+        };
+        let defaultStatus = defaulStatusMap[me.action] ?? '';
         let defaultType = me.action === 'suspendall' ? 'qemu' : '';
 
         let statusMap = [];
-- 
2.47.3



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  parent reply	other threads:[~2025-11-14 14:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-14 14:59 [pve-devel] [PATCH apiclient/common/manager v4 0/5] implement cluster-wide bulk-actions for guests Dominik Csapak
2025-11-14 14:59 ` [pve-devel] [PATCH pve-apiclient v4 1/1] try to refresh ticket before an api call Dominik Csapak
2025-11-14 14:59 ` [pve-devel] [PATCH common v4 1/1] json schema/rest environment: add 'expose_credentials' option Dominik Csapak
2025-11-14 14:59 ` [pve-devel] [PATCH manager v4 1/3] http server/pvesh: set credentials if necessary Dominik Csapak
2025-11-14 21:02   ` [pve-devel] applied: " Thomas Lamprecht
2025-11-14 14:59 ` [pve-devel] [PATCH manager v4 2/3] api: implement node-independent bulk actions Dominik Csapak
2025-11-14 21:02   ` [pve-devel] applied: " Thomas Lamprecht
2025-11-14 14:59 ` Dominik Csapak [this message]
2025-11-14 21:02   ` [pve-devel] applied: [PATCH manager v4 3/3] ui: add bulk actions to the datacenter level 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=20251114145927.3766668-6-d.csapak@proxmox.com \
    --to=d.csapak@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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal