[pve-devel] Pool View

Andrew Thrift andrew at networklabs.co.nz
Sun Jul 6 23:51:49 CEST 2014


Hello,

We have a number of administrators using our PVE cluster, with hundreds of
VM's that are grouped by customer in to Pools.   We were regularly getting
complaints from our admin users about the difficulty in finding Virtual
Machines that were for a specific customer.  As our VM's were already
grouped by pool we decided to develop a new view  called "Pool View".

The Pool View is very similar to the current Server View, but lists the
Pools in the left hand column, and allows expansion of each pool to show
the VM's within it.

This makes administration of pools and VM's a lot more logical, and faster.

The "Pool View" patch honors security permissions on Pools, and has been
developed against PVE3.2 (we also have a tested patch for PVE3.0).  The
Pool View does not list Storage Resources, as it clutters the view making
locating VM's more cumbersome, and is just duplication of what can be done
in the "Storage View".

We figure that since this has been so useful for us, it would most likely
be useful for other PVE users, and would be nice to see included in PVE.

Patch inline:


diff -Nuarp usr/share/perl5/PVE/AccessControl.pm
usr/share/perl5/PVE/AccessControl.pm
--- usr/share/perl5/PVE/AccessControl.pm 2014-06-27 16:23:34.305587119 +1200
+++ usr/share/perl5/PVE/AccessControl.pm 2014-06-27 16:23:44.077692909 +1200
@@ -492,7 +492,7 @@ my $privgroups = {
     },
 };

-my $valid_privs = {};
+our $valid_privs = {};

 my $special_roles = {
     'NoAccess' => {}, # no priviledges
diff -Nuarp usr/share/perl5/PVE/API2/Cluster.pm
usr/share/perl5/PVE/API2/Cluster.pm
--- usr/share/perl5/PVE/API2/Cluster.pm 2014-06-27 16:22:37.302970017 +1200
+++ usr/share/perl5/PVE/API2/Cluster.pm 2014-06-27 16:26:30.939493106 +1200
@@ -19,6 +19,8 @@ use PVE::RESTHandler;
 use PVE::RPCEnvironment;
 use PVE::JSONSchema qw(get_standard_option);

+use PVE::AccessControl qw(valid_privs);
+
 use base qw(PVE::RESTHandler);

 __PACKAGE__->register_method ({
@@ -160,12 +162,20 @@ __PACKAGE__->register_method({
  my $vmlist = PVE::Cluster::get_vmlist() || {};
  my $idlist = $vmlist->{ids} || {};

+ my $storage_pool = {};
+
+ foreach my $pool (keys(%{$usercfg->{pools}})) {
+ foreach my $storage (keys(%{$usercfg->{pools}->{$pool}->{storage}})) {
+ $storage_pool->{$storage}=$pool;
+ }
+ }
+
  my $pooldata = {};
  if (!$param->{type} || $param->{type} eq 'pool') {
     foreach my $pool (keys %{$usercfg->{pools}}) {
  my $d = $usercfg->{pools}->{$pool};

- next if !$rpcenv->check($authuser, "/pool/$pool", [ 'Pool.Allocate' ], 1);
+ next if !$rpcenv->check_any($authuser, "/pool/$pool", [keys
$PVE::AccessControl::valid_privs], 1);

  my $entry = {
     id => "/pool/$pool",
@@ -185,9 +195,9 @@ __PACKAGE__->register_method({

  my $data = $idlist->{$vmid};
  my $entry = PVE::API2Tools::extract_vm_stats($vmid, $data, $rrd);
- if ($entry->{uptime}) {
-    if (my $pool = $usercfg->{vms}->{$vmid}) {
- if (my $pe = $pooldata->{$pool}) {
+ if (my $pool = $usercfg->{vms}->{$vmid}) {
+    if (my $pe = $pooldata->{$pool}) {
+ if ($entry->{uptime}) {
     $pe->{uptime} = $entry->{uptime} if !$pe->{uptime} || $entry->{uptime}
> $pe->{uptime};
     $pe->{mem} = 0 if !$pe->{mem};
     $pe->{mem} += $entry->{mem};
@@ -198,6 +208,7 @@ __PACKAGE__->register_method({
     $pe->{maxcpu} = 0 if !$pe->{maxcpu};
     $pe->{maxcpu} += $entry->{maxcpu};
  }
+ $entry->{pool} = $pe->{pool};
     }
  }

@@ -228,6 +239,9 @@ __PACKAGE__->register_method({
     next if !PVE::Storage::storage_check_enabled($cfg, $storeid, $node, 1);

     my $entry = PVE::API2Tools::extract_storage_stats($storeid, $scfg,
$node, $rrd);
+    if (exists $storage_pool->{$entry->{storage}}) {
+ $entry->{"pool"}=$storage_pool->{$entry->{storage}};
+    }
     push @$res, $entry;
  }
     }
diff -Nuarp usr/share/pve-manager/css/ext-pve.css
usr/share/pve-manager/css/ext-pve.css
--- usr/share/pve-manager/css/ext-pve.css 2014-06-27 16:33:46.291799762
+1200
+++ usr/share/pve-manager/css/ext-pve.css 2014-06-27 16:34:56.083492567
+1200
@@ -108,7 +108,7 @@
 .x-tree-node-pool,
 .x-grid-tree-pool-expanded .x-tree-node-pool
 {
-    background-image:url(../images/connect_established.png);
+    background-image:url(../images/connect_established.png) !important;
 }

 .pve-itype-icon-itype
diff -Nuarp usr/share/pve-manager/ext4/pvemanagerlib.js
usr/share/pve-manager/ext4/pvemanagerlib.js
--- usr/share/pve-manager/ext4/pvemanagerlib.js 2014-06-27
16:33:56.642902474 +1200
+++ usr/share/pve-manager/ext4/pvemanagerlib.js 2014-07-03
12:39:08.325001416 +1200
@@ -4234,6 +4234,15 @@ Ext.define('PVE.form.ViewSelector', {
  filterfn: function(node) {
     return node.data.type === 'storage';
  }
+    },
+    pool: {
+ text: gettext('Pool View'),
+ groups: ['pool'],
+                // Pool View is essentially an inverse of "Storage View",
+                // where storage items are excluded from the overview.
+                filterfn: function(node) {
+                    return node.data.type !== 'storage';
+                }
     }
  };

@@ -7220,6 +7229,11 @@ Ext.define('PVE.grid.PoolMembers', {
     if (!group) {
  var groupinfo;
  if (info.type === groupby) {
+    if (groupby=="pool") {
+ var rstore = new Ext.data.Store({
+    model: 'pve-pools'
+ });
+    }
     groupinfo = info;
  } else {
     groupinfo = {
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://pve.proxmox.com/pipermail/pve-devel/attachments/20140707/3f740b9c/attachment-0001.html>


More information about the pve-devel mailing list