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:
Wolfgang Bumiller 2018-03-07 08:08:03 +01:00
parent 7b42f95142
commit e8ac21381e
2 changed files with 17 additions and 23 deletions

View File

@ -574,12 +574,6 @@ my $confdesc_cloudinit = {
description => "cloud-init : Setup public SSH keys (one key per line, " . description => "cloud-init : Setup public SSH keys (one key per line, " .
"OpenSSH format).", "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 ? # what about other qemu settings ?

View File

@ -44,26 +44,30 @@ sub get_cloudinit_format {
return 'nocloud'; return 'nocloud';
} }
sub get_fqdn { sub get_hostname_fqdn {
my ($conf) = @_; my ($conf) = @_;
my $fqdn = $conf->{hostname}; my $hostname = $conf->{name};
if (!defined($fqdn)) { my $fqdn;
$fqdn = $conf->{name}; if ($hostname =~ /\./) {
if (my $search = $conf->{searchdomain}) { $fqdn = $hostname;
$fqdn .= ".$search"; $hostname =~ s/\..*$//;
} } elsif (my $search = $conf->{searchdomain}) {
$fqdn = "$hostname.$search";
} }
return $fqdn; return ($hostname, $fqdn);
} }
sub cloudinit_userdata { sub cloudinit_userdata {
my ($conf) = @_; my ($conf) = @_;
my $fqdn = get_fqdn($conf); my ($hostname, $fqdn) = get_hostname_fqdn($conf);
my $content = "#cloud-config\n"; my $content = "#cloud-config\n";
$content .= "manage_resolv_conf: true\n"; $content .= "manage_resolv_conf: true\n";
$content .= "hostname: $hostname\n";
$content .= "fqdn: $fqdn\n" if defined($fqdn);
my $username = $conf->{ciuser}; my $username = $conf->{ciuser};
my $password = $conf->{cipassword}; my $password = $conf->{cipassword};
@ -324,24 +328,20 @@ sub nocloud_network {
} }
sub nocloud_metadata { sub nocloud_metadata {
my ($uuid, $hostname) = @_; my ($uuid) = @_;
return <<"EOF"; return "instance-id: $uuid\n";
instance-id: $uuid
local-hostname: $hostname
EOF
} }
sub generate_nocloud { sub generate_nocloud {
my ($conf, $vmid, $drive, $volname, $storeid) = @_; my ($conf, $vmid, $drive, $volname, $storeid) = @_;
my $hostname = $conf->{hostname} // '';
my $user_data = cloudinit_userdata($conf); my $user_data = cloudinit_userdata($conf);
my $network_data = nocloud_network($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 $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"; mkdir "/tmp/cloudinit";
my $path = "/tmp/cloudinit/$vmid"; my $path = "/tmp/cloudinit/$vmid";