From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <pdm-devel-bounces@lists.proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9])
	by lore.proxmox.com (Postfix) with ESMTPS id DBF001FF164
	for <inbox@lore.proxmox.com>; Fri, 20 Dec 2024 15:24:44 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 072BD743B;
	Fri, 20 Dec 2024 15:24:44 +0100 (CET)
From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Date: Fri, 20 Dec 2024 15:24:30 +0100
Message-Id: <20241220142430.277101-5-l.wagner@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20241220142430.277101-1-l.wagner@proxmox.com>
References: <20241220142430.277101-1-l.wagner@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.007 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
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 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] [RFC proxmox-datacenter-manager 5/5] server: pve api:
 track new tasks created by PDM
X-BeenThere: pdm-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox Datacenter Manager development discussion
 <pdm-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pdm-devel>, 
 <mailto:pdm-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pdm-devel/>
List-Post: <mailto:pdm-devel@lists.proxmox.com>
List-Help: <mailto:pdm-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel>, 
 <mailto:pdm-devel-request@lists.proxmox.com?subject=subscribe>
Reply-To: Proxmox Datacenter Manager development discussion
 <pdm-devel@lists.proxmox.com>
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: 7bit
Errors-To: pdm-devel-bounces@lists.proxmox.com
Sender: "pdm-devel" <pdm-devel-bounces@lists.proxmox.com>

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@proxmox.com>
Signed-off-by: Lukas Wagner <l.wagner@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



_______________________________________________
pdm-devel mailing list
pdm-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel