From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [PATCH datacenter-manager 2/7] pbs-client: add bindings for task list, task status, task log
Date: Wed, 12 Nov 2025 10:41:58 +0100 [thread overview]
Message-ID: <20251112094203.112452-3-l.wagner@proxmox.com> (raw)
In-Reply-To: <20251112094203.112452-1-l.wagner@proxmox.com>
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 <l.wagner@proxmox.com>
---
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<bool>,
}
+// 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<u64>,
+
+ /// Only list tasks since this UNIX epoch.
+ #[serde(default, skip_serializing_if = "Option::is_none")]
+ pub since: Option<i64>,
+}
+
+// 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<String>,
+
+ pub id: Option<String>,
+
+ 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<pve_api_types::VersionResponse, Error> {
@@ -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<Vec<pbs_api_types::TaskListItem>, 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<bool>,
+ limit: Option<u64>,
+ start: Option<u64>,
+ ) -> Result<ApiResponseData<Vec<TaskLogLine>>, 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<TaskStatus, Error> {
+ 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
next prev parent reply other threads:[~2025-11-12 9:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-12 9:41 [pdm-devel] [PATCH datacenter-manager 0/7] PBS remotes: task API and task cache support Lukas Wagner
2025-11-12 9:41 ` [pdm-devel] [PATCH datacenter-manager 1/7] pdm-api-types: remote upid: add helpers for getting native UPID type Lukas Wagner
2025-11-12 9:41 ` Lukas Wagner [this message]
2025-11-12 20:23 ` [pdm-devel] [PATCH datacenter-manager 2/7] pbs-client: add bindings for task list, task status, task log Thomas Lamprecht
2025-11-12 9:41 ` [pdm-devel] [PATCH datacenter-manager 3/7] pdm-api-types: api: factor out schema definitions for task log params Lukas Wagner
2025-11-12 9:42 ` [pdm-devel] [PATCH datacenter-manager 4/7] api: pbs tasks: add PBS task API Lukas Wagner
2025-11-12 9:42 ` [pdm-devel] [PATCH datacenter-manager 5/7] api: pve tasks: use shared helpers for RemoteUpid handling Lukas Wagner
2025-11-12 9:42 ` [pdm-devel] [PATCH datacenter-manager 6/7] remote tasks: fetch/track PBS tasks Lukas Wagner
2025-11-12 9:42 ` [pdm-devel] [PATCH datacenter-manager 7/7] remote updates: re-enable PBS update fetching Lukas Wagner
2025-11-12 20:26 ` Thomas Lamprecht
2025-11-12 20:27 ` [pdm-devel] applied-series: [PATCH datacenter-manager 0/7] PBS remotes: task API and task cache support Thomas Lamprecht
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251112094203.112452-3-l.wagner@proxmox.com \
--to=l.wagner@proxmox.com \
--cc=pdm-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.