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

svn-commits at proxmox.com svn-commits at proxmox.com
Thu Jan 13 08:25:31 CET 2011


Author: dietmar
Date: 2011-01-13 08:25:31 +0100 (Thu, 13 Jan 2011)
New Revision: 5381

Modified:
   pve-manager/pve2/bin/pvesh
   pve-manager/pve2/lib/PVE/API2/Cluster.pm
   pve-manager/pve2/lib/PVE/API2/VM.pm
   pve-manager/pve2/lib/PVE/APIDaemon.pm
   pve-manager/pve2/lib/PVE/REST.pm
   pve-manager/pve2/www/manager/PVECache.js
Log:
try to get it workinhg again



Modified: pve-manager/pve2/bin/pvesh
===================================================================
--- pve-manager/pve2/bin/pvesh	2011-01-13 07:23:13 UTC (rev 5380)
+++ pve-manager/pve2/bin/pvesh	2011-01-13 07:25:31 UTC (rev 5381)
@@ -13,6 +13,7 @@
 use HTTP::Status qw(:constants :is status_message);
 use Text::ParseWords;
 use PVE::JSONSchema;
+use PVE::Cluster;
 use PVE::INotify;
 use PVE::RPCEnvironment;
 use PVE::API2;
@@ -141,6 +142,8 @@
 sub call_method {
     my ($dir, $cmd, $args) = @_;
 
+    PVE::Cluster::cfs_update();
+
     my $method = map_cmd($cmd);
 
     my $uri_param = {};

Modified: pve-manager/pve2/lib/PVE/API2/Cluster.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Cluster.pm	2011-01-13 07:23:13 UTC (rev 5380)
+++ pve-manager/pve2/lib/PVE/API2/Cluster.pm	2011-01-13 07:25:31 UTC (rev 5381)
@@ -4,6 +4,10 @@
 use warnings;
 
 use PVE::SafeSyslog;
+use PVE::Cluster;
+
+use Data::Dumper; # fixme: remove
+
 use Apache2::Const qw(:http);
 use JSON;
 
@@ -31,29 +35,36 @@
     code => sub {
 	my ($param) = @_;
     
-	# fixme: this is just some test code
 
-	my $ctime = int(time()/1);
-	$ctime = 0;
+	my $clinfo = PVE::Cluster::get_clinfo();
+	my $result = [];
 
-	#my $count = 30 + ($ctime % 10);
-	my $count = 4;
+	my $nodename = PVE::INotify::nodename();
+	my $nodelist = $clinfo->{nodelist};
 
-	my $result = [];
-	for (my $i = 0; $i < $count; $i++) {
-	    my $tag = int($i / 4);
-	    my $store = int($i / 2);
+	if (!$nodelist) {
 	    push @$result, { 
-		name => "node-$i",
-#	    storage => "store-$store",
+		name => $nodename,
 		cpu => 0.5,
 		maxcpu => 16,
 		uptime => 20*3600*24,
 		mem => 0,
 		maxmem => 10
 	    };
+	    return $result;
 	}
 
+	foreach my $node (keys %$nodelist) {
+	    push @$result, { 
+		name => $node,
+		cpu => 0.1,
+		maxcpu => 8,
+		uptime => 10*3600*24,
+		mem => 0,
+		maxmem => 10
+	    };
+	}
+
 	return $result;
     }});
 

Modified: pve-manager/pve2/lib/PVE/API2/VM.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/VM.pm	2011-01-13 07:23:13 UTC (rev 5380)
+++ pve-manager/pve2/lib/PVE/API2/VM.pm	2011-01-13 07:25:31 UTC (rev 5381)
@@ -3,8 +3,12 @@
 use strict;
 use warnings;
 
+use PVE::SafeSyslog;
 use PVE::RESTHandler;
+use PVE::Cluster;
 
+use Data::Dumper; # fixme: remove
+
 use base qw(PVE::RESTHandler);
 
 use PVE::API2::Qemu;
@@ -36,7 +40,7 @@
     code => sub {
 	my ($param) = @_;
 
-	my $res = [];
+	my $res = [ { subdir => 'index' } ];
 
 	my $ma = __PACKAGE__->method_attributes();
 
@@ -51,10 +55,9 @@
 	return $res;
     }});
 
