[pdm-devel] [PATCH datacenter-manager 3/7] pdm-api-types: api: factor out schema definitions for task log params

Lukas Wagner l.wagner at proxmox.com
Wed Nov 12 10:41:59 CET 2025


The PBS tasks API will also need them, so it makes sense to move them to
a shared crate now.

Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
 lib/pdm-api-types/src/lib.rs  | 21 +++++++++++++++++++++
 server/src/api/nodes/tasks.rs | 30 +++++-------------------------
 server/src/api/pve/tasks.rs   | 35 ++++++++---------------------------
 3 files changed, 34 insertions(+), 52 deletions(-)

diff --git a/lib/pdm-api-types/src/lib.rs b/lib/pdm-api-types/src/lib.rs
index ad52372e..5ac99aa1 100644
--- a/lib/pdm-api-types/src/lib.rs
+++ b/lib/pdm-api-types/src/lib.rs
@@ -494,3 +494,24 @@ pub struct TaskFilters {
     #[serde(skip_serializing_if = "Option::is_none")]
     pub statusfilter: Option<Vec<TaskStateType>>,
 }
+
+pub const TASKLOG_START_PARAM_SCHEMA: Schema =
+    proxmox_schema::IntegerSchema::new("Start at this line when reading the tasklog")
+        .minimum(0)
+        .default(0)
+        .schema();
+
+pub const TASKLOG_LIMIT_PARAM_SCHEMA: Schema = proxmox_schema::IntegerSchema::new(
+    "The amount of lines to read from the tasklog. \
+         Setting this parameter to 0 will return all lines until the end of the file.",
+)
+.minimum(0)
+.default(50)
+.schema();
+
+pub const TASKLOG_DOWNLOAD_PARAM_SCHEMA: Schema = proxmox_schema::BooleanSchema::new(
+    "Whether the tasklog file should be downloaded. \
+        This parameter can't be used in conjunction with other parameters",
+)
+.default(false)
+.schema();
diff --git a/server/src/api/nodes/tasks.rs b/server/src/api/nodes/tasks.rs
index 2ab1284f..9725f022 100644
--- a/server/src/api/nodes/tasks.rs
+++ b/server/src/api/nodes/tasks.rs
@@ -13,7 +13,8 @@ use proxmox_sortable_macro::sortable;
 
 use pdm_api_types::{
     Authid, TaskFilters, TaskListItem, TaskStateType, Tokenname, Userid, NODE_SCHEMA,
-    PRIV_SYS_AUDIT, PRIV_SYS_MODIFY, UPID, UPID_SCHEMA,
+    PRIV_SYS_AUDIT, PRIV_SYS_MODIFY, TASKLOG_DOWNLOAD_PARAM_SCHEMA, TASKLOG_LIMIT_PARAM_SCHEMA,
+    TASKLOG_START_PARAM_SCHEMA, UPID, UPID_SCHEMA,
 };
 
 pub const ROUTER: Router = Router::new()
@@ -305,27 +306,6 @@ async fn get_task_status(upid: UPID, rpcenv: &mut dyn RpcEnvironment) -> Result<
     Ok(result)
 }
 
-const START_PARAM_SCHEMA: Schema =
-    proxmox_schema::IntegerSchema::new("Start at this line when reading the tasklog")
-        .minimum(0)
-        .default(0)
-        .schema();
-
-const LIMIT_PARAM_SCHEMA: Schema = proxmox_schema::IntegerSchema::new(
-    "The amount of lines to read from the tasklog. \
-         Setting this parameter to 0 will return all lines until the end of the file.",
-)
-.minimum(0)
-.default(50)
-.schema();
-
-const DOWNLOAD_PARAM_SCHEMA: Schema = proxmox_schema::BooleanSchema::new(
-    "Whether the tasklog file should be downloaded. \
-        This parameter can't be used in conjunction with other parameters",
-)
-.default(false)
-.schema();
-
 const TEST_STATUS_PARAM_SCHEMA: Schema = proxmox_schema::BooleanSchema::new(
     "Test task status, and set result attribute \"active\" accordingly.",
 )
