[pve-devel] r5826 - in pve-manager/pve2: lib/PVE/API2 www/css
svn-commits at proxmox.com
svn-commits at proxmox.com
Tue Apr 19 11:17:34 CEST 2011
Author: dietmar
Date: 2011-04-19 11:17:33 +0200 (Tue, 19 Apr 2011)
New Revision: 5826
Modified:
pve-manager/pve2/lib/PVE/API2/Cluster.pm
pve-manager/pve2/www/css/ext-pve.css
Log:
use single method to resturn whole status
Modified: pve-manager/pve2/lib/PVE/API2/Cluster.pm
===================================================================
--- pve-manager/pve2/lib/PVE/API2/Cluster.pm 2011-04-19 09:07:15 UTC (rev 5825)
+++ pve-manager/pve2/lib/PVE/API2/Cluster.pm 2011-04-19 09:17:33 UTC (rev 5826)
@@ -40,6 +40,7 @@
my $result = [
{ name => 'log' },
+ { name => 'resources' },
{ name => 'vms' },
{ name => 'storage' },
{ name => 'tasks' },
@@ -217,6 +218,134 @@
}});
__PACKAGE__->register_method({
+ name => 'resources',
+ path => 'resources',
+ method => 'GET',
+ description => "Resources index (cluster wide).",
+ permissions => { user => 'all' },
+ parameters => {
+ additionalProperties => 0,
+ properties => {},
+ },
+ returns => {
+ type => 'array',
+ items => {
+ type => "object",
+ properties => {
+ },
+ },
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $rpcenv = PVE::RPCEnvironment::get();
+ my $user = $rpcenv->get_user();
+
+ my $res = [];
+
+ my $nodes = PVE::Cluster::get_nodelist();
+
+ my $rrd = PVE::Cluster::rrd_dump();
+
+ my $vmlist = PVE::Cluster::get_vmlist() || {};
+ my $idlist = $vmlist->{ids} || {};
+
+ foreach my $vmid (keys %$idlist) {
+ my $data = $idlist->{$vmid};
+
+ next if !$rpcenv->check($user, "/vms/$vmid", [ 'VM.Audit' ]);
+
+ my $entry = {
+ id => "$data->{type}/$vmid",
+ vmid => $vmid,
+ node => $data->{node},
+ type => $data->{type},
+ };
+
+ if (my $d = $rrd->{"pve2-vm/$vmid"}) {
+
+ $entry->{uptime} = $d->[0];
+ $entry->{name} = $d->[1];
+
+ $entry->{maxcpu} = $d->[3];
+ $entry->{cpu} = $d->[4];
+ $entry->{maxmem} = $d->[5];
+ $entry->{mem} = $d->[6];
+ $entry->{maxdisk} = $d->[7];
+ $entry->{disk} = $d->[8];
+ }
+
+ push @$res, $entry;
+ }
+
+ if (0) { # fixme: remove test code
+ my $ctime = time();
+
+ for (my $i = 5000; $i < (5900 + ($ctime % 100)); $i++) {
+ my $nodeid = int(($i - 5000) / 100);
+ my $entry = {
+ id => "qemu/$i",
+ vmid => $i,
+ node => sprintf("tnode%05d", $nodeid),
+ type => 'qemu',
+ maxcpu => 1,
+ cpu => ($ctime % 100)/100.0,
+ };
+ push @$res, $entry;
+ }
+ }
+
+ foreach my $node (@$nodes) {
+ my $entry = {
+ id => "node/$node",
+ node => $node,
+ type => "node",
+ };
+ if (my $d = $rrd->{"pve2-node/$node"}) {
+
+ $entry->{uptime} = $d->[0];
+ $entry->{maxcpu} = $d->[3];
+ $entry->{cpu} = $d->[4];
+ $entry->{maxmem} = $d->[6];
+ $entry->{mem} = $d->[7];
+ $entry->{maxdisk} = $d->[10];
+ $entry->{disk} = $d->[11];
+ }
+
+ push @$res, $entry;
+ }
+
+ my $cfg = PVE::Storage::config();
+ my @sids = PVE::Storage::storage_ids ($cfg);
+
+ foreach my $storeid (@sids) {
+ my $scfg = PVE::Storage::storage_config ($cfg, $storeid);
+
+ next if !$rpcenv->check($user, "/storage/$storeid", [ 'Datastore.Audit' ]);
+ # we create a entry for each node
+ foreach my $node (@$nodes) {
+ # fixme: check if storage is available on this node
+ my $entry = {
+ id => "storage/$node/$storeid",
+ storage => $storeid,
+ node => $node,
+ type => 'storage',
+ };
+
+ if (my $d = $rrd->{"pve2-storage/$node/$storeid"}) {
+ $entry->{maxdisk} = $d->[1];
+ $entry->{disk} = $d->[2];
+ }
+
+ push @$res, $entry;
+
+ }
+ }
+
+ return $res;
+ }});
+
+__PACKAGE__->register_method({
name => 'tasks',
path => 'tasks',
method => 'GET',
Modified: pve-manager/pve2/www/css/ext-pve.css
===================================================================
--- pve-manager/pve2/www/css/ext-pve.css 2011-04-19 09:07:15 UTC (rev 5825)
+++ pve-manager/pve2/www/css/ext-pve.css 2011-04-19 09:17:33 UTC (rev 5826)
@@ -27,7 +27,7 @@
.pve-itype-icon-storage,
.x-tree-node-harddisk,
-.x-grid-tree-node-expanded .x-tree-node-harddisk,
+.x-grid-tree-node-expanded .x-tree-node-harddisk
{
background-image:url(../images/drive-harddisk.png);
}
More information about the pve-devel
mailing list