[pdm-devel] [RFC proxmox-datacenter-manager 5/5] server: pve api: track new tasks created by PDM

Lukas Wagner l.wagner at proxmox.com
Fri Dec 20 15:24:30 CET 2024


When we start a new tasks from PDM, we add the task's UPID to the set of
tracked tasks. Theses tasks will be polled regularly to track their
status.

Originally-by: Dominik Csapak <d.csapak at proxmox.com>
Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
 server/src/api/pve/mod.rs | 33 ++++++++++++++++++++++-----------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/server/src/api/pve/mod.rs b/server/src/api/pve/mod.rs
index 6b16b43..a232d59 100644
--- a/server/src/api/pve/mod.rs
+++ b/server/src/api/pve/mod.rs
@@ -24,12 +24,13 @@ use pdm_api_types::{
 
 use pve_api_types::client::PveClient;
 use pve_api_types::{
-    ClusterResourceKind, ClusterResourceType, QemuMigratePreconditions, StartQemuMigrationType,
+    ClusterResourceKind, ClusterResourceType, PveUpid, QemuMigratePreconditions,
+    StartQemuMigrationType,
 };
 
 use super::resources::{map_pve_lxc, map_pve_node, map_pve_qemu, map_pve_storage};
 
-use crate::connection;
+use crate::{connection, task_cache};
 
 mod node;
 mod rrddata;
@@ -115,6 +116,13 @@ const QEMU_VM_SUBDIRS: SubdirMap = &sorted!([
 
 const RESOURCES_ROUTER: Router = Router::new().get(&API_METHOD_CLUSTER_RESOURCES);
 
+// converts a remote + PveUpid into a RemoteUpid and starts tracking it
+fn new_remote_upid(remote: String, upid: PveUpid) -> Result<RemoteUpid, Error> {
+    let remote_upid: RemoteUpid = (remote, upid.to_string()).try_into()?;
+    task_cache::track_running_task(remote_upid.clone());
+    Ok(remote_upid)
+}
+
 pub(crate) fn get_remote<'a>(
     config: &'a SectionConfigData<Remote>,
     id: &str,
@@ -507,7 +515,7 @@ pub async fn qemu_start(
         .start_qemu_async(&node, vmid, Default::default())
         .await?;
 
-    (remote, upid.to_string()).try_into()
+    new_remote_upid(remote, upid)
 }
 
 #[api(
@@ -540,7 +548,7 @@ pub async fn qemu_stop(
 
     let upid = pve.stop_qemu_async(&node, vmid, Default::default()).await?;
 
-    (remote, upid.to_string()).try_into()
+    new_remote_upid(remote, upid)
 }
 
 #[api(
@@ -575,7 +583,8 @@ pub async fn qemu_shutdown(
         .shutdown_qemu_async(&node, vmid, Default::default())
         .await?;
 
-    (remote, upid.to_string()).try_into()
+    //(remote, upid.to_string()).try_into()
+    new_remote_upid(remote, upid)
 }
 
 fn check_guest_delete_perms(
@@ -684,7 +693,8 @@ pub async fn qemu_migrate(
         with_local_disks,
     };
     let upid = pve.migrate_qemu(&node, vmid, params).await?;
-    (remote, upid.to_string()).try_into()
+    //(remote, upid.to_string()).try_into()
+    new_remote_upid(remote, upid)
 }
 
 #[api(
@@ -962,7 +972,7 @@ pub async fn lxc_start(
 
     let upid = pve.start_lxc_async(&node, vmid, Default::default()).await?;
 
-    (remote, upid.to_string()).try_into()
+    new_remote_upid(remote, upid)
 }
 
 #[api(
@@ -995,7 +1005,7 @@ pub async fn lxc_stop(
 
     let upid = pve.stop_lxc_async(&node, vmid, Default::default()).await?;
 
-    (remote, upid.to_string()).try_into()
+    new_remote_upid(remote, upid)
 }
 
 #[api(
@@ -1030,7 +1040,7 @@ pub async fn lxc_shutdown(
         .shutdown_lxc_async(&node, vmid, Default::default())
         .await?;
 
-    (remote, upid.to_string()).try_into()
+    new_remote_upid(remote, upid)
 }
 
 #[api(
@@ -1109,7 +1119,8 @@ pub async fn lxc_migrate(
         timeout,
     };
     let upid = pve.migrate_lxc(&node, vmid, params).await?;
-    (remote, upid.to_string()).try_into()
+
+    new_remote_upid(remote, upid)
 }
 
 #[api(
@@ -1255,7 +1266,7 @@ pub async fn lxc_remote_migrate(
     log::info!("migrating vm {vmid} of node {node:?}");
     let upid = source_conn.remote_migrate_lxc(&node, vmid, params).await?;
 
-    (source, upid.to_string()).try_into()
+    new_remote_upid(source, upid)
 }
 
 #[api(
-- 
2.39.5





More information about the pdm-devel mailing list