all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v2 manager 2/2] ui: allow specifying shutdown policy during node shutdown/reboot
Date: Tue, 20 Jun 2023 12:54:38 +0200	[thread overview]
Message-ID: <20230620105438.121605-10-f.ebner@proxmox.com> (raw)
In-Reply-To: <20230620105438.121605-1-f.ebner@proxmox.com>

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---

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





      parent reply	other threads:[~2023-06-20 10:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-20 10:54 [pve-devel] [PATCH-SERIES v2 (ha-)manager] allow node HA shutdown policy override Fiona Ebner
2023-06-20 10:54 ` [pve-devel] [PATCH v2 ha-manager 1/7] lrm service: add runtime directory Fiona Ebner
2023-06-20 10:54 ` [pve-devel] [RFC v2 ha-manager 2/7] lrm service: move PID file to service's " Fiona Ebner
2023-06-20 10:54 ` [pve-devel] [PATCH v2 ha-manager 3/7] pve2 env: get shutdown policy override set by node's shutdown API endpoint Fiona Ebner
2023-06-20 10:54 ` [pve-devel] [PATCH v2 ha-manager 4/7] lrm: honor " Fiona Ebner
2023-06-20 10:54 ` [pve-devel] [RFC v2 ha-manager 5/7] pve2 env: validate shutdown policy from override file Fiona Ebner
2023-06-20 10:54 ` [pve-devel] [PATCH v2 ha-manager 6/7] sim env: add support for datacenter config overrides Fiona Ebner
2023-06-20 10:54 ` [pve-devel] [PATCH v2 ha-manager 7/7] tests: add test for shutdown policy override Fiona Ebner
2023-06-20 10:54 ` [pve-devel] [PATCH v2 manager 1/2] api: nodes: allow setting HA shutdown policy during shutdown/reboot Fiona Ebner
2023-06-20 10:54 ` Fiona Ebner [this message]

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=20230620105438.121605-10-f.ebner@proxmox.com \
    --to=f.ebner@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