From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 2CE93A2BE8 for ; Tue, 20 Jun 2023 12:55:43 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 780AE33A0B for ; Tue, 20 Jun 2023 12:54:44 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Tue, 20 Jun 2023 12:54:43 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 2C6D441C64 for ; Tue, 20 Jun 2023 12:54:43 +0200 (CEST) From: Fiona Ebner To: pve-devel@lists.proxmox.com Date: Tue, 20 Jun 2023 12:54:38 +0200 Message-Id: <20230620105438.121605-10-f.ebner@proxmox.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230620105438.121605-1-f.ebner@proxmox.com> References: <20230620105438.121605-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.046 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH v2 manager 2/2] ui: allow specifying shutdown policy during node shutdown/reboot X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 20 Jun 2023 10:55:43 -0000 Signed-off-by: Fiona Ebner --- New in v2, was sent separately before (no changes to that). Used a new window, because it's small and couldn't find a good fit with the existing ones. Maybe SafeDestroy, but not in name and would require a few modifications too. Not sure about using gettext() for the option names either. www/manager6/Makefile | 1 + www/manager6/node/Config.js | 32 +++---- www/manager6/window/NodeShutdown.js | 126 ++++++++++++++++++++++++++++ 3 files changed, 139 insertions(+), 20 deletions(-) create mode 100644 www/manager6/window/NodeShutdown.js diff --git a/www/manager6/Makefile b/www/manager6/Makefile index 9b6dd13b..94c8c05e 100644 --- a/www/manager6/Makefile +++ b/www/manager6/Makefile @@ -107,6 +107,7 @@ JSSRC= \ window/FirewallLograteEdit.js \ window/LoginWindow.js \ window/Migrate.js \ + window/NodeShutdown.js \ window/Prune.js \ window/Restore.js \ window/SafeDestroyGuest.js \ diff --git a/www/manager6/node/Config.js b/www/manager6/node/Config.js index 6ed2172a..7a074879 100644 --- a/www/manager6/node/Config.js +++ b/www/manager6/node/Config.js @@ -19,18 +19,6 @@ Ext.define('PVE.node.Config', { interval: 5000, }); - var node_command = function(cmd) { - Proxmox.Utils.API2Request({ - params: { command: cmd }, - url: '/nodes/' + nodename + '/status', - method: 'POST', - waitMsgTarget: me, - failure: function(response, opts) { - Ext.Msg.alert(gettext('Error'), response.htmlStatus); - }, - }); - }; - var actionBtn = Ext.create('Ext.Button', { text: gettext('Bulk Actions'), iconCls: 'fa fa-fw fa-ellipsis-v', @@ -83,24 +71,28 @@ Ext.define('PVE.node.Config', { }), }); - let restartBtn = Ext.create('Proxmox.button.Button', { + let restartBtn = Ext.create('Ext.button.Button', { text: gettext('Reboot'), disabled: !caps.nodes['Sys.PowerMgmt'], - dangerous: true, - confirmMsg: Ext.String.format(gettext("Reboot node '{0}'?"), nodename), handler: function() { - node_command('reboot'); + Ext.create('PVE.window.NodeShutdown', { + confirmMsg: Ext.String.format(gettext("Reboot node '{0}'?"), nodename), + url: '/nodes/' + nodename + '/status', + command: 'reboot', + }).show(); }, iconCls: 'fa fa-undo', }); - var shutdownBtn = Ext.create('Proxmox.button.Button', { + let shutdownBtn = Ext.create('Ext.button.Button', { text: gettext('Shutdown'), disabled: !caps.nodes['Sys.PowerMgmt'], - dangerous: true, - confirmMsg: Ext.String.format(gettext("Shutdown node '{0}'?"), nodename), handler: function() { - node_command('shutdown'); + Ext.create('PVE.window.NodeShutdown', { + confirmMsg: Ext.String.format(gettext("Shutdown node '{0}'?"), nodename), + url: '/nodes/' + nodename + '/status', + command: 'shutdown', + }).show(); }, iconCls: 'fa fa-power-off', }); diff --git a/www/manager6/window/NodeShutdown.js b/www/manager6/window/NodeShutdown.js new file mode 100644 index 00000000..4cdc541c --- /dev/null +++ b/www/manager6/window/NodeShutdown.js @@ -0,0 +1,126 @@ +Ext.define('PVE.window.NodeShutdown', { + extend: 'Ext.window.Window', + alias: 'widget.pveNodeShutdown', + mixins: ['Proxmox.Mixin.CBind'], + + title: gettext('Confirm'), + modal: true, + buttonAlign: 'center', + bodyPadding: 10, + width: 450, + layout: { type: 'hbox' }, + defaultFocus: 'nodeShutdownNoButton', + + config: { + url: undefined, + confirmMsg: undefined, + command: undefined, + }, + + getParams: function() { + let me = this; + let params = { command: me.getCommand(), }; + + let shutdownPolicy = me.lookup('shutdownPolicy').getValue(); + if (shutdownPolicy && shutdownPolicy !== '__default__') { + params['shutdown-policy'] = shutdownPolicy; + } + + return params; + }, + + controller: { + xclass: 'Ext.app.ViewController', + + control: { + 'button[reference=yesButton]': { + click: function() { + const view = this.getView(); + Proxmox.Utils.API2Request({ + params: view.getParams(), + url: view.getUrl(), + method: 'POST', + waitMsgTarget: view, + failure: function(response, opts) { + Ext.Msg.alert(gettext('Error'), response.htmlStatus); + }, + success: function(response, options) { + view.close(); + }, + }); + }, + }, + 'button[reference=noButton]': { + click: function() { + this.getView().close(); + }, + }, + }, + }, + + buttons: [ + { + xtype: 'proxmoxHelpButton', + listeners: { + beforerender: () => { + Ext.GlobalEvents.fireEvent('proxmoxShowHelp', 'ha_manager_shutdown_policy'); + }, + }, + }, + '->', + { + reference: 'yesButton', + text: gettext('Yes'), + }, + { + id: 'nodeShutdownNoButton', + reference: 'noButton', + text: gettext('No'), + }, + ], + + items: [ + { + xtype: 'component', + cls: [ + Ext.baseCSSPrefix + 'message-box-icon', + Ext.baseCSSPrefix + 'message-box-warning', + Ext.baseCSSPrefix + 'dlg-icon', + ], + }, + { + xtype: 'container', + flex: 1, + layout: { + type: 'vbox', + align: 'stretch', + }, + items: [ + { + xtype: 'displayfield', + reference: 'messageCmp', + cbind: { + value: '{confirmMsg}', + }, + }, + { + reference: 'shutdownPolicy', + fieldLabel: gettext('HA Shutdown Policy'), + labelWidth: 130, + xtype: 'proxmoxKVComboBox', + comboItems: [ + [ + '__default__', + Ext.String.format(gettext("Fallback from {0}"), "datacenter.cfg") + ], + ['migrate', gettext("Migrate")], + ['conditional', gettext("Conditional")], + ['freeze', gettext("Freeze")], + ['failover', gettext("Failover")], + ], + value: '__default__', + }, + ], + }, + ], +}); -- 2.39.2