all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Thomas Lamprecht <t.lamprecht@proxmox.com>
To: Proxmox VE development discussion <pve-devel@lists.proxmox.com>,
	Stoiko Ivanov <s.ivanov@proxmox.com>
Subject: [pve-devel] applied: [PATCH installer] tui: fix interface sort order
Date: Fri, 17 Nov 2023 19:34:34 +0100	[thread overview]
Message-ID: <aeb008a5-0958-4769-a12c-a1ea991c94b1@proxmox.com> (raw)
In-Reply-To: <20231117173023.1484541-1-s.ivanov@proxmox.com>

Am 17/11/2023 um 18:30 schrieb Stoiko Ivanov:
> currently when multiple nics are present in a system the TUI
> sometimes selects the wrong interface (not the one that has the
> default gateway/dhcp lease)
> 
> I assume this is due to HashMap's values yielding an iterator in
> arbitrary order
> 
> Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
> ---
> sadly a bit difficult to test due to the randomnes - but at least the 3
> tests on a VM were consistent.
> 
>  proxmox-tui-installer/src/main.rs | 13 ++++++++++---
>  1 file changed, 10 insertions(+), 3 deletions(-)
> 
>

applied, thanks!

as talked off-list, I remolded this to avoid a separate vector by re-using the
SelectView's data, which is already sorted:

diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs
index 4c14482..4b6b5b2 100644
--- a/proxmox-tui-installer/src/main.rs
+++ b/proxmox-tui-installer/src/main.rs
@@ -493,13 +493,14 @@ fn network_dialog(siv: &mut Cursive) -> InstallerView {
         .map(|iface| (iface.render(), iface.name.clone()));
     let mut ifaces_selection = SelectView::new().popup().with_all(ifnames.clone());
 
+    // sort first to always have stable view
     ifaces_selection.sort();
-    ifaces_selection.set_selection(
-        ifnames
-            .clone()
-            .position(|iface| iface.1 == options.ifname)
-            .unwrap_or(ifaces.len() - 1),
-    );
+    let selected = ifaces_selection
+        .iter()
+        .position(|(_label, iface)| *iface == options.ifname)
+        .unwrap_or(ifaces.len() - 1);
+
+    ifaces_selection.set_selection(selected);
 
     let inner = FormView::new()
         .child("Management interface", ifaces_selection)




      reply	other threads:[~2023-11-17 18:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-17 17:30 [pve-devel] " Stoiko Ivanov
2023-11-17 18:34 ` Thomas Lamprecht [this message]

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=aeb008a5-0958-4769-a12c-a1ea991c94b1@proxmox.com \
    --to=t.lamprecht@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    --cc=s.ivanov@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal