[pve-devel] r5967 - in pve-manager/pve2: lib/PVE/API2 www/new/node

svn-commits at proxmox.com svn-commits at proxmox.com
Thu May 12 10:27:14 CEST 2011


Author: dietmar
Date: 2011-05-12 10:27:14 +0200 (Thu, 12 May 2011)
New Revision: 5967

Modified:
   pve-manager/pve2/lib/PVE/API2/Nodes.pm
   pve-manager/pve2/www/new/node/Config.js
Log:
impl. node reboot/shutdown


Modified: pve-manager/pve2/lib/PVE/API2/Nodes.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-05-12 06:59:47 UTC (rev 5966)
+++ pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-05-12 08:27:14 UTC (rev 5967)
@@ -162,6 +162,38 @@
     }});
 
 __PACKAGE__->register_method({
+    name => 'node_cmd', 
+    path => 'status', 
+    method => 'POST',
+    permissions => {
+	path => '/nodes/{node}',
+	privs => [ 'Sys.PowerMgmt' ],
+    },
+    description => "Reboot or shutdown a node.",
+    proxyto => 'node',
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    command => {
+		description => "Specify the command.",
+		type => 'string',
+		enum => [qw(reboot shutdown)],
+	    },
+	},
+    },
+    returns => { type => "null" },
+    code => sub {
+	my ($param) = @_;
+
+	if ($param->{command} eq 'reset') {
+	    system ("(sleep 2;shutdown -r now)&");
+	} elsif ($param->{command} eq 'shutdown') {
+	    system ("(sleep 2;/sbin/poweroff)&");
+	}
+    }});
+
+__PACKAGE__->register_method({
     name => 'tasks', 
     path => 'tasks', 
     method => 'GET',

Modified: pve-manager/pve2/www/new/node/Config.js
===================================================================
--- pve-manager/pve2/www/new/node/Config.js	2011-05-12 06:59:47 UTC (rev 5966)
+++ pve-manager/pve2/www/new/node/Config.js	2011-05-12 08:27:14 UTC (rev 5967)
@@ -1,3 +1,80 @@
+Ext.define('PVE.node.Summary', {
+    extend: 'Ext.panel.Panel',
+    alias: 'widget.pveNodeSummary',
+
+    initComponent: function() {
+        var me = this;
+
+	var nodename = me.pveSelNode.data.node;
+	if (!nodename) 
+	    throw "no node name specified";
+
+	var node_command = function(cmd) {
+	    me.setLoading(true, true);
+	    PVE.Utils.API2Request({
+		params: { command: cmd },
+		url: '/nodes/' + nodename + '/status',
+		method: 'POST',
+		callback: function() {
+		    me.setLoading(false);
+		},
+		failure: function(response, opts) {
+		    Ext.Msg.alert('Error', response.htmlStatus);
+		}
+	    });
+	};
+
+	Ext.apply(me, {
+	    layout: 'table',
+	    layoutConfig: {
+		columns: 1
+	    },
+	    bodyStyle: 'padding:10px',
+	    defaults: {
+		style: 'padding-bottom:10px'
+	    },		
+	    tbar: [ 
+		{ 
+		    text: 'Reboot',
+		    handler: function() { 
+			var msg = "Do you really want to reboot node '" + nodename + "'?";
+			Ext.Msg.confirm('Confirm', msg, function(btn) {
+			    if (btn !== 'yes')
+				return;
+			    node_command('reboot');
+			});
+		    }
+		},
+		{ 
+		    text: 'Shutdown', 
+		    handler: function() { 
+			var msg = "Do you really want to shutdown node '" + nodename + "'?";
+			Ext.Msg.confirm('Confirm', msg, function(btn) {
+			    if (btn !== 'yes')
+				return;
+			    node_command('shutdown');
+			});
+		    }
+		}, '->',
+		{ 
+		    text: 'Shell',
+		    handler: function() {
+			var url = Ext.urlEncode({
+			    console: 'shell',
+			    node: nodename
+			});
+			var nw = window.open("?" + url, '_blank', 
+					     "innerWidth=745,innerheight=427");
+			nw.focus();
+		    }
+		}
+	    ]
+	});
+
+	me.callParent();
+    }
+});
+
 Ext.define('PVE.node.Config', {
     extend: 'PVE.panel.Config',
     alias: 'widget.PVE.node.Config',
@@ -16,23 +93,7 @@
 		{
 		    title: 'Summary',
 		    itemId: 'summary',
-		    //xtype: 'pveNodeSummaryView',
-		    tbar: [
-			'->',
-			{ 
-			    text: 'Shell',
-			    handler: function() {
-				var url = Ext.urlEncode({
-				    console: 'shell',
-				    node: nodename
-				});
-				var nw = window.open("?" + url, '_blank', 
-						     "innerWidth=745,innerheight=427");
-				nw.focus();
-			    }
-			}
-		    ],
-		    html: 'summary'
+		    xtype: 'pveNodeSummary',
 		},
 		{
 		    title: 'Services',




More information about the pve-devel mailing list