[pdm-devel] [PATCH proxmox-datacenter-manager 10/12] api: add APT endpoints for PBS remotes

Lukas Wagner l.wagner at proxmox.com
Wed Oct 15 14:47:09 CEST 2025


Since the endpoints are exactly identical as the PVE ones, we move the
implementation to a shared module and use the same for both.

Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
 server/src/api/pbs/mod.rs        |   4 ++
 server/src/api/pbs/node.rs       |   9 +++
 server/src/api/pve/apt.rs        | 119 -------------------------------
 server/src/api/pve/mod.rs        |   1 -
 server/src/api/pve/node.rs       |   2 +-
 server/src/api/remote_updates.rs | 118 +++++++++++++++++++++++++++++-
 6 files changed, 130 insertions(+), 123 deletions(-)
 create mode 100644 server/src/api/pbs/node.rs
 delete mode 100644 server/src/api/pve/apt.rs

diff --git a/server/src/api/pbs/mod.rs b/server/src/api/pbs/mod.rs
index b3bb126c..43bd1a28 100644
--- a/server/src/api/pbs/mod.rs
+++ b/server/src/api/pbs/mod.rs
@@ -20,6 +20,7 @@ use crate::{
 
 use crate::remote_tasks;
 
+mod node;
 mod rrddata;
 
 pub const ROUTER: Router = Router::new()
@@ -41,8 +42,11 @@ pub const MAIN_ROUTER: Router = Router::new()
     .get(&list_subdirs_api_method!(REMOTE_SUBDIRS))
     .subdirs(REMOTE_SUBDIRS);
 
+const NODES_ROUTER: Router = Router::new().match_all("node", &node::ROUTER);
+
 #[sortable]
 const REMOTE_SUBDIRS: SubdirMap = &sorted!([
+    ("nodes", &NODES_ROUTER),
     ("status", &Router::new().get(&API_METHOD_GET_STATUS)),
     ("rrddata", &rrddata::PBS_NODE_RRD_ROUTER),
     ("datastore", &DATASTORE_ROUTER)
diff --git a/server/src/api/pbs/node.rs b/server/src/api/pbs/node.rs
new file mode 100644
index 00000000..286e1a11
--- /dev/null
+++ b/server/src/api/pbs/node.rs
@@ -0,0 +1,9 @@
+use proxmox_router::{list_subdirs_api_method, Router, SubdirMap};
+use proxmox_sortable_macro::sortable;
+
+pub const ROUTER: Router = Router::new()
+    .get(&list_subdirs_api_method!(SUBDIRS))
+    .subdirs(SUBDIRS);
+
+#[sortable]
+const SUBDIRS: SubdirMap = &sorted!([("apt", &crate::api::remote_updates::APT_ROUTER),]);
diff --git a/server/src/api/pve/apt.rs b/server/src/api/pve/apt.rs
deleted file mode 100644
index f5027fb8..00000000
--- a/server/src/api/pve/apt.rs
+++ /dev/null
@@ -1,119 +0,0 @@
-use anyhow::Error;
-
-use proxmox_apt_api_types::{APTGetChangelogOptions, APTUpdateInfo};
-use proxmox_router::{list_subdirs_api_method, Permission, Router, SubdirMap};
-use proxmox_schema::api;
-use proxmox_schema::api_types::NODE_SCHEMA;
-
-use pdm_api_types::{remotes::REMOTE_ID_SCHEMA, RemoteUpid, PRIV_RESOURCE_MODIFY};
-
-use crate::{api::remotes::get_remote, remote_updates};
-
-#[api(
-    input: {
-        properties: {
-            remote: {
-                schema: REMOTE_ID_SCHEMA,
-            },
-            node: {
-                schema: NODE_SCHEMA,
-            },
-        },
-    },
-    returns: {
-        description: "A list of packages with available updates.",
-        type: Array,
-        items: {
-            type: APTUpdateInfo
-        },
-    },
-    access: {
-        permission: &Permission::Privilege(&["resource", "{remote}", "node", "{node}", "system"], PRIV_RESOURCE_MODIFY, false),
-    },
-)]
-/// List available APT updates for a remote PVE node.
-async fn apt_update_available(remote: String, node: String) -> Result<Vec<APTUpdateInfo>, Error> {
-    let (config, _digest) = pdm_config::remotes::config()?;
-    let remote = get_remote(&config, &remote)?;
-
-    let updates = remote_updates::list_available_updates(remote.clone(), &node).await?;
-
-    Ok(updates)
-}
-
-#[api(
-    input: {
-        properties: {
-            remote: {
-                schema: REMOTE_ID_SCHEMA,
-            },
-            node: {
-                schema: NODE_SCHEMA,
-            },
-        },
-    },
-    access: {
-        permission: &Permission::Privilege(&["resource", "{remote}", "node", "{node}", "system"], PRIV_RESOURCE_MODIFY, false),
-    },
-)]
-/// Update the APT database of a remote PVE node.
-pub async fn apt_update_database(remote: String, node: String) -> Result<RemoteUpid, Error> {
-    let (config, _digest) = pdm_config::remotes::config()?;
-    let remote = get_remote(&config, &remote)?;
-
-    let upid = remote_updates::update_apt_database(remote, &node).await?;
-
-    Ok(upid)
-}
-
-#[api(
-    input: {
-        properties: {
-            remote: {
-                schema: REMOTE_ID_SCHEMA,
-            },
-            node: {
-                schema: NODE_SCHEMA,
-            },
-            options: {
-                type: APTGetChangelogOptions,
-                flatten: true,
-            },
-        },
-    },
-    returns: {
-        description: "The Package changelog.",
-        type: String,
-    },
-    access: {
-        permission: &Permission::Privilege(&["resource", "{remote}", "node", "{node}", "system"], PRIV_RESOURCE_MODIFY, false),
-    },
-)]
-/// Retrieve the changelog of the specified package for a remote PVE node.
-async fn apt_get_changelog(
-    remote: String,
-    node: String,
-    options: APTGetChangelogOptions,
-) -> Result<String, Error> {
-    let (config, _digest) = pdm_config::remotes::config()?;
-    let remote = get_remote(&config, &remote)?;
-
-    remote_updates::get_changelog(remote.clone(), &node, options.name).await
-}
-
-const SUBDIRS: SubdirMap = &[
-    (
-        "changelog",
-        &Router::new().get(&API_METHOD_APT_GET_CHANGELOG),
-    ),
-    (
-        "update",
-        &Router::new()
-            .get(&API_METHOD_APT_UPDATE_AVAILABLE)
-            .post(&API_METHOD_APT_UPDATE_DATABASE),
-    ),
-];
-
-pub const ROUTER: Router = Router::new()
-    .get(&list_subdirs_api_method!(SUBDIRS))
-    .subdirs(SUBDIRS);
diff --git a/server/src/api/pve/mod.rs b/server/src/api/pve/mod.rs
index a94ab8d0..fd4ea542 100644
--- a/server/src/api/pve/mod.rs
+++ b/server/src/api/pve/mod.rs
@@ -33,7 +33,6 @@ use crate::connection::PveClient;
 use crate::connection::{self, probe_tls_connection};
 use crate::remote_tasks;
 
-mod apt;
 mod lxc;
 mod node;
 mod qemu;
diff --git a/server/src/api/pve/node.rs b/server/src/api/pve/node.rs
index 1924e252..301c0b19 100644
--- a/server/src/api/pve/node.rs
+++ b/server/src/api/pve/node.rs
@@ -15,7 +15,7 @@ pub const ROUTER: Router = Router::new()
 
 #[sortable]
 const SUBDIRS: SubdirMap = &sorted!([
-    ("apt", &super::apt::ROUTER),
+    ("apt", &crate::api::remote_updates::APT_ROUTER),
     ("rrddata", &super::rrddata::NODE_RRD_ROUTER),
     ("network", &Router::new().get(&API_METHOD_GET_NETWORK)),
     ("storage", &STORAGE_ROUTER),
diff --git a/server/src/api/remote_updates.rs b/server/src/api/remote_updates.rs
index 724b705a..5907259f 100644
--- a/server/src/api/remote_updates.rs
+++ b/server/src/api/remote_updates.rs
@@ -2,10 +2,13 @@
 
 use anyhow::Error;
 
-use pdm_api_types::remote_updates::UpdateSummary;
 use pdm_api_types::remotes::Remote;
-use pdm_api_types::{PRIV_RESOURCE_MODIFY, UPID};
+use pdm_api_types::{
+    remote_updates::UpdateSummary, remotes::REMOTE_ID_SCHEMA, RemoteUpid, NODE_SCHEMA,
+    PRIV_RESOURCE_MODIFY, UPID,
+};
 use proxmox_access_control::CachedUserInfo;
+use proxmox_apt_api_types::{APTGetChangelogOptions, APTUpdateInfo};
 use proxmox_rest_server::WorkerTask;
 use proxmox_router::{
     http_bail, list_subdirs_api_method, Permission, Router, RpcEnvironment, SubdirMap,
@@ -15,6 +18,8 @@ use proxmox_sortable_macro::sortable;
 
 use crate::remote_updates;
 
+use super::remotes::get_remote;
+
 pub const ROUTER: Router = Router::new()
     .get(&list_subdirs_api_method!(SUBDIRS))
     .subdirs(SUBDIRS);
@@ -106,3 +111,112 @@ pub fn refresh_remote_update_summaries(rpcenv: &mut dyn RpcEnvironment) -> Resul
 
     upid_str.parse()
 }
+
+#[api(
+    input: {
+        properties: {
+            remote: {
+                schema: REMOTE_ID_SCHEMA,
+            },
+            node: {
+                schema: NODE_SCHEMA,
+            },
+        },
+    },
+    returns: {
+        description: "A list of packages with available updates.",
+        type: Array,
+        items: {
+            type: APTUpdateInfo
+        },
+    },
+    access: {
+        permission: &Permission::Privilege(&["resource", "{remote}", "node", "{node}", "system"], PRIV_RESOURCE_MODIFY, false),
+    },
+)]
+/// List available APT updates for a remote PVE node.
+async fn apt_update_available(remote: String, node: String) -> Result<Vec<APTUpdateInfo>, Error> {
+    let (config, _digest) = pdm_config::remotes::config()?;
+    let remote = get_remote(&config, &remote)?;
+
+    let updates = remote_updates::list_available_updates(remote.clone(), &node).await?;
+
+    Ok(updates)
+}
+
+#[api(
+    input: {
+        properties: {
+            remote: {
+                schema: REMOTE_ID_SCHEMA,
+            },
+            node: {
+                schema: NODE_SCHEMA,
+            },
+        },
+    },
+    access: {
+        permission: &Permission::Privilege(&["resource", "{remote}", "node", "{node}", "system"], PRIV_RESOURCE_MODIFY, false),
+    },
+)]
+/// Update the APT database of a remote PVE node.
+pub async fn apt_update_database(remote: String, node: String) -> Result<RemoteUpid, Error> {
+    let (config, _digest) = pdm_config::remotes::config()?;
+    let remote = get_remote(&config, &remote)?;
+
+    let upid = remote_updates::update_apt_database(remote, &node).await?;
+
+    Ok(upid)
+}
+
+#[api(
+    input: {
+        properties: {
+            remote: {
+                schema: REMOTE_ID_SCHEMA,
+            },
+            node: {
+                schema: NODE_SCHEMA,
+            },
+            options: {
+                type: APTGetChangelogOptions,
+                flatten: true,
+            },
+        },
+    },
+    returns: {
+        description: "The Package changelog.",
+        type: String,
+    },
+    access: {
+        permission: &Permission::Privilege(&["resource", "{remote}", "node", "{node}", "system"], PRIV_RESOURCE_MODIFY, false),
+    },
+)]
+/// Retrieve the changelog of the specified package for a remote PVE node.
+async fn apt_get_changelog(
+    remote: String,
+    node: String,
+    options: APTGetChangelogOptions,
+) -> Result<String, Error> {
+    let (config, _digest) = pdm_config::remotes::config()?;
+    let remote = get_remote(&config, &remote)?;
+
+    remote_updates::get_changelog(remote.clone(), &node, options.name).await
+}
+
+const APT_SUBDIRS: SubdirMap = &[
+    (
+        "changelog",
+        &Router::new().get(&API_METHOD_APT_GET_CHANGELOG),
+    ),
+    (
+        "update",
+        &Router::new()
+            .get(&API_METHOD_APT_UPDATE_AVAILABLE)
+            .post(&API_METHOD_APT_UPDATE_DATABASE),
+    ),
+];
+
+pub const APT_ROUTER: Router = Router::new()
+    .get(&list_subdirs_api_method!(APT_SUBDIRS))
+    .subdirs(APT_SUBDIRS);
-- 
2.47.3





More information about the pdm-devel mailing list