[PATCH perl-rs v3 14/40] pve-rs: resource-scheduling: static: replace deprecated usage structs

Daniel Kral
2026-03-30T14:41:11Z

The StaticServiceUsage is marked as deprecated in
proxmox-resource-scheduling now to make the crate independent of the
specific usage structs and the deserialization of these.

Therefore, define the same struct in the pve_static bindings module.

Though this is technically a Rust API break, the Perl bindings do not
have the concept of structs, which are serialized as Perl hashes.

Signed-off-by: Daniel Kral <d.kral@proxmox.com>
Reviewed-by: Dominik Rusovac <d.rusovac@proxmox.com>
---
changes v2 -> v3:
- none

.../resource_scheduling/pve_static.rs | 32 ++++++++++++++++---
1 file changed, 27 insertions(+), 5 deletions(-)

diff --git a/pve-rs/src/bindings/resource_scheduling/pve_static.rs b/pve-rs/src/bindings/resource_scheduling/pve_static.rs
index 5353db9..678fccb 100644
--- a/pve-rs/src/bindings/resource_scheduling/pve_static.rs
+++ b/pve-rs/src/bindings/resource_scheduling/pve_static.rs
@@ -9,10 +9,11 @@ pub mod pve_rs_resource_scheduling_static {
use std::sync::Mutex;

use anyhow::Error;
+ use serde::{Deserialize, Serialize};

use perlmod::Value;
use proxmox_resource_scheduling::node::NodeStats;
- use proxmox_resource_scheduling::pve_static::StaticServiceUsage;
+ use proxmox_resource_scheduling::resource::ResourceStats;
use proxmox_resource_scheduling::usage::Usage;

use crate::bindings::resource_scheduling::{
@@ -26,7 +27,28 @@ pub mod pve_rs_resource_scheduling_static {
inner: Mutex<Usage>,
}

- type StaticResource = PveResource<StaticServiceUsage>;
+ #[derive(Clone, Copy, Debug, Serialize, Deserialize)]
+ #[serde(rename_all = "kebab-case")]
+ /// Static usage stats of a resource.
+ pub struct StaticResourceStats {
+ /// Number of assigned CPUs or CPU limit.
+ pub maxcpu: f64,
+ /// Maximum assigned memory in bytes.
+ pub maxmem: usize,
+ }
+
+ impl From<StaticResourceStats> for ResourceStats {
+ fn from(stats: StaticResourceStats) -> Self {
+ Self {
+ cpu: stats.maxcpu,
+ maxcpu: stats.maxcpu,
+ mem: stats.maxmem,
+ maxmem: stats.maxmem,
+ }
+ }
+ }
+
+ type StaticResource = PveResource<StaticResourceStats>;

/// Class method: Create a new [`Scheduler`] instance.
///
@@ -113,13 +135,13 @@ pub mod pve_rs_resource_scheduling_static {
#[try_from_ref] this: &Scheduler,
nodename: &str,
sid: &str,
- service_usage: StaticServiceUsage,
+ service_stats: StaticResourceStats,
) -> Result<(), Error> {
let mut usage = this.inner.lock().unwrap();

// TODO Only for backwards compatibility, can be removed with a proper version bump
#[allow(deprecated)]
- usage.add_resource_usage_to_node(nodename, sid, service_usage.into())
+ usage.add_resource_usage_to_node(nodename, sid, service_stats.into())
}

/// Method: Remove service `sid` and its usage from all assigned nodes.
@@ -138,7 +160,7 @@ pub mod pve_rs_resource_scheduling_static {
#[export]
pub fn score_nodes_to_start_service(
#[try_from_ref] this: &Scheduler,
- service_stats: StaticServiceUsage,
+ service_stats: StaticResourceStats,
) -> Result<Vec<(String, f64)>, Error> {
let usage = this.inner.lock().unwrap();

--
2.47.3