[pve-devel] r5498 - in pve-manager/pve2: lib/PVE/API2 www/manager

svn-commits at proxmox.com svn-commits at proxmox.com
Wed Feb 9 13:46:42 CET 2011


Author: dietmar
Date: 2011-02-09 13:46:41 +0100 (Wed, 09 Feb 2011)
New Revision: 5498

Modified:
   pve-manager/pve2/lib/PVE/API2/Services.pm
   pve-manager/pve2/www/manager/NodeConfig.js
Log:
implement service view


Modified: pve-manager/pve2/lib/PVE/API2/Services.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Services.pm	2011-02-09 10:58:40 UTC (rev 5497)
+++ pve-manager/pve2/lib/PVE/API2/Services.pm	2011-02-09 12:46:41 UTC (rev 5498)
@@ -124,6 +124,7 @@
     method => 'GET',
     description => "Service list.",
     proxyto => 'node',
+    protected => 1,
     parameters => {
     	additionalProperties => 0,
 	properties => {
@@ -161,6 +162,7 @@
     method => 'GET',
     description => "Read service properties",
     proxyto => 'node',
+    protected => 1,
     parameters => {
     	additionalProperties => 0,
 	properties => {

Modified: pve-manager/pve2/www/manager/NodeConfig.js
===================================================================
--- pve-manager/pve2/www/manager/NodeConfig.js	2011-02-09 10:58:40 UTC (rev 5497)
+++ pve-manager/pve2/www/manager/NodeConfig.js	2011-02-09 12:46:41 UTC (rev 5498)
@@ -778,6 +778,150 @@
 });
 Ext.reg('pveNodeDNSView', PVE.NodeDNSView);
 
+PVE.NodeServiceView = Ext.extend(Ext.grid.GridPanel, {
+
+    initComponent : function() {
+	var self = this;
+
+	var nodename = self.nodename;
+
+	if (!nodename) 
+	    throw "no node name specified";
+
+	var store = new Ext.data.JsonStore({
+	    url: "/api2/json/nodes/" + nodename + "/services",
+	    autoDestory: true,
+	    root: 'data',
+	    restful: true, // use GET, not POST
+	    fields: [ 'service', 'name', 'desc', 'state' ],
+	    sortInfo: { field: 'name', order: 'DESC' }
+	});
+
+	var update_store = function() {
+	    store.load();
+	};
+
+	var sm;
+
+	var service_cmd = function(cmd) {
+	    var rec = sm.getSelected();
+	    Ext.Ajax.request({
+		url: "/api2/json/nodes/" + nodename + "/services/" + rec.data.service,
+		params: { command: cmd },
+		method: 'PUT',
+		failure: function(response, opts) {
+		    Ext.Msg.alert("Error", "Error " + response.status + ": " 
+				  + response.statusText);
+		    update_store();
+		},
+		success: function(response, opts) {
+		    update_store();
+		}
+	    });
+	};
+
+	var start_btn = new Ext.Button({
+	    text: 'Start',
+	    disabled: true,
+	    handler: function(){
+		service_cmd("start");
+	    }
+	});
+	var stop_btn = new Ext.Button({
+	    text: 'Stop',
+	    disabled: true,
+	    handler: function(){
+		service_cmd("stop");
+	    }
+	});
+	var restart_btn = new Ext.Button({
+	    text: 'Restart',
+	    disabled: true,
+	    handler: function(){
+		service_cmd("restart");
+	    }
+	});
+
+	sm = new Ext.grid.RowSelectionModel({
+	    singleSelect: true,
+	    listeners: {
+		rowselect: function(selm, row, record) {
+		    var service = record.data.service;
+		    var state = record.data.state;
+		    if (service == 'apache' || service == 'pvedaemon') {
+			if (state == 'running') {
+			    start_btn.disable();
+			    restart_btn.enable();
+			} else {
+			    start_btn.enable();
+			    restart_btn.disable();
+			}
+			stop_btn.disable();
+		    } else {
+			if (state == 'running') {
+			    start_btn.disable();
+			    restart_btn.enable();
+			    stop_btn.enable();
+			} else {
+			    start_btn.enable();
+			    restart_btn.disable();
+			    stop_btn.disable();
+			}
+		    }
+		},
+		rowdeselect: function(selm, row, record) {
+		    start_btn.disable();
+		    stop_btn.disable();
+		    restart_btn.disable();
+		}
+	    }
+	});
+
+	store.on("load", function() {
+	    start_btn.disable();
+	    stop_btn.disable();
+	    restart_btn.disable();
+	}); 
+
+	Ext.apply(self, {
+	    store: store,
+	    autoExpandColumn: 'desc',
+	    stateful: false,
+	    columns: [
+		{
+		    header: 'Name',
+		    width: 100,
+		    sortable: true,
+		    dataIndex: 'name'
+		},
+		{
+		    header: 'State',
+		    width: 100,
+		    sortable: true,
+		    dataIndex: 'state'
+		},
+		{
+		    header: 'Description',
+		    dataIndex: 'desc',
+		    id: 'desc'
+		}
+	    ],
+	    sm: sm,
+	    listeners: {
+		show: function() {
+		    update_store();
+		}
+	    },
+	    tbar: [ 
+		start_btn, "-", stop_btn, "-", restart_btn
+	    ]
+	});
+
+	PVE.NodeServiceView.superclass.initComponent.call(self);
+    }
+});
+Ext.reg('pveNodeServiceView', PVE.NodeServiceView);
+
 PVE.NodeConfig = Ext.extend(PVE.ConfigPanel, {
 
     initComponent : function() {
@@ -811,7 +955,8 @@
 		{
 		    title: 'Services',
 		    id: 'services',
-		    html: 'services ' + nodename
+		    xtype: 'pveNodeServiceView',
+		    nodename: nodename
 		},
 		{
 		    title: 'Network',




More information about the pve-devel mailing list