all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH installer 11/14] tui: views: move network options view to own module
Date: Tue, 14 Oct 2025 15:21:56 +0200	[thread overview]
Message-ID: <20251014132207.1171073-12-c.heiss@proxmox.com> (raw)
In-Reply-To: <20251014132207.1171073-1-c.heiss@proxmox.com>

In preparation for adding network interface name pinning, which will
introduce quite a bit more functionality.

No functional changes.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
 proxmox-tui-installer/src/main.rs          |  90 +---------------
 proxmox-tui-installer/src/views/mod.rs     |   3 +
 proxmox-tui-installer/src/views/network.rs | 113 +++++++++++++++++++++
 3 files changed, 121 insertions(+), 85 deletions(-)
 create mode 100644 proxmox-tui-installer/src/views/network.rs

diff --git a/proxmox-tui-installer/src/main.rs b/proxmox-tui-installer/src/main.rs
index 15ee5d3..b24f90b 100644
--- a/proxmox-tui-installer/src/main.rs
+++ b/proxmox-tui-installer/src/main.rs
@@ -1,6 +1,6 @@
 #![forbid(unsafe_code)]
 
-use std::{collections::HashMap, env, net::IpAddr};
+use std::{collections::HashMap, env};
 
 use cursive::{
     Cursive, CursiveRunnable, ScreenId, View, XY,
@@ -9,7 +9,7 @@ use cursive::{
     view::{Nameable, Offset, Resizable, ViewWrapper},
     views::{
         Button, Checkbox, Dialog, DummyView, EditView, Layer, LinearLayout, PaddedView, Panel,
-        ResizedView, ScrollView, SelectView, StackView, TextView,
+        ResizedView, ScrollView, StackView, TextView,
     },
 };
 
@@ -20,7 +20,6 @@ use proxmox_installer_common::{
     ROOT_PASSWORD_MIN_LENGTH,
     options::{BootdiskOptions, NetworkOptions, TimezoneOptions, email_validate},
     setup::{LocaleInfo, ProxmoxProduct, RuntimeInfo, SetupInfo, installer_setup},
-    utils::{CidrAddress, Fqdn},
 };
 mod setup;
 
@@ -28,7 +27,7 @@ mod system;
 
 mod views;
 use views::{
-    BootdiskOptionsView, CidrAddressEditView, FormView, InstallProgressView, TableView,
+    BootdiskOptionsView, FormView, InstallProgressView, NetworkOptionsView, TableView,
     TableViewItem, TimezoneOptionsView,
 };
 
@@ -483,91 +482,12 @@ fn password_dialog(siv: &mut Cursive) -> InstallerView {
 fn network_dialog(siv: &mut Cursive) -> InstallerView {
     let state = siv.user_data::<InstallerState>().unwrap();
     let options = &state.options.network;
-    let ifaces = state.runtime_info.network.interfaces.values();
-    let ifnames = ifaces
-        .clone()
-        .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();
-    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)
-        .child(
-            "Hostname (FQDN)",
-            EditView::new().content(options.fqdn.to_string()),
-        )
-        .child(
-            "IP address (CIDR)",
-            CidrAddressEditView::new().content(options.address.clone()),
-        )
-        .child(
-            "Gateway address",
-            EditView::new().content(options.gateway.to_string()),
-        )
-        .child(
-            "DNS server address",
-            EditView::new().content(options.dns_server.to_string()),
-        )
-        .with_name("network-options");
 
     InstallerView::new(
         state,
-        inner,
+        NetworkOptionsView::new(options, &state.runtime_info.network).with_name("network-options"),
         Box::new(|siv| {
-            let options = siv.call_on_name("network-options", |view: &mut FormView| {
-                let ifname = view
-                    .get_value::<SelectView, _>(0)
-                    .ok_or("failed to retrieve management interface name")?;
-
-                let fqdn = view
-                    .get_value::<EditView, _>(1)
-                    .ok_or("failed to retrieve host FQDN")?
-                    .parse::<Fqdn>()
-                    .map_err(|err| format!("hostname does not look valid:\n\n{err}"))?;
-
-                let address = view
-                    .get_value::<CidrAddressEditView, _>(2)
-                    .ok_or("failed to retrieve host address".to_string())
-                    .and_then(|(ip_addr, mask)| {
-                        CidrAddress::new(ip_addr, mask).map_err(|err| err.to_string())
-                    })?;
-
-                let gateway = view
-                    .get_value::<EditView, _>(3)
-                    .ok_or("failed to retrieve gateway address")?
-                    .parse::<IpAddr>()
-                    .map_err(|err| err.to_string())?;
-
-                let dns_server = view
-                    .get_value::<EditView, _>(4)
-                    .ok_or("failed to retrieve DNS server address")?
-                    .parse::<IpAddr>()
-                    .map_err(|err| err.to_string())?;
-
-                if address.addr().is_ipv4() != gateway.is_ipv4() {
-                    Err("host and gateway IP address version must not differ".to_owned())
-                } else if address.addr().is_ipv4() != dns_server.is_ipv4() {
-                    Err("host and DNS IP address version must not differ".to_owned())
-                } else if fqdn.to_string().ends_with(".invalid") {
-                    Err("hostname does not look valid".to_owned())
-                } else {
-                    Ok(NetworkOptions {
-                        ifname,
-                        fqdn,
-                        address,
-                        gateway,
-                        dns_server,
-                    })
-                }
-            });
+            let options = siv.call_on_name("network-options", NetworkOptionsView::get_values);
 
             match options {
                 Some(Ok(options)) => {
diff --git a/proxmox-tui-installer/src/views/mod.rs b/proxmox-tui-installer/src/views/mod.rs
index 537e3ed..43ca999 100644
--- a/proxmox-tui-installer/src/views/mod.rs
+++ b/proxmox-tui-installer/src/views/mod.rs
@@ -16,6 +16,9 @@ pub use bootdisk::*;
 mod install_progress;
 pub use install_progress::*;
 
+mod network;
+pub use network::*;
+
 mod tabbed_view;
 pub use tabbed_view::*;
 
diff --git a/proxmox-tui-installer/src/views/network.rs b/proxmox-tui-installer/src/views/network.rs
new file mode 100644
index 0000000..5e3e258
--- /dev/null
+++ b/proxmox-tui-installer/src/views/network.rs
@@ -0,0 +1,113 @@
+use std::net::IpAddr;
+
+use cursive::{
+    view::ViewWrapper,
+    views::{EditView, SelectView},
+};
+
+use super::{CidrAddressEditView, FormView};
+use proxmox_installer_common::{
+    options::NetworkOptions,
+    setup::NetworkInfo,
+    utils::{CidrAddress, Fqdn},
+};
+
+pub struct NetworkOptionsView {
+    view: FormView,
+}
+
+impl NetworkOptionsView {
+    pub fn new(options: &NetworkOptions, network_info: &NetworkInfo) -> Self {
+        let ifaces = network_info.interfaces.values();
+        let ifnames = ifaces
+            .clone()
+            .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();
+        let selected = ifaces_selection
+            .iter()
+            .position(|(_label, iface)| *iface == options.ifname)
+            .unwrap_or(ifaces.len() - 1);
+
+        ifaces_selection.set_selection(selected);
+
+        let view = FormView::new()
+            .child("Management interface", ifaces_selection)
+            .child(
+                "Hostname (FQDN)",
+                EditView::new().content(options.fqdn.to_string()),
+            )
+            .child(
+                "IP address (CIDR)",
+                CidrAddressEditView::new().content(options.address.clone()),
+            )
+            .child(
+                "Gateway address",
+                EditView::new().content(options.gateway.to_string()),
+            )
+            .child(
+                "DNS server address",
+                EditView::new().content(options.dns_server.to_string()),
+            );
+
+        Self { view }
+    }
+
+    pub fn get_values(&mut self) -> Result<NetworkOptions, String> {
+        let ifname = self
+            .view
+            .get_value::<SelectView, _>(0)
+            .ok_or("failed to retrieve management interface name")?;
+
+        let fqdn = self
+            .view
+            .get_value::<EditView, _>(1)
+            .ok_or("failed to retrieve host FQDN")?
+            .parse::<Fqdn>()
+            .map_err(|err| format!("hostname does not look valid:\n\n{err}"))?;
+
+        let address = self
+            .view
+            .get_value::<CidrAddressEditView, _>(2)
+            .ok_or("failed to retrieve host address".to_string())
+            .and_then(|(ip_addr, mask)| {
+                CidrAddress::new(ip_addr, mask).map_err(|err| err.to_string())
+            })?;
+
+        let gateway = self
+            .view
+            .get_value::<EditView, _>(3)
+            .ok_or("failed to retrieve gateway address")?
+            .parse::<IpAddr>()
+            .map_err(|err| err.to_string())?;
+
+        let dns_server = self
+            .view
+            .get_value::<EditView, _>(4)
+            .ok_or("failed to retrieve DNS server address")?
+            .parse::<IpAddr>()
+            .map_err(|err| err.to_string())?;
+
+        if address.addr().is_ipv4() != gateway.is_ipv4() {
+            Err("host and gateway IP address version must not differ".to_owned())
+        } else if address.addr().is_ipv4() != dns_server.is_ipv4() {
+            Err("host and DNS IP address version must not differ".to_owned())
+        } else if fqdn.to_string().ends_with(".invalid") {
+            Err("hostname does not look valid".to_owned())
+        } else {
+            Ok(NetworkOptions {
+                ifname,
+                fqdn,
+                address,
+                gateway,
+                dns_server,
+            })
+        }
+    }
+}
+
+impl ViewWrapper for NetworkOptionsView {
+    cursive::wrap_impl!(self.view: FormView);
+}
-- 
2.51.0



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


  parent reply	other threads:[~2025-10-14 13:23 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-14 13:21 [pve-devel] [PATCH installer 00/14] support network interface name pinning Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 01/14] test: parse-kernel-cmdline: fix module import statement Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 02/14] install: add support for network interface name pinning Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 03/14] run env: network: add kernel driver name to network interface info Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 04/14] common: utils: fix clippy warnings Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 05/14] common: setup: simplify network address list serialization Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 06/14] common: implement support for `network_interface_pin_map` config Christoph Heiss
2025-10-21 14:05   ` Michael Köppl
2025-10-22  9:37     ` Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 07/14] auto: add support for pinning network interface names Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 08/14] assistant: verify network settings in `validate-answer` subcommand Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 09/14] post-hook: avoid redundant Option<bool> for (de-)serialization Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 10/14] post-hook: add network interface name and pinning status Christoph Heiss
2025-10-14 13:21 ` Christoph Heiss [this message]
2025-10-14 13:21 ` [pve-devel] [PATCH installer 12/14] tui: views: form: allow attaching user-defined data to children Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 13/14] tui: add support for pinning network interface names Christoph Heiss
2025-10-14 13:21 ` [pve-devel] [PATCH installer 14/14] gui: " Christoph Heiss
2025-10-14 15:04   ` Maximiliano Sandoval
2025-10-16 12:01     ` Christoph Heiss
2025-10-21 14:05   ` Michael Köppl
2025-10-22  9:40     ` Christoph Heiss
2025-10-21 14:04 ` [pve-devel] [PATCH installer 00/14] support network interface name pinning Michael Köppl
2025-10-22  9:46   ` Christoph Heiss

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=20251014132207.1171073-12-c.heiss@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=pve-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 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