mirror of
https://git.proxmox.com/git/pve-manager
synced 2025-08-06 04:36:29 +00:00
fix undefined value warning in resources api call
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.
This commit is contained in:
parent
6897aeb307
commit
c37f23f53b
@ -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};
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user