From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 081021FF187 for ; Mon, 8 Sep 2025 16:04:41 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id ABCD4139E9; Mon, 8 Sep 2025 16:04:43 +0200 (CEST) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Date: Mon, 8 Sep 2025 16:04:15 +0200 Message-ID: <20250908140424.3376082-9-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.2 In-Reply-To: <20250908140424.3376082-1-d.csapak@proxmox.com> References: <20250908140424.3376082-1-d.csapak@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.023 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pdm-devel] [PATCH datacenter-manager 4/7] server: api: pve: add nodes/storage api for status and rrddata X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" just tunnels through the pve api Signed-off-by: Dominik Csapak --- 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 { + let (remotes, _) = pdm_config::remotes::config()?; + + let pve = connect_to_remote(&remotes, &remote)?; + + Ok(pve.storage_status(&node, &storage).await?) +} -- 2.47.2 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel