]> git.proxmox.com Git - pve-manager-legacy.git/commitdiff
fix undefined value warning in resources api call
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Tue, 5 Jul 2016 12:45:35 +0000 (14:45 +0200)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Thu, 7 Jul 2016 06:15:15 +0000 (08:15 +0200)
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

index aeba9342ec1c47b79ed5b21f3ea785ac367656cf..331e2f75ab9f1d1efc1bdc1a6d8182c2006953a8 100644 (file)
@@ -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};
                        }
                    }