From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id E3CFC1FF173 for ; Mon, 13 Jan 2025 16:46:16 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 417454ECF; Mon, 13 Jan 2025 16:45:59 +0100 (CET) From: Dominik Csapak To: pdm-devel@lists.proxmox.com Date: Mon, 13 Jan 2025 16:45:50 +0100 Message-Id: <20250113154550.3462139-12-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 9/9] ui: migrate: make target endpoint selectable for remote migration X-BeenThere: pdm-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Datacenter Manager development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Proxmox Datacenter Manager development discussion Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pdm-devel-bounces@lists.proxmox.com Sender: "pdm-devel" by showing a target endpoint selector instead of a target node one when it's a remote migration. For the user to be able to select the target storage/network properly, we have to query the nodename for the target and update the storage/network selectors. Signed-off-by: Dominik Csapak --- ui/src/widget/migrate_window.rs | 68 ++++++++++++++++++++++++++++++++- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/ui/src/widget/migrate_window.rs b/ui/src/widget/migrate_window.rs index c87cf9a..7214ff4 100644 --- a/ui/src/widget/migrate_window.rs +++ b/ui/src/widget/migrate_window.rs @@ -23,6 +23,7 @@ use pdm_client::{MigrateLxc, MigrateQemu, RemoteMigrateLxc, RemoteMigrateQemu}; use crate::pve::GuestInfo; use crate::pve::GuestType; +use super::remote_endpoint_selector::EndpointSelector; use super::{ PveMigrateMap, PveNetworkSelector, PveNodeSelector, PveStorageSelector, RemoteSelector, }; @@ -62,6 +63,8 @@ impl MigrateWindow { pub enum Msg { RemoteChange(String), + EndpointChange(String), + NodenameResult(Result), Result(RemoteUpid), LoadPreconditions(Option), PreconditionResult(Result), @@ -71,9 +74,29 @@ pub struct PdmMigrateWindow { target_remote: AttrValue, _async_pool: AsyncPool, preconditions: Option, + target_node: Option, } impl PdmMigrateWindow { + async fn get_nodename( + remote: AttrValue, + target_endpoint: AttrValue, + ) -> Result { + let status_list = crate::pdm_client() + .pve_cluster_status(&remote, Some(&target_endpoint)) + .await?; + + for status in status_list { + if status.local.unwrap_or(false) { + return Ok(status.name); + } + } + + Err(proxmox_client::Error::Other( + "could not find local nodename", + )) + } + async fn load_preconditions( remote: String, guest_info: GuestInfo, @@ -132,6 +155,7 @@ impl PdmMigrateWindow { let target_remote = value["remote"].as_str().unwrap_or_default(); let upid = if target_remote != remote { + let target_endpoint = value.get("target-endpoint").and_then(|e| e.as_str()); match guest_info.guest_type { crate::pve::GuestType::Qemu => { let mut migrate_opts = RemoteMigrateQemu::new() @@ -174,6 +198,7 @@ impl PdmMigrateWindow { None, guest_info.vmid, target_remote.to_string(), + target_endpoint, migrate_opts, ) .await? @@ -218,6 +243,7 @@ impl PdmMigrateWindow { None, guest_info.vmid, target_remote.to_string(), + target_endpoint, migrate_opts, ) .await? @@ -266,10 +292,12 @@ impl PdmMigrateWindow { source_remote: AttrValue, guest_info: GuestInfo, preconditions: Option, + target_node: Option, ) -> Html { let same_remote = target_remote == source_remote; if !same_remote { - form_ctx.write().set_field_value("node", "".into()); + let node = target_node.unwrap_or_default().to_string(); + form_ctx.write().set_field_value("node", node.into()); } let detail_mode = form_ctx.read().get_field_checked("detailed-mode"); let mut uses_local_disks = false; @@ -336,13 +364,27 @@ impl PdmMigrateWindow { tr!("Mode"), DisplayField::new("").name("migrate-mode").key("mode"), ) - .with_right_field( + .with_field_and_options( + pwt::widget::FieldPosition::Right, + false, + !same_remote, tr!("Target Node"), PveNodeSelector::new(target_remote.clone()) .name("node") .required(same_remote) .on_change(link.callback(Msg::LoadPreconditions)) .disabled(!same_remote), + ) + .with_field_and_options( + pwt::widget::FieldPosition::Right, + false, + same_remote, + tr!("Target Endpoint"), + EndpointSelector::new(target_remote.clone()) + .placeholder(tr!("Automatic")) + .name("target-endpoint") + .on_change(link.callback(Msg::EndpointChange)) + .disabled(same_remote), ); if !same_remote || uses_local_disks || uses_local_resources { @@ -460,6 +502,7 @@ impl Component for PdmMigrateWindow { target_remote: ctx.props().remote.clone(), _async_pool: AsyncPool::new(), preconditions: None, + target_node: None, } } @@ -501,6 +544,25 @@ impl Component for PdmMigrateWindow { } true } + Msg::EndpointChange(endpoint) => { + let remote = self.target_remote.clone(); + self._async_pool + .send_future(ctx.link().clone(), async move { + let res = Self::get_nodename(remote, endpoint.into()).await; + Msg::NodenameResult(res) + }); + false + } + Msg::NodenameResult(result) => match result { + Ok(nodename) => { + self.target_node = Some(nodename.into()); + true + } + Err(err) => { + log::error!("could not extract nodename from endpoint: {err}"); + false + } + }, } } @@ -525,6 +587,7 @@ impl Component for PdmMigrateWindow { let source_remote = ctx.props().remote.clone(); let link = ctx.link().clone(); let preconditions = self.preconditions.clone(); + let target_node = self.target_node.clone(); move |form| { Self::input_panel( &link, @@ -533,6 +596,7 @@ impl Component for PdmMigrateWindow { source_remote.clone(), guest_info, preconditions.clone(), + target_node.clone(), ) } }) -- 2.39.5 _______________________________________________ pdm-devel mailing list pdm-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pdm-devel