Signed-off-by: Daniel Kral <[email protected]>
---
In general, in a v2 or later series this could be generalized for the
static and (upcoming) dynamic use case and moved to
proxmox-resource-scheduling as well to make the perlmod bindings as thin
as possible (to allow flexibility in the internals and not introduce
unnecessary build breaks).
.../bindings/resource_scheduling_static.rs | 41 +++++++++++--------
1 file changed, 24 insertions(+), 17 deletions(-)
diff --git a/pve-rs/src/bindings/resource_scheduling_static.rs
b/pve-rs/src/bindings/resource_scheduling_static.rs
index 5b91d36..a51b8a2 100644
--- a/pve-rs/src/bindings/resource_scheduling_static.rs
+++ b/pve-rs/src/bindings/resource_scheduling_static.rs
@@ -13,6 +13,7 @@ pub mod pve_rs_resource_scheduling_static {
use perlmod::Value;
use proxmox_resource_scheduling::pve_static::{StaticNodeUsage,
StaticServiceUsage};
+ use proxmox_resource_scheduling::scheduler::ClusterUsage;
perlmod::declare_magic!(Box<Scheduler> : &Scheduler as
"PVE::RS::ResourceScheduling::Static");
@@ -175,21 +176,7 @@ pub mod pve_rs_resource_scheduling_static {
Ok(())
}
- /// Scores all previously added nodes for starting a `service` on.
- ///
- /// Scoring is done according to the static memory and CPU usages of the
nodes as if the
- /// service would already be running on each.
- ///
- /// Returns a vector of (nodename, score) pairs. Scores are between 0.0
and 1.0 and a higher
- /// score is better.
- ///
- /// See
[`proxmox_resource_scheduling::pve_static::score_nodes_to_start_service`].
- #[export]
- pub fn score_nodes_to_start_service(
- #[try_from_ref] this: &Scheduler,
- service: StaticServiceUsage,
- ) -> Result<Vec<(String, f64)>, Error> {
- let usage = this.inner.lock().unwrap();
+ fn as_cluster_usage(usage: &Usage) -> ClusterUsage {
let nodes = usage
.nodes
.values()
@@ -208,8 +195,28 @@ pub mod pve_rs_resource_scheduling_static {
node_usage
})
- .collect::<Vec<StaticNodeUsage>>();
+ .collect::<Vec<_>>();
-
proxmox_resource_scheduling::pve_static::score_nodes_to_start_service(&nodes,
&service)
+ ClusterUsage::from_nodes(nodes)
+ }
+
+ /// Scores all previously added nodes for starting a `service` on.
+ ///
+ /// Scoring is done according to the static memory and CPU usages of the
nodes as if the
+ /// service would already be running on each.
+ ///
+ /// Returns a vector of (nodename, score) pairs. Scores are between 0.0
and 1.0 and a higher
+ /// score is better.
+ ///
+ /// See
[`proxmox_resource_scheduling::pve_static::score_nodes_to_start_service`].
+ #[export]
+ pub fn score_nodes_to_start_service(
+ #[try_from_ref] this: &Scheduler,
+ service: StaticServiceUsage,
+ ) -> Result<Vec<(String, f64)>, Error> {
+ let usage = this.inner.lock().unwrap();
+ let cluster_usage = as_cluster_usage(&usage);
+
+ cluster_usage.score_nodes_to_start_service(service)
}
}
--
2.47.3