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

svn-commits at proxmox.com svn-commits at proxmox.com
Wed May 25 19:00:25 CEST 2011


Author: dietmar
Date: 2011-05-25 19:00:25 +0200 (Wed, 25 May 2011)
New Revision: 6021

Added:
   pve-manager/pve2/www/new/window/TaskViewer.js
Removed:
   pve-manager/pve2/lib/PVE/Qemu.pm
Modified:
   pve-manager/pve2/lib/PVE/API2/Nodes.pm
   pve-manager/pve2/lib/PVE/Makefile.am
   pve-manager/pve2/www/new/Makefile.am
   pve-manager/pve2/www/new/PVEUtils.js
   pve-manager/pve2/www/new/node/Tasks.js
Log:
mpl. task viewer


Modified: pve-manager/pve2/lib/PVE/API2/Nodes.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-05-25 13:07:40 UTC (rev 6020)
+++ pve-manager/pve2/lib/PVE/API2/Nodes.pm	2011-05-25 17:00:25 UTC (rev 6021)
@@ -290,6 +290,7 @@
 		upid => { type => 'string' },
 	    },
 	},
+	links => [ { rel => 'child', href => "{upid}" } ],
     },
     code => sub {
 	my ($param) = @_;
@@ -301,6 +302,7 @@
 
 	my $filename = "/var/log/pve/tasks/index";
 
+	my $node = $param->{node};
 	my $start = $param->{start} || 0;
 	my $limit = $param->{limit} || 50;
 	my $userfilter = $param->{userfilter};
@@ -309,6 +311,8 @@
 	my $count = 0;
 	my $line;
 
+	my $autitor = $rpcenv->check($user, "/nodes/$node", [ 'Sys.Audit' ]);
+
 	my $parse_line = sub {
 	    if ($line =~ m/^(\S+)(\s([0-9A-Za-z]{8})(\s(\S.*))?)?$/) {
 		my $upid = $1;
@@ -316,6 +320,8 @@
 		my $status = $5;
 		if ((my $task = PVE::Tools::upid_decode($upid, 1))) {
 		    return if $userfilter && $task->{user} !~ m/\Q$userfilter\E/i;
+		    next if !($autitor || $user eq $task->{user});
+
 		    return if $errors && $status && $status eq 'OK';
 
 		    return if $count++ < $start;
@@ -349,6 +355,88 @@
     }});
 
 __PACKAGE__->register_method({
+    name => 'read_task_log', 
+    path => 'tasks/{upid}', 
+    method => 'GET',
+    permissions => { user => 'all' },
+    protected => 1,
+    description => "Read task log.",
+    proxyto => 'node',
+    parameters => {
+    	additionalProperties => 0,
+	properties => {
+	    node => get_standard_option('pve-node'),
+	    upid => { type => 'string' },
+	    start => {
+		type => 'integer',
+		minimum => 0,
+		optional => 1,
+	    },
+	    limit => {
+		type => 'integer',
+		minimum => 0,
+		optional => 1,
+	    },
+	},
+    },
+    returns => {
+	type => 'array',
+	items => { 
+	    type => "object",
+	    properties => {
+		n => {
+		  description=>  "Line number",
+		  type=> 'integer',
+		},
+		t => {
+		  description=>  "Line text",
+		  type => 'string',
+		}
+	    }
+	}
+    },
+    code => sub {
+	my ($param) = @_;
+
+	my ($task, $filename) = PVE::Tools::upid_decode($param->{upid}, 1);
+	raise_param_exc({ upid => "unable to parse worker upid" }) if !$task;
+
+	$filename = "/var/log/syslog"; # fixme: remove
+
+	my $lines = [];
+
+	my $rpcenv = PVE::RPCEnvironment::get();
+	my $user = $rpcenv->get_user();
+	my $node = $param->{node};
+
+	my $autitor = $rpcenv->check($user, "/nodes/$node", [ 'Sys.Audit' ]);
+	die "Permission check failed\n"
+	    if !($autitor || $user eq $task->{user});
+
+	my $fh = IO::File->new($filename, "r");
+	raise_param_exc({ upid => "no such task - unable to open file - $!" }) if !$fh;
+
+	my $start = $param->{start} || 0;
+	my $limit = $param->{limit} || 50;
+	my $count = 0;
+	my $line;
+
+	while (defined ($line = <$fh>)) {
+	    next if $count++ < $start;
+	    next if $limit <= 0;
+	    chomp $line;
+	    push @$lines, { n => $count, t => $line};
+	    $limit--;
+	}
+
+	close($fh);
+
+	$rpcenv->set_result_count($count);
+	    
+	return $lines;
+    }});
+
+__PACKAGE__->register_method({
     name => 'rrd', 
     path => 'rrd', 
     method => 'GET',
@@ -474,6 +562,7 @@
 
 	my $loguser = $user eq 'root at pam' ? "" : $user;
 
+	# fixme: read local file instead? use start/limit parameter?
 	my $res = decode_json(PVE::Cluster::get_system_log($loguser, $max));
 
 	# fixme: can we avoid that?

Modified: pve-manager/pve2/lib/PVE/Makefile.am
===================================================================
--- pve-manager/pve2/lib/PVE/Makefile.am	2011-05-25 13:07:40 UTC (rev 6020)
+++ pve-manager/pve2/lib/PVE/Makefile.am	2011-05-25 17:00:25 UTC (rev 6021)
@@ -7,8 +7,6 @@
 	API2Client.pm		\
 	APIDaemon.pm		\
 	REST.pm			\
-	OpenVZ.pm		\
-	Qemu.pm			\
 	APLInfo.pm
 
 BUILDDATA = pvecfg.pm

Deleted: pve-manager/pve2/lib/PVE/Qemu.pm
===================================================================
--- pve-manager/pve2/lib/PVE/Qemu.pm	2011-05-25 13:07:40 UTC (rev 6020)
+++ pve-manager/pve2/lib/PVE/Qemu.pm	2011-05-25 17:00:25 UTC (rev 6021)
@@ -1,116 +0,0 @@
-package PVE::Qemu;
-
-use strict;
-use IO::Dir;
-use IO::File;
-use PVE::Config;
-use PVE::QemuServer;
-use PVE::SafeSyslog;
-use Time::HiRes qw (gettimeofday);
-
-my $last_proc_pid_stat;
-
-my $clock_ticks = POSIX::sysconf(&POSIX::_SC_CLK_TCK);
-
-sub vmlist {
-
-    my $res = {};
-
-    my $list =  PVE::QemuServer::vzlist();
-    my ($uptime) = PVE::Utils::read_proc_uptime();
-
-    foreach my $veid (keys %$list) {
-	my $fn = PVE::QemuServer::config_file ($veid);
-	my $conf = PVE::Config::read_file ($fn);
-     
-	my $d = {};
-	$d->{type} = 'qemu';
-	$d->{nproc} = 0;
-	$d->{pid} = $list->{$veid}->{pid};
-	$d->{status} = $list->{$veid}->{pid} ? 'running' : 'stopped';
-	$d->{ip} = '-';
-	$d->{disk} = 0;
-	$d->{cpus} = ($conf->{sockets} || 1) * ($conf->{cores} || 1);
-	$d->{name} = $conf->{name} || "VM$veid";
-
-	$d->{maxmem} = $conf->{memory} ? $conf->{memory} : 0; 
-
-	$d->{maxdisk} = $conf->{disksize} ? int($conf->{disksize}*1024) : 0;
-
-	$d->{uptime} = 0;
-	$d->{pctcpu} = 0;
-	$d->{relcpu} = 0;
-	$d->{mem} = 0;
-
-	$res->{"VEID_$veid"} = $d;
-
-    }
-
-    my $cpuinfo = PVE::Utils::get_cpu_info();
-    my $cpucount = $cpuinfo->{cpus} || 1;
-    my $ctime = gettimeofday;
-
-    foreach my $veid (keys %$list) {
-
-	my $d = $res->{"VEID_$veid"};
-	my $pid = $d->{pid};
-	next if !$pid;
-
-	my $statstr;
-	if (my $fh = IO::File->new ("/proc/$pid/stat", "r")) {
-	    $statstr = <$fh>;
-	    $fh->close;
-	}
-	next if !$statstr;
-
-	my ($utime, $stime, $vsize, $rss, $starttime);
-	if ($statstr =~ m/^$pid \(.*\) \S (-?\d+) -?\d+ -?\d+ -?\d+ -?\d+ \d+ \d+ \d+ \d+ \d+ (\d+) (\d+) (-?\d+) (-?\d+) -?\d+ -?\d+ -?\d+ 0 (\d+) (\d+) (-?\d+) \d+ \d+ \d+ \d+ \d+ \d+ \d+ \d+ \d+ \d+ \d+ \d+ \d+ -?\d+ -?\d+ \d+ \d+ \d+/) {
-	    ($utime, $stime, $vsize, $rss, $starttime) = ($2, $3, $7, $8 * 4096, $6);
-	} else {
-	    next;
-	}
- 
-	my $used = $utime + $stime;
-
-	my $vcpus = $d->{cpus} > $cpucount ? $cpucount : $d->{cpus};
-
-	$d->{uptime} = int ($uptime - ($starttime/100));
-
-	if ($vsize) {
-	    $d->{mem} = int (($rss/$vsize)*$d->{maxmem});
-	}
-
-	my $old = $last_proc_pid_stat->{$pid};
-	if (!$old) {
-	    $last_proc_pid_stat->{$pid} = { 
-		time => $ctime, 
-		used => $used,
-		pctcpu => 0,
-		relcpu => 0,
-	    };
-	    next;
-	}
-
-	my $dtime = ($ctime -  $old->{time}) * $cpucount * $clock_ticks;
-
-	if ($dtime > 1000) {
-	    my $dutime = $used -  $old->{used};
-
-	    $d->{pctcpu} = int((($dutime)*100)/$dtime);
-	    $d->{relcpu} = int (($d->{pctcpu} * $cpucount) / $vcpus);
-	    $last_proc_pid_stat->{$pid} = {
-		time => $ctime, 
-		used => $used,
-		pctcpu => $d->{pctcpu},
-		relcpu => $d->{relcpu},
-	    };
-	} else {
-	    $d->{pctcpu} = $old->{pctcpu};
-	    $d->{relcpu} = $old->{relcpu};
-	}
-    }
-
-    return $res;
-}
-
-1;

Modified: pve-manager/pve2/www/new/Makefile.am
===================================================================
--- pve-manager/pve2/www/new/Makefile.am	2011-05-25 13:07:40 UTC (rev 6020)
+++ pve-manager/pve2/www/new/Makefile.am	2011-05-25 17:00:25 UTC (rev 6021)
@@ -28,6 +28,7 @@
 	panel/StatusPanel.js				\
 	panel/RRDView.js				\
 	window/LoginWindow.js				\
+	window/TaskViewer.js				\
 	window/Wizard.js				\
 	grid/ObjectGrid.js				\
 	grid/ResourceGrid.js				\

Modified: pve-manager/pve2/www/new/PVEUtils.js
===================================================================
--- pve-manager/pve2/www/new/PVEUtils.js	2011-05-25 13:07:40 UTC (rev 6020)
+++ pve-manager/pve2/www/new/PVEUtils.js	2011-05-25 17:00:25 UTC (rev 6021)
@@ -177,6 +177,38 @@
 	}
     },
 
+    format_task_description: function(type, id) {
+
+	if (type == 'vncproxy')
+	    return "VNC connection to VM " + id;
+
+	if (type == 'vncshell')
+	    return "VNC shell";
+
+	return type;
+    },
+
+
+    parse_task_upid: function(upid) {
+	var task = {};
+
+	var res = upid.match(/^UPID:(\w+):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8}):([^:\s]+):([^:\s]*):([^:\s]+):$/);
+	if (!res)
+	    throw "unable to parse upid '" + upid + "'";
+
+	task.node = res[1];
+	task.pid = parseInt(res[2], 16);
+	task.pstart = parseInt(res[3], 16);
+	task.starttime = parseInt(res[4], 16);
+	task.type = res[5];
+	task.id = res[6];
+	task.user = res[7];
+
+	task.desc = PVE.Utils.format_task_description(task.type, task.id);
+
+	return task;
+    },
+
     format_size: function(size) {
 
 	var kb = size / 1024;
@@ -311,20 +343,6 @@
 	return PVE.Utils.log_severity_hash[value] || value;
     },
 