@@ -339,9 +319,9 @@ pub const API_METHOD_READ_TASK_LOG: proxmox_router::ApiMethod = proxmox_router::
         &sorted!([
             ("node", false, &NODE_SCHEMA),
             ("upid", false, &UPID_SCHEMA),
-            ("start", true, &START_PARAM_SCHEMA),
-            ("limit", true, &LIMIT_PARAM_SCHEMA),
-            ("download", true, &DOWNLOAD_PARAM_SCHEMA),
+            ("start", true, &TASKLOG_START_PARAM_SCHEMA),
+            ("limit", true, &TASKLOG_LIMIT_PARAM_SCHEMA),
+            ("download", true, &TASKLOG_DOWNLOAD_PARAM_SCHEMA),
             ("test-status", true, &TEST_STATUS_PARAM_SCHEMA)
         ]),
     ),
diff --git a/server/src/api/pve/tasks.rs b/server/src/api/pve/tasks.rs
index 9f04a448..e66712ac 100644
--- a/server/src/api/pve/tasks.rs
+++ b/server/src/api/pve/tasks.rs
@@ -3,11 +3,14 @@
 use anyhow::{bail, format_err, Error};
 
 use proxmox_router::{list_subdirs_api_method, Permission, Router, RpcEnvironment, SubdirMap};
-use proxmox_schema::{api, Schema};
+use proxmox_schema::api;
 use proxmox_sortable_macro::sortable;
 
 use pdm_api_types::remotes::REMOTE_ID_SCHEMA;
-use pdm_api_types::{RemoteUpid, NODE_SCHEMA, PRIV_RESOURCE_AUDIT, PRIV_RESOURCE_MANAGE};
+use pdm_api_types::{
+    RemoteUpid, NODE_SCHEMA, PRIV_RESOURCE_AUDIT, PRIV_RESOURCE_MANAGE,
+    TASKLOG_DOWNLOAD_PARAM_SCHEMA, TASKLOG_LIMIT_PARAM_SCHEMA, TASKLOG_START_PARAM_SCHEMA,
+};
 use pve_api_types::PveUpid;
 
 use super::{connect, connect_to_remote, get_remote};
@@ -149,28 +152,6 @@ pub async fn get_task_status(
     }
 }
 
-// FIXME: Deduplicate these into pdm_api_types:
-const START_PARAM_SCHEMA: Schema =
-    proxmox_schema::IntegerSchema::new("Start at this line when reading the tasklog")
-        .minimum(0)
-        .default(0)
-        .schema();
-
-const LIMIT_PARAM_SCHEMA: Schema = proxmox_schema::IntegerSchema::new(
-    "The amount of lines to read from the tasklog. \
-         Setting this parameter to 0 will return all lines until the end of the file.",
-)
-.minimum(0)
-.default(50)
-.schema();
-
-const DOWNLOAD_PARAM_SCHEMA: Schema = proxmox_schema::BooleanSchema::new(
-    "Whether the tasklog file should be downloaded. \
-        This parameter can't be used in conjunction with other parameters",
-)
-.default(false)
-.schema();
-
 // FIXME: make *actually* streaming with router support!
 #[api(
     input: {
@@ -178,15 +159,15 @@ const DOWNLOAD_PARAM_SCHEMA: Schema = proxmox_schema::BooleanSchema::new(
             remote: { schema: REMOTE_ID_SCHEMA },
             upid: { type: RemoteUpid },
             start: {
-                schema: START_PARAM_SCHEMA,
+                schema: TASKLOG_START_PARAM_SCHEMA,
                 optional: true,
             },
             limit: {
-                schema: LIMIT_PARAM_SCHEMA,
+                schema: TASKLOG_LIMIT_PARAM_SCHEMA,
                 optional: true,
             },
             download: {
-                schema: DOWNLOAD_PARAM_SCHEMA,
+                schema: TASKLOG_DOWNLOAD_PARAM_SCHEMA,
                 optional: true,
             }
         },
-- 
2.47.3





More information about the pdm-devel mailing list