From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id EE6409BAC6 for ; Fri, 20 Oct 2023 11:46:59 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C1C5131FED for ; Fri, 20 Oct 2023 11:46:59 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Fri, 20 Oct 2023 11:46:56 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D211B435F3 for ; Fri, 20 Oct 2023 11:46:55 +0200 (CEST) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Fri, 20 Oct 2023 11:46:47 +0200 Message-ID: <20231020094651.432513-5-c.heiss@proxmox.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231020094651.432513-1-c.heiss@proxmox.com> References: <20231020094651.432513-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.022 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [setup.rs, options.rs] Subject: [pve-devel] [PATCH installer 4/5] tui: use hostname from run env if available X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Oct 2023 09:47:00 -0000 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 --- 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, + + /// The hostname of this machine, if set by the DHCP server. + pub hostname: Option, } #[derive(Clone, Deserialize)] -- 2.42.0