]> git.proxmox.com Git - pve-installer.git/commitdiff
tui: use hostname from run env if available
authorChristoph Heiss <c.heiss@proxmox.com>
Fri, 20 Oct 2023 09:46:47 +0000 (11:46 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 20 Oct 2023 10:31:22 +0000 (12:31 +0200)
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@proxmox.com>
proxmox-tui-installer/src/options.rs
proxmox-tui-installer/src/setup.rs

index a0a81c9d5451f15b03258e3e89eddabb3b41ec15..9e54da7b0d6fcef1cf46838f748830b9cfbac90f 100644 (file)
@@ -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 {
index c415d0ef8df78b4ee056d8793867af664d19fd23..72381318c20558717af56877e641a51279747dbb 100644 (file)
@@ -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)]