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 DE9331FF179 for ; Wed, 12 Nov 2025 10:41:59 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 298BB1C462; Wed, 12 Nov 2025 10:42:47 +0100 (CET) From: Lukas Wagner To: pdm-devel@lists.proxmox.com Date: Wed, 12 Nov 2025 10:41:58 +0100 Message-ID: <20251112094203.112452-3-l.wagner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20251112094203.112452-1-l.wagner@proxmox.com> References: <20251112094203.112452-1-l.wagner@proxmox.com> MIME-Version: 1.0 X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1762940505921 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.029 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 2/7] pbs-client: add bindings for task list, task status, task log 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" Add the necessary bindings for remote task management for PBS remotes. Some of the parameter types / return types should be moved to a shared crate, but this involves some refactoring in PBS, which is not the priority now. The current implementation is just enough to get the remote task fetching and tracking working for PBS remotes. Signed-off-by: Lukas Wagner --- server/Cargo.toml | 1 + server/src/pbs_client.rs | 120 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 119 insertions(+), 2 deletions(-) diff --git a/server/Cargo.toml b/server/Cargo.toml index a215aaf2..b336f1a0 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -27,6 +27,7 @@ openssl.workspace = true percent-encoding.workspace = true serde.workspace = true serde_json.workspace = true +serde_plain.workspace = true syslog.workspace = true tokio = { workspace = true, features = [ "fs", "io-util", "io-std", "macros", "net", "parking_lot", "process", "rt", "rt-multi-thread", "signal", "time" ] } tokio-stream.workspace = true diff --git a/server/src/pbs_client.rs b/server/src/pbs_client.rs index 49087360..4285f402 100644 --- a/server/src/pbs_client.rs +++ b/server/src/pbs_client.rs @@ -6,9 +6,9 @@ use anyhow::bail; // don't import Error as default error in here use http_body_util::BodyExt; -use serde::Deserialize; +use serde::{Deserialize, Serialize}; -use proxmox_client::{ApiPathBuilder, Error, HttpApiClient}; +use proxmox_client::{ApiPathBuilder, ApiResponseData, Error, HttpApiClient}; use proxmox_router::stream::JsonRecords; use proxmox_schema::api; use proxmox_section_config::typed::SectionConfigData; @@ -125,6 +125,75 @@ pub struct AptUpdateParams { pub quiet: Option, } +// TODO: This is incomplete, it only contains the parameters needed for remote task fetching. +// Ideally, the task list API in PBS would use a parameter struct defined in pbs-api-types, which +// is then also used here. +#[derive(Debug, Default, Deserialize, Serialize)] +pub struct ListTasks { + /// Only list this number of tasks. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub limit: Option, + + /// Only list tasks since this UNIX epoch. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub since: Option, +} + +// TODO: The task-status APIs in PBS as well as PDM don't have a +// proper type defined anywhere. This should be moved to a shared crate +// and then the API handlers adapted. +#[derive(Debug, Deserialize, Serialize)] +pub struct TaskStatus { + pub exitstatus: Option, + + pub id: Option, + + pub node: String, + + pub pid: i64, + + pub pstart: i64, + + pub starttime: i64, + + pub status: IsRunning, + + #[serde(rename = "type")] + pub ty: String, + + pub upid: String, + + pub user: String, +} + +#[derive(Debug, Deserialize, Serialize, PartialEq)] +#[serde(rename_all = "kebab-case")] +pub enum IsRunning { + Running, + Stopped, +} + +impl TaskStatus { + /// Checks if the task is currently running. + pub fn is_running(&self) -> bool { + self.status == IsRunning::Running + } +} + +#[api] +// TODO: The task-status APIs in PBS as well as PDM don't have a +// proper type defined anywhere. This should be moved to a shared crate +// and then the API handlers adapted. +/// One line in the task log. +#[derive(Debug, serde::Deserialize, serde::Serialize)] +pub struct TaskLogLine { + /// Line number + pub n: i64, + + /// Line text + pub t: String, +} + impl PbsClient { /// API version details, including some parts of the global datacenter config. pub async fn version(&self) -> Result { @@ -318,6 +387,53 @@ impl PbsClient { Ok(self.0.get(&path).await?.expect_json()?.data) } + + /// Get list of tasks. + /// + /// `params`: Filters specifying which tasks to get. + pub async fn get_task_list( + &self, + params: ListTasks, + ) -> Result, Error> { + let ListTasks { limit, since } = params; + + let url = ApiPathBuilder::new("/api2/extjs/nodes/localhost/tasks".to_string()) + .maybe_arg("limit", &limit) + .maybe_arg("since", &since) + .build(); + + Ok(self.0.get(&url).await?.expect_json()?.data) + } + + /// Read task log. + pub async fn get_task_log( + &self, + upid: &str, + download: Option, + limit: Option, + start: Option, + ) -> Result>, Error> { + let url = ApiPathBuilder::new(format!("/api2/extjs/nodes/localhost/tasks/{upid}/log")) + .maybe_bool_arg("download", download) + .maybe_arg("limit", &limit) + .maybe_arg("start", &start) + .build(); + + self.0.get(&url).await?.expect_json() + } + + /// Read task status. + pub async fn get_task_status(&self, upid: &str) -> Result { + let url = format!("/api2/extjs/nodes/localhost/tasks/{upid}/status"); + let response = self.0.get(&url).await?; + Ok(response.expect_json()?.data) + } + + /// Stop a task. + pub async fn stop_task(&self, upid: &str) -> Result<(), Error> { + let url = format!("/api2/extjs/nodes/localhost/tasks/{upid}"); + self.0.delete(&url).await?.nodata() + } } #[derive(Deserialize)] -- 2.47.3 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel