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 4/5] tui: use hostname from run env if available
Date: Fri, 20 Oct 2023 11:46:47 +0200	[thread overview]
Message-ID: <20231020094651.432513-5-c.heiss@proxmox.com> (raw)
In-Reply-To: <20231020094651.432513-1-c.heiss@proxmox.com>

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 | 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





  parent reply	other threads:[~2023-10-20  9:46 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-20  9:46 [pve-devel] [PATCH installer 0/5] use hostname from DHCP lease " Christoph Heiss
2023-10-20  9:46 ` [pve-devel] [PATCH installer 1/5] net: move hostname/fqdn regexes into common code Christoph Heiss
2023-10-20  9:46 ` [pve-devel] [PATCH installer 2/5] run env: retrieve and store hostname from DHCP lease if available Christoph Heiss
2023-10-20  9:46 ` [pve-devel] [PATCH installer 3/5] proxinstall: use hostname from run env " Christoph Heiss
2023-10-20  9:46 ` Christoph Heiss [this message]
2023-10-20  9:46 ` [pve-devel] [PATCH installer 5/5] tui: add some tests for `NetworkInfo` -> `NetworkOptions` conversion Christoph Heiss
2023-10-20 15:21 ` [pve-devel] applied-series: [PATCH installer 0/5] use hostname from DHCP lease if available Thomas Lamprecht
2023-10-24  7:45   ` 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=20231020094651.432513-5-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