From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager] ui: allow specifying shutdown policy during node shutdown/reboot
Date: Mon, 19 Jun 2023 17:12:25 +0200 [thread overview]
Message-ID: <20230619151225.92725-1-f.ebner@proxmox.com> (raw)
Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
Depends on https://lists.proxmox.com/pipermail/pve-devel/2023-June/057635.html
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.
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..51d9e85d 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
reply other threads:[~2023-06-19 15:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230619151225.92725-1-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.