[pve-devel] [PATCH installer 4/5] tui: use hostname from run env if available

Christoph Heiss c.heiss at proxmox.com
Fri Oct 20 11:46:47 CEST 2023


This now tries to use the hostname from the DHCP lease if it was set,
falling back to the product name as before.

Signed-off-by: Christoph Heiss <c.heiss at proxmox.com>
---
 proxmox-tui-installer/src/options.rs | 22 +++++++++++++++-------
 proxmox-tui-installer/src/setup.rs   |  3 +++
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/proxmox-tui-installer/src/options.rs b/proxmox-tui-installer/src/options.rs
index a0a81c9..9e54da7 100644
--- a/proxmox-tui-installer/src/options.rs
+++ b/proxmox-tui-installer/src/options.rs
@@ -337,11 +337,16 @@ pub struct NetworkOptions {
     pub dns_server: IpAddr,
 }
 
+impl NetworkOptions {
+    const DEFAULT_DOMAIN: &str = "example.invalid";
+}
+
 impl Default for NetworkOptions {
     fn default() -> Self {
         let fqdn = format!(
-            "{}.example.invalid",
-            crate::current_product().default_hostname()
+            "{}.{}",
+            crate::current_product().default_hostname(),
+            Self::DEFAULT_DOMAIN
         );
         // TODO: Retrieve automatically
         Self {
@@ -363,11 +368,14 @@ impl From<&NetworkInfo> for NetworkOptions {
             this.dns_server = *ip;
         }
 
-        if let Some(domain) = &info.dns.domain {
-            let hostname = crate::current_product().default_hostname();
-            if let Ok(fqdn) = Fqdn::from(&format!("{hostname}.{domain}")) {
-                this.fqdn = fqdn;
-            }
+        let hostname = info
+            .hostname
+            .as_deref()
+            .unwrap_or_else(|| crate::current_product().default_hostname());
+        let domain = info.dns.domain.as_deref().unwrap_or(Self::DEFAULT_DOMAIN);
+
+        if let Ok(fqdn) = Fqdn::from(&format!("{hostname}.{domain}")) {
+            this.fqdn = fqdn;
         }
 
         if let Some(routes) = &info.routes {
diff --git a/proxmox-tui-installer/src/setup.rs b/proxmox-tui-installer/src/setup.rs
index 942e319..c7b32e5 100644
--- a/proxmox-tui-installer/src/setup.rs
+++ b/proxmox-tui-installer/src/setup.rs
@@ -408,6 +408,9 @@ pub struct NetworkInfo {
     /// (Contains no entries for devices with only link-local addresses.)
     #[serde(default)]
     pub interfaces: HashMap<String, Interface>,
+
+    /// The hostname of this machine, if set by the DHCP server.
+    pub hostname: Option<String>,
 }
 
 #[derive(Clone, Deserialize)]
-- 
2.42.0






More information about the pve-devel mailing list