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 7CADE1FF173
	for <inbox@lore.proxmox.com>; Mon, 13 Jan 2025 16:46:44 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 2607F5086;
	Mon, 13 Jan 2025 16:46:28 +0100 (CET)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pdm-devel@lists.proxmox.com
Date: Mon, 13 Jan 2025 16:45:45 +0100
Message-Id: <20250113154550.3462139-7-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250113154550.3462139-1-d.csapak@proxmox.com>
References: <20250113154550.3462139-1-d.csapak@proxmox.com>
MIME-Version: 1.0
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.016 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
 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] [PATCH datacenter-manager 4/9] server: api: add
 target-endpoint parameter to remote migrate api calls
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>

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@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



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