-# fixme:remove
-__PACKAGE__->register_method ({
-    name => 'oldindex', 
-    path => 'oldindex', 
+__PACKAGE__->register_method({
+    name => 'vmlist', 
+    path => 'index', 
     method => 'GET',
     description => "Virtual machine index.",
     parameters => {
@@ -67,33 +70,37 @@
 	    type => "object",
 	    properties => {},
 	},
-	links => [ { rel => 'child', href => "{id}" } ],
+#	links => [ { rel => 'child', href => "{id}" } ],
     },
     code => sub {
 	my ($param) = @_;
 
-	my $ctime = int(time()/3);
-	$ctime = 0;
-
+	my $vmlist = PVE::Cluster::get_vmlist();
 	my $result = [];
 
-	for (my $i = 0; $i < 4; $i++) {
-	    for (my $j = 0; $j < 1; $j++) {
-		my $vmid = $i*100+$j;
-		my $cpu = (($ctime + $vmid) % 100)/100;
-		#  storage => "local (node-$i)",
-		push @$result, { id => $vmid, name => "VM $vmid", node => "node-$i" , cpu => $cpu, maxcpu => 1, mem => 1024*1024*1024*6, maxmem => 1024*1024*1024*24, disk => 1024*1024*1024*1024*6, maxdisk => 1024*1024*1024*1024*32, uptime => 2*3600 };
-	    }
-	}
+	return $result if !$vmlist;
 
-	my $count = ($ctime % 10);
+	my $idlist = $vmlist->{ids};
+	return $result if !$idlist;
 
-	for (my $i = 0; $i < $count; $i++) {
-	    my $vmid = 50+$i;
-	    my $cpu = (($ctime + $vmid) % 100)/100;
-	    push @$result, { id => $vmid, name => "VM $vmid", node => "node-$i" , storage => "store-$i", cpu => $cpu, maxcpu => 2};
+	foreach my $vmid (keys %$idlist) {
+	    my $data = $idlist->{$vmid};
+
+	    push @$result, { 
+		id => $vmid, 
+		name => "VM $vmid", 
+		node => $data->{node},
+		type => $data->{type},
+		cpu => 0, 
+		maxcpu => 1, 
+		mem => 1024*1024*1024*6, 
+		maxmem => 1024*1024*1024*24, 
+		disk => 1024*1024*1024*1024*6, 
+		maxdisk => 1024*1024*1024*1024*32, 
+		uptime => 2*3600 
+	    };
 	}
-    
+   
 	return $result;
     }});
 

Modified: pve-manager/pve2/lib/PVE/APIDaemon.pm
===================================================================
--- pve-manager/pve2/lib/PVE/APIDaemon.pm	2011-01-13 07:23:13 UTC (rev 5380)
+++ pve-manager/pve2/lib/PVE/APIDaemon.pm	2011-01-13 07:25:31 UTC (rev 5381)
@@ -4,6 +4,7 @@
 use warnings;
 use vars qw(@ISA);
 use PVE::SafeSyslog;
+use PVE::Cluster;
 use PVE::INotify;
 use PVE::RPCEnvironment;
 
@@ -252,7 +253,9 @@
 
 			my $parser = HTTP::Request::Params->new({req => $r});
 			my $params = $parser->params;
-		
+
+			PVE::Cluster::cfs_update();
+
 			my $res = PVE::REST::rest_handler($method, $uri, $rel_uri, $ticket, $params);
 
 			if ($res->{proxy}) {

Modified: pve-manager/pve2/lib/PVE/REST.pm
===================================================================
--- pve-manager/pve2/lib/PVE/REST.pm	2011-01-13 07:23:13 UTC (rev 5380)
+++ pve-manager/pve2/lib/PVE/REST.pm	2011-01-13 07:25:31 UTC (rev 5381)
@@ -3,6 +3,7 @@
 use warnings;
 use strict;
 use Digest::SHA1 qw(sha1_base64);
+use PVE::Cluster;
 use PVE::SafeSyslog;
 use PVE::Tools;
 use PVE::API2;
@@ -365,6 +366,8 @@
      my ($rel_uri, $format) = split_abs_uri($abs_uri);
      return HTTP_NOT_IMPLEMENTED if !$format;
 
+     PVE::Cluster::cfs_update();
+
      my $res = rest_handler($method, $abs_uri, $rel_uri, $ticket, $params);
 
      if ($res->{proxy}) {

Modified: pve-manager/pve2/www/manager/PVECache.js
===================================================================
--- pve-manager/pve2/www/manager/PVECache.js	2011-01-13 07:23:13 UTC (rev 5380)
+++ pve-manager/pve2/www/manager/PVECache.js	2011-01-13 07:25:31 UTC (rev 5381)
@@ -37,7 +37,7 @@
 		itype: 'vm',
 		idProperty: 'id',
 		autoDestroy: false,
-		url: '/api2/json/vms',
+		url: '/api2/json/vms/index',
 		fields: fields
 	    });
 




More information about the pve-devel mailing list