-    render_upid: function(value, metaData, record) { 
-	var type = record.data.type;
-	var id = record.data.id;
-
-	if (type == 'vncproxy') {
-	    return "VNC connection to VM " + id;
-	}
-	if (type == 'vncshell') {
-	    return "VNC shell";
-	}
-
-	return value;
-    },
-    
     render_cpu: function(value, metaData, record, rowIndex, colIndex, store) {
 
 	var maxcpu = record.data.maxcpu;
@@ -401,15 +419,7 @@
 	var type = record.data.type;
 	var id = record.data.id;
 
-	if (type == 'vncproxy') {
-	    return "VNC connection to VM " + id;
-	}
-	if (type == 'vncshell') {
-	    return "VNC shell";
-	}
-
-	return value;
-    }			  
-
+	return PVE.Utils.format_task_description(type, id);
+    }
 });
 

Modified: pve-manager/pve2/www/new/node/Tasks.js
===================================================================
--- pve-manager/pve2/www/new/node/Tasks.js	2011-05-25 13:07:40 UTC (rev 6020)
+++ pve-manager/pve2/www/new/node/Tasks.js	2011-05-25 17:00:25 UTC (rev 6021)
@@ -55,6 +55,25 @@
 	    ptbar.doRefresh();
 	});
 
+	var run_task_viewer = function() {
+	    var sm = me.getSelectionModel();
+	    var rec = sm.getLastSelected();
+	    if (!rec)
+		return;
+
+	    var win = Ext.create('PVE.window.TaskViewer', { 
+		upid: rec.data.upid
+	    });
+	    win.show();
+	};
+
+	var view_btn = new Ext.Button({
+	    text: 'View',
+	    disabled: true,
+	    handler: run_task_viewer
+	});
+
+
 	Ext.apply(me, {
 	    store: store,
 	    stateful: false,
@@ -71,7 +90,7 @@
 		}
 	    },
 	    tbar: [
-		'->', 'User:', ' ',
+		view_btn, '->', 'User:', ' ',
 		{
 		    xtype: 'textfield',
 		    width: 200,
@@ -137,6 +156,10 @@
 		}
 	    ],
 	    listeners: {
+		itemdblclick: run_task_viewer,
+		selectionchange: function(v, selections) {
+		    view_btn.setDisabled(!(selections && selections[0]));
+		},
 		show: function() { reload_task.delay(10); }
 	    }
 	});

Added: pve-manager/pve2/www/new/window/TaskViewer.js
===================================================================
--- pve-manager/pve2/www/new/window/TaskViewer.js	                        (rev 0)
+++ pve-manager/pve2/www/new/window/TaskViewer.js	2011-05-25 17:00:25 UTC (rev 6021)
@@ -0,0 +1,68 @@
+Ext.define('PVE.window.TaskViewer', {
+    extend: 'Ext.window.Window',
+    requires: [
+        'PVE.Utils'
+    ],
+    alias: 'widget.pveTaskViewer',
+
+    initComponent: function() {
+        var me = this;
+
+	if (!me.upid)
+	    throw "no task specified";
+
+	console.log("TEST " + me.upid);
+
+	var task = PVE.Utils.parse_task_upid(me.upid);
+	console.dir(task);
+
+	var store = Ext.create('Ext.data.Store', {
+ 	    model: Ext.define('pve-string-list', {
+		extend: 'Ext.data.Model',
+		fields:  [ 'n', 't' ],
+		idProperty: 'n'
+	    }),
+            pageSize: 200,
+	    buffered: true,
+	    proxy: {
+                type: 'pve',
+		startParam: 'start',
+		limitParam: 'limit',
+                url: "/api2/json/nodes/" + task.node + "/tasks/" + me.upid
+	    },
+	});
+
+	store.load();
+
+	Ext.applyIf(me, {
+	    title: "Task viewer: " + task.desc,
+	    width: 800,
+	    height: 400,
+	    layout: 'fit',
+	    items: {
+		xtype: 'gridpanel',
+		store: store,
+		stateful: false,
+		border: false,
+		tbar: [ 'test' ],
+		verticalScrollerType: 'paginggridscroller',
+		loadMask: true,
+		disableSelection: true,
+		invalidateScrollerOnRefresh: false,
+		viewConfig: {
+		    trackOver: false,
+		    stripeRows: false,
+		    emptyText: 'Log is empty.'
+		},
+		hideHeaders: true,
+		columns: [ 
+		    { header: "Line", dataIndex: 'n', width: 50 },
+		    { header: "Text", dataIndex: 't', flex: 1 } 
+		]
+	    }
+        });
+
+        me.callParent();
+    }
+});
+




More information about the pve-devel mailing list