]> git.proxmox.com Git - qemu-server.git/commitdiff
cloud-init: remove separate hostname config entry
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 7 Mar 2018 07:08:03 +0000 (08:08 +0100)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 7 Mar 2018 08:15:42 +0000 (09:15 +0100)
Use the vm name and set hostname and fqdn in user data
again.

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
PVE/QemuServer.pm
PVE/QemuServer/Cloudinit.pm

index 6237cbc0adaa4b4e5e0bbc46ec2a6c72618ca6af..a51f83265e568c376317b171505d423dcfafc39b 100644 (file)
@@ -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 ?
index 9fcb817be3df6d3ce62074d79f3f1851160d3be0..c026d79fe8540a596c8b74af300c7bc8565ce81e 100644 (file)
@@ -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";