[pve-devel] [PATCH 14/19] cloudinit: allow a different hostname

Alexandre Derumier aderumier at odiso.com
Tue May 23 08:57:12 CEST 2017


From: Wolfgang Bumiller <w.bumiller at proxmox.com>

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuServer.pm | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 023a51a..f057641 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -525,6 +525,12 @@ my $confdesc_cloudinit = {
 	type => 'string',
 	description => "cloud-init: ssh keys for root",
     },
+    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 ?
@@ -6658,7 +6664,13 @@ sub generate_cloudinit_userdata {
     my ($conf, $path) = @_;
 
     my $content = "#cloud-config\n";
-    my $hostname = $conf->{searchdomain} ? $conf->{name}.".".$conf->{searchdomain} : $conf->{name};
+    my $hostname = $conf->{hostname};
+    if (!defined($hostname)) {
+	$hostname = $conf->{name};
+	if (my $search = $conf->{searchdomain}) {
+	    $hostname .= ".$search";
+	}
+    }
     $content .= "fqdn: $hostname\n";
     $content .= "manage_etc_hosts: true\n";
     $content .= "bootcmd: \n";
-- 
2.11.0




More information about the pve-devel mailing list