[pve-devel] [PATCH manager] Add button to wake nodes via WoL to the node Config.js

Christian Ebner c.ebner at proxmox.com
Mon Jan 28 15:21:36 CET 2019


This adds a WoL button to the Config.js status bar. In order to be able to
correctly enable/disable the button on node status changes, the monitoring code
had to be slightly modified.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
 www/manager6/node/Config.js | 38 ++++++++++++++++++++++++++++++--------
 1 file changed, 30 insertions(+), 8 deletions(-)

diff --git a/www/manager6/node/Config.js b/www/manager6/node/Config.js
index f9a62670..0d1d4d13 100644
--- a/www/manager6/node/Config.js
+++ b/www/manager6/node/Config.js
@@ -102,6 +102,29 @@ Ext.define('PVE.node.Config', {
 	    iconCls: 'fa fa-power-off'
 	});
 
+	var wakeonlanBtn = Ext.create('Proxmox.button.Button', {
+	    text: gettext('Wake-on-LAN'),
+	    disabled: me.pveSelNode.data.running || !caps.nodes['Sys.PowerMgmt'],
+	    handler: function() {
+		Proxmox.Utils.API2Request({
+		    param: {},
+		    url: '/nodes/' + nodename + '/wakeonlan',
+		    method: 'POST',
+		    failure: function(response, opts) {
+			Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+		    },
+		    success: function(response, opts) {
+			Ext.Msg.show({
+			    title: 'Success',
+			    icon: Ext.Msg.INFO,
+			    msg: Ext.String.format(gettext("Wake on LAN packet send for '{0}': '{1}'"), nodename, response.result.data)
+			});
+		    }
+		});
+	    },
+	    iconCls: 'fa fa-power-off'
+	});
+
 	var shellBtn = Ext.create('PVE.button.ConsoleButton', {
 	    disabled: !caps.nodes['Sys.Console'],
 	    text: gettext('Shell'),
@@ -115,7 +138,7 @@ Ext.define('PVE.node.Config', {
 	    title: gettext('Node') + " '" + nodename + "'",
 	    hstateid: 'nodetab',
 	    defaults: { statusStore: me.statusStore },
-	    tbar: [ restartBtn, shutdownBtn, shellBtn, actionBtn]
+	    tbar: [ restartBtn, shutdownBtn, wakeonlanBtn, shellBtn, actionBtn ]
 	});
 
 	if (caps.nodes['Sys.Audit']) {
@@ -401,13 +424,12 @@ Ext.define('PVE.node.Config', {
 
 	me.mon(me.statusStore, 'load', function(s, records, success) {
 	    var uptimerec = s.data.get('uptime');
-	    var powermgmt = uptimerec ? uptimerec.data.value : false;
-	    if (!caps.nodes['Sys.PowerMgmt']) {
-		powermgmt = false;
-	    }
-	    restartBtn.setDisabled(!powermgmt);
-	    shutdownBtn.setDisabled(!powermgmt);
-	    shellBtn.setDisabled(!powermgmt);
+	    var running = uptimerec ? true : false;
+	    var powermgmt = caps.nodes['Sys.PowerMgmt'];
+	    restartBtn.setDisabled(!(powermgmt && running));
+	    shutdownBtn.setDisabled(!(powermgmt && running));
+	    shellBtn.setDisabled(!(powermgmt && running));
+	    wakeonlanBtn.setDisabled(!powermgmt || running);
 	});
 
 	me.on('afterrender', function() {
-- 
2.11.0




More information about the pve-devel mailing list