[pdm-devel] [PATCH datacenter-manager 4/7] server: api: pve: add nodes/storage api for status and rrddata

Dominik Csapak d.csapak at proxmox.com
Mon Sep 8 16:04:15 CEST 2025


just tunnels through the pve api

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 server/src/api/pve/mod.rs     |  1 +
 server/src/api/pve/node.rs    |  8 +++++-
 server/src/api/pve/storage.rs | 46 +++++++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 1 deletion(-)
 create mode 100644 server/src/api/pve/storage.rs

diff --git a/server/src/api/pve/mod.rs b/server/src/api/pve/mod.rs
index 0768083..edafdde 100644
--- a/server/src/api/pve/mod.rs
+++ b/server/src/api/pve/mod.rs
@@ -36,6 +36,7 @@ mod lxc;
 mod node;
 mod qemu;
 mod rrddata;
+mod storage;
 pub mod tasks;
 
 pub const ROUTER: Router = Router::new()
diff --git a/server/src/api/pve/node.rs b/server/src/api/pve/node.rs
index 99539d1..1924e25 100644
--- a/server/src/api/pve/node.rs
+++ b/server/src/api/pve/node.rs
@@ -7,6 +7,8 @@ use proxmox_sortable_macro::sortable;
 use pdm_api_types::{remotes::REMOTE_ID_SCHEMA, NODE_SCHEMA, PRIV_RESOURCE_AUDIT};
 use pve_api_types::StorageContent;
 
+use crate::api::pve::storage;
+
 pub const ROUTER: Router = Router::new()
     .get(&list_subdirs_api_method!(SUBDIRS))
     .subdirs(SUBDIRS);
@@ -16,10 +18,14 @@ const SUBDIRS: SubdirMap = &sorted!([
     ("apt", &super::apt::ROUTER),
     ("rrddata", &super::rrddata::NODE_RRD_ROUTER),
     ("network", &Router::new().get(&API_METHOD_GET_NETWORK)),
-    ("storage", &Router::new().get(&API_METHOD_GET_STORAGES)),
+    ("storage", &STORAGE_ROUTER),
     ("status", &Router::new().get(&API_METHOD_GET_STATUS)),
 ]);
 
+const STORAGE_ROUTER: Router = Router::new()
+    .get(&API_METHOD_GET_STORAGES)
+    .match_all("storage", &storage::ROUTER);
+
 #[api(
     input: {
         properties: {
diff --git a/server/src/api/pve/storage.rs b/server/src/api/pve/storage.rs
new file mode 100644
index 0000000..e337d06
--- /dev/null
+++ b/server/src/api/pve/storage.rs
@@ -0,0 +1,46 @@
+use anyhow::Error;
+
+use proxmox_router::{list_subdirs_api_method, Permission, Router, SubdirMap};
+use proxmox_schema::api;
+use proxmox_sortable_macro::sortable;
+
+use pdm_api_types::remotes::REMOTE_ID_SCHEMA;
+use pdm_api_types::{NODE_SCHEMA, PRIV_RESOURCE_AUDIT, PVE_STORAGE_ID_SCHEMA};
+
+use super::connect_to_remote;
+
+pub const ROUTER: Router = Router::new()
+    .get(&list_subdirs_api_method!(STORAGE_SUBDIR))
+    .subdirs(STORAGE_SUBDIR);
+#[sortable]
+const STORAGE_SUBDIR: SubdirMap = &sorted!([
+    ("rrddata", &super::rrddata::STORAGE_RRD_ROUTER),
+    ("status", &Router::new().get(&API_METHOD_GET_STATUS)),
+]);
+
+#[api(
+    input: {
+        properties: {
+            remote: { schema: REMOTE_ID_SCHEMA },
+            node: { schema: NODE_SCHEMA, },
+            storage: { schema: PVE_STORAGE_ID_SCHEMA, },
+        },
+    },
+    returns: { type: pve_api_types::QemuStatus },
+    access: {
+        permission: &Permission::Privilege(&["resource", "{remote}", "storage", "{storage}"], PRIV_RESOURCE_AUDIT, false),
+    },
+)]
+/// Get the status of a qemu VM from a remote. If a node is provided, the VM must be on that
+/// node, otherwise the node is determined automatically.
+pub async fn get_status(
+    remote: String,
+    node: String,
+    storage: String,
+) -> Result<pve_api_types::StorageStatus, Error> {
+    let (remotes, _) = pdm_config::remotes::config()?;
+
+    let pve = connect_to_remote(&remotes, &remote)?;
+
+    Ok(pve.storage_status(&node, &storage).await?)
+}
-- 
2.47.2





More information about the pdm-devel mailing list