From: Lukas Wagner <l.wagner@proxmox.com>
To: pdm-devel@lists.proxmox.com
Subject: [pdm-devel] [RFC proxmox-datacenter-manager 5/5] server: pve api: track new tasks created by PDM
Date: Fri, 20 Dec 2024 15:24:30 +0100 [thread overview]
Message-ID: <20241220142430.277101-5-l.wagner@proxmox.com> (raw)
In-Reply-To: <20241220142430.277101-1-l.wagner@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
next prev parent reply other threads:[~2024-12-20 14:24 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-20 14:24 [pdm-devel] [RFC proxmox-datacenter-manager 1/5] privileged-api: create /var/cache/proxmox-datacenter-manager/ on startup Lukas Wagner
2024-12-20 14:24 ` [pdm-devel] [RFC proxmox-datacenter-manager 2/5] pdm-api-types: derive Clone for TaskListItem Lukas Wagner
2024-12-20 14:24 ` [pdm-devel] [RFC proxmox-datacenter-manager 3/5] pdm-api-types: derive Eq, PartialEq and Hash for RemoteUpid Lukas Wagner
2024-12-20 14:24 ` [pdm-devel] [RFC proxmox-datacenter-manager 4/5] api: add caching 'remote-tasks' API endpoint Lukas Wagner
2024-12-20 14:24 ` Lukas Wagner [this message]
2025-01-13 11:28 ` [pdm-devel] applied: [RFC proxmox-datacenter-manager 1/5] privileged-api: create /var/cache/proxmox-datacenter-manager/ on startup Dietmar Maurer
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=20241220142430.277101-5-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox