mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-05-02 03:35:46 +00:00
cloud-init: remove separate hostname config entry
Use the vm name and set hostname and fqdn in user data again. Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
parent
7b42f95142
commit
e8ac21381e
@ -574,12 +574,6 @@ my $confdesc_cloudinit = {
|
||||
description => "cloud-init : Setup public SSH keys (one key per line, " .
|
||||
"OpenSSH format).",
|
||||
},
|
||||
hostname => {
|
||||
optional => 1,
|
||||
description => "cloud-init: Hostname to use instead of the vm-name + search-domain.",
|
||||
type => 'string', format => 'dns-name',
|
||||
maxLength => 255,
|
||||
},
|
||||
};
|
||||
|
||||
# what about other qemu settings ?
|
||||
|
@ -44,26 +44,30 @@ sub get_cloudinit_format {
|
||||
return 'nocloud';
|
||||
}
|
||||
|
||||
sub get_fqdn {
|
||||
sub get_hostname_fqdn {
|
||||
my ($conf) = @_;
|
||||
my $fqdn = $conf->{hostname};
|
||||
if (!defined($fqdn)) {
|
||||
$fqdn = $conf->{name};
|
||||
if (my $search = $conf->{searchdomain}) {
|
||||
$fqdn .= ".$search";
|
||||
}
|
||||
my $hostname = $conf->{name};
|
||||
my $fqdn;
|
||||
if ($hostname =~ /\./) {
|
||||
$fqdn = $hostname;
|
||||
$hostname =~ s/\..*$//;
|
||||
} elsif (my $search = $conf->{searchdomain}) {
|
||||
$fqdn = "$hostname.$search";
|
||||
}
|
||||
return $fqdn;
|
||||
return ($hostname, $fqdn);
|
||||
}
|
||||
|
||||
sub cloudinit_userdata {
|
||||
my ($conf) = @_;
|
||||
|
||||
my $fqdn = get_fqdn($conf);
|
||||
my ($hostname, $fqdn) = get_hostname_fqdn($conf);
|
||||
|
||||
my $content = "#cloud-config\n";
|
||||
$content .= "manage_resolv_conf: true\n";
|
||||
|
||||
$content .= "hostname: $hostname\n";
|
||||
$content .= "fqdn: $fqdn\n" if defined($fqdn);
|
||||
|
||||
my $username = $conf->{ciuser};
|
||||
my $password = $conf->{cipassword};
|
||||
|
||||
@ -324,24 +328,20 @@ sub nocloud_network {
|
||||
}
|
||||
|
||||
sub nocloud_metadata {
|
||||
my ($uuid, $hostname) = @_;
|
||||
return <<"EOF";
|
||||
instance-id: $uuid
|
||||
local-hostname: $hostname
|
||||
EOF
|
||||
my ($uuid) = @_;
|
||||
return "instance-id: $uuid\n";
|
||||
}
|
||||
|
||||
sub generate_nocloud {
|
||||
my ($conf, $vmid, $drive, $volname, $storeid) = @_;
|
||||
|
||||
my $hostname = $conf->{hostname} // '';
|
||||
my $user_data = cloudinit_userdata($conf);
|
||||
my $network_data = nocloud_network($conf);
|
||||
|
||||
my $digest_data = $user_data . $network_data . "local-hostname: $hostname\n";
|
||||
my $digest_data = $user_data . $network_data;
|
||||
my $uuid_str = Digest::SHA::sha1_hex($digest_data);
|
||||
|
||||
my $meta_data = nocloud_metadata($uuid_str, $hostname);
|
||||
my $meta_data = nocloud_metadata($uuid_str);
|
||||
|
||||
mkdir "/tmp/cloudinit";
|
||||
my $path = "/tmp/cloudinit/$vmid";
|
||||
|
Loading…
Reference in New Issue
Block a user