[pdm-devel] [PATCH datacenter-manager 4/9] server: api: add target-endpoint parameter to remote migrate api calls

Dominik Csapak d.csapak at proxmox.com
Mon Jan 13 16:45:45 CET 2025


so we can explicitly control where the remote migration should go to.
It is still necessary that the endpoint is part of the remote
configuration.

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 server/src/api/pve/lxc.rs  | 19 +++++++++++++++++--
 server/src/api/pve/qemu.rs | 21 ++++++++++++++++++---
 2 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/server/src/api/pve/lxc.rs b/server/src/api/pve/lxc.rs
index b16d268..f1c3142 100644
--- a/server/src/api/pve/lxc.rs
+++ b/server/src/api/pve/lxc.rs
@@ -403,6 +403,12 @@ pub async fn lxc_migrate(
                 description: "Add a shutdown timeout for the restart-migration.",
                 optional: true,
             },
+            // TODO better to change remote migration to proxy to node?
+            "target-endpoint": {
+                type: String,
+                optional: true,
+                description: "The target endpoint to use for the connection.",
+            },
         },
     },
     returns: { type: RemoteUpid },
@@ -427,6 +433,7 @@ pub async fn lxc_remote_migrate(
     bwlimit: Option<u64>,
     restart: Option<bool>,
     timeout: Option<i64>,
+    target_endpoint: Option<String>,
     rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<RemoteUpid, Error> {
     let user_info = CachedUserInfo::new()?;
@@ -472,8 +479,16 @@ pub async fn lxc_remote_migrate(
 
     let target_node = target
         .nodes
-        .first()
-        .ok_or_else(|| format_err!("no nodes configured for target cluster"))?;
+        .iter()
+        .find(|endpoint| match target_endpoint.as_deref() {
+            Some(target) => target == endpoint.hostname,
+            None => true,
+        })
+        .ok_or_else(|| match target_endpoint {
+            Some(endpoint) => format_err!("{endpoint} not configured for target cluster"),
+            None => format_err!("no nodes configured for target cluster"),
+        })?;
+
     let target_host_port: Authority = target_node.hostname.parse()?;
     let mut target_endpoint = format!(
         "host={host},port={port},apitoken=PVEAPIToken={authid}={secret}",
diff --git a/server/src/api/pve/qemu.rs b/server/src/api/pve/qemu.rs
index 335c332..dea0550 100644
--- a/server/src/api/pve/qemu.rs
+++ b/server/src/api/pve/qemu.rs
@@ -450,7 +450,13 @@ async fn qemu_migrate_preconditions(
             bwlimit: {
                 description: "Override I/O bandwidth limit (in KiB/s).",
                 optional: true,
-            }
+            },
+            // TODO better to change remote migration to proxy to node?
+            "target-endpoint": {
+                type: String,
+                optional: true,
+                description: "The target endpoint to use for the connection.",
+            },
         },
     },
     returns: { type: RemoteUpid },
@@ -473,6 +479,7 @@ pub async fn qemu_remote_migrate(
     target_storage: String,
     target_bridge: String,
     bwlimit: Option<u64>,
+    target_endpoint: Option<String>,
     rpcenv: &mut dyn RpcEnvironment,
 ) -> Result<RemoteUpid, Error> {
     let user_info = CachedUserInfo::new()?;
@@ -519,8 +526,16 @@ pub async fn qemu_remote_migrate(
 
     let target_node = target
         .nodes
-        .first()
-        .ok_or_else(|| format_err!("no nodes configured for target cluster"))?;
+        .iter()
+        .find(|endpoint| match target_endpoint.as_deref() {
+            Some(target) => target == endpoint.hostname,
+            None => true,
+        })
+        .ok_or_else(|| match target_endpoint {
+            Some(endpoint) => format_err!("{endpoint} not configured for target cluster"),
+            None => format_err!("no nodes configured for target cluster"),
+        })?;
+
     let target_host_port: Authority = target_node.hostname.parse()?;
     let mut target_endpoint = format!(
         "host={host},port={port},apitoken=PVEAPIToken={authid}={secret}",
-- 
2.39.5





More information about the pdm-devel mailing list