which uses the efficient PVE::Cluster::get_guest_config_properties() to retrieve the information and supports caching, so the information can be passed around avoiding overhead from load_config().
Signed-off-by: Fiona Ebner <f.eb...@proxmox.com> --- src/PVE/HA/Env.pm | 6 ++++++ src/PVE/HA/Env/PVE2.pm | 15 +++++++++++++++ src/PVE/HA/Sim/Env.pm | 7 +++++++ 3 files changed, 28 insertions(+) diff --git a/src/PVE/HA/Env.pm b/src/PVE/HA/Env.pm index 16603ec..2b422eb 100644 --- a/src/PVE/HA/Env.pm +++ b/src/PVE/HA/Env.pm @@ -275,4 +275,10 @@ sub get_static_node_stats { return $self->{plug}->get_static_node_stats(); } +sub get_static_guest_stats { + my ($self, $cached) = @_; + + return $self->{plug}->get_static_guest_stats($cached); +} + 1; diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm index f6ebfeb..02b981e 100644 --- a/src/PVE/HA/Env/PVE2.pm +++ b/src/PVE/HA/Env/PVE2.pm @@ -476,4 +476,19 @@ sub get_static_node_stats { return $stats; } +sub get_static_guest_stats { + my ($self, $cached) = @_; + + return $self->{'static-guest-stats'} if $self->{'static-guest-stats'} && $cached; + + # NOTE see get_static_stats in Resources/*.pm for what properties are required. + my $properties = ['cores', 'cpulimit', 'memory', 'sockets', 'vcpus']; + my $stats = eval { PVE::Cluster::get_guest_config_properties($properties); }; + $self->log('warning', "unable to initialize cache for static service stats - $@") if $@; + + $self->{'static-guest-stats'} = $stats; + + return $stats // {}; +} + 1; diff --git a/src/PVE/HA/Sim/Env.pm b/src/PVE/HA/Sim/Env.pm index c6ea73c..51690f5 100644 --- a/src/PVE/HA/Sim/Env.pm +++ b/src/PVE/HA/Sim/Env.pm @@ -442,4 +442,11 @@ sub get_static_node_stats { return $self->{hardware}->get_static_node_stats(); } +# FIXME actually return the stats here +sub get_static_guest_stats { + my ($self, $cached) = @_; + + return {}; +} + 1; -- 2.30.2 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel