mirror of
https://git.proxmox.com/git/pve-installer
synced 2025-08-27 15:35:12 +00:00
run env: retrieve and store hostname from DHCP lease if available
Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
This commit is contained in:
parent
18f58123e8
commit
bda1cdf699
@ -264,6 +264,10 @@ sub query_installation_environment : prototype() {
|
|||||||
routes => $routes,
|
routes => $routes,
|
||||||
dns => query_dns(),
|
dns => query_dns(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Cannot be put directly in the above hash as it might return undef ..
|
||||||
|
$output->{network}->{hostname} = Proxmox::Sys::Net::get_dhcp_hostname();
|
||||||
|
|
||||||
# FIXME: move whatever makes sense over to Proxmox::Sys::Net:: and keep that as single source,
|
# FIXME: move whatever makes sense over to Proxmox::Sys::Net:: and keep that as single source,
|
||||||
# it can then use some different structure just fine (after adapting the GTK GUI to that) but
|
# it can then use some different structure just fine (after adapting the GTK GUI to that) but
|
||||||
# **never** to (slightly different!) things for the same stuff...
|
# **never** to (slightly different!) things for the same stuff...
|
||||||
|
@ -189,4 +189,29 @@ sub get_ip_config {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Tries to detect the hostname for this system via DHCP, if available.
|
||||||
|
# DHCP server can set option 12 to inform the client about it's hostname [0].
|
||||||
|
# dhclient dumps all options set by the DHCP server it in lease file, so just
|
||||||
|
# read it from there.
|
||||||
|
# [0] RFC 2132, section 3.14
|
||||||
|
sub get_dhcp_hostname : prototype() {
|
||||||
|
my $leasefile = '/var/lib/dhcp/dhclient.leases';
|
||||||
|
return if ! -f $leasefile;
|
||||||
|
|
||||||
|
open (my $fh, '<', $leasefile) or return;
|
||||||
|
|
||||||
|
my $name = undef;
|
||||||
|
while (my $line = <$fh>) {
|
||||||
|
# "The name may or may not be qualified with the local domain name"
|
||||||
|
# Thus, only match the first part.
|
||||||
|
if ($line =~ m/^\s+option host-name \"(${FQDN_RE})\";$/) {
|
||||||
|
$name = $1;
|
||||||
|
last;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
close($fh);
|
||||||
|
return $1 if defined($name) && $name =~ m/^([^\.]+)(?:\.(?:\S+))?$/;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
Reference in New Issue
Block a user