With the new calculation $pe->{maxcpu} was used before being
initialized to zero. Moving the initialization up.
Additionally setting $pe->{cpu} to $entry->{cpu} if maxcpu
is not set seems pointless as with its factor (maxcpu)
initialized to zero it is cancelled out anyway.
---
PVE/API2/Cluster.pm | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/PVE/API2/Cluster.pm b/PVE/API2/Cluster.pm
index aeba934..331e2f7 100644
--- a/PVE/API2/Cluster.pm
+++ b/PVE/API2/Cluster.pm
@@ -203,14 +203,13 @@ __PACKAGE__->register_method({
$pe->{maxmem} = 0 if !$pe->{maxmem};
$pe->{maxmem} += $entry->{maxmem};
$pe->{cpu} = 0 if !$pe->{cpu};
+ $pe->{maxcpu} = 0 if !$pe->{maxcpu};
# explanation:
# we do not know how much cpus there are in the
cluster at this moment
# so we calculate the current % of the cpu
# but we had already the old cpu % before this vm,
so:
# new% = (old%*oldmax + cur%*curmax) /
(oldmax+curmax)
- $pe->{cpu} = $entry->{cpu} if !$pe->{maxcpu};
$pe->{cpu} = (($pe->{cpu} * $pe->{maxcpu}) +
($entry->{cpu} * $entry->{maxcpu})) / ($pe->{maxcpu} + $entry->{maxcpu});
- $pe->{maxcpu} = 0 if !$pe->{maxcpu};
$pe->{maxcpu} += $entry->{maxcpu};
}
}
--
2.1.4
_______________________________________________
pve-devel mailing list
[email protected]
http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel