[pve-devel] [PATCH ha-manager 1/1] resources: pve: avoid relying on internal configuration details

Fiona Ebner f.ebner at proxmox.com
Tue Feb 28 11:54:10 CET 2023


Instead, use the new get_derived_property() method to get the same
information in a way that is robust regarding changes in the
configuration structure.

Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
 src/PVE/HA/Resources/PVECT.pm | 4 ++--
 src/PVE/HA/Resources/PVEVM.pm | 7 ++-----
 2 files changed, 4 insertions(+), 7 deletions(-)

diff --git a/src/PVE/HA/Resources/PVECT.pm b/src/PVE/HA/Resources/PVECT.pm
index e77d98c..6e14692 100644
--- a/src/PVE/HA/Resources/PVECT.pm
+++ b/src/PVE/HA/Resources/PVECT.pm
@@ -158,8 +158,8 @@ sub get_static_stats {
     my $conf = PVE::LXC::Config->load_config($id, $service_node);
 
     return {
-	maxcpu => $conf->{cpulimit} || $conf->{cores} || 0,
-	maxmem => ($conf->{memory} || 512) * 1024 * 1024,
+	maxcpu => PVE::LXC::Config->get_derived_property($conf, 'max-cpu'),
+	maxmem => PVE::LXC::Config->get_derived_property($conf, 'max-memory'),
     };
 }
 
diff --git a/src/PVE/HA/Resources/PVEVM.pm b/src/PVE/HA/Resources/PVEVM.pm
index f405d86..1543a2d 100644
--- a/src/PVE/HA/Resources/PVEVM.pm
+++ b/src/PVE/HA/Resources/PVEVM.pm
@@ -179,13 +179,10 @@ sub get_static_stats {
     my ($class, $haenv, $id, $service_node) = @_;
 
     my $conf = PVE::QemuConfig->load_config($id, $service_node);
-    my $defaults = PVE::QemuServer::load_defaults();
-
-    my $cpus = ($conf->{sockets} || $defaults->{sockets}) * ($conf->{cores} || $defaults->{cores});
 
     return {
-	maxcpu => $conf->{vcpus} || $cpus,
-	maxmem => ($conf->{memory} || $defaults->{memory}) * 1024 * 1024,
+	maxcpu => PVE::QemuConfig->get_derived_property($conf, 'max-cpu'),
+	maxmem => PVE::QemuConfig->get_derived_property($conf, 'max-memory'),
     };
 }
 
-- 
2.30.2






More information about the pve-devel mailing list