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

Alexandre Derumier aderumier at odiso.com
Sun Jun 18 15:03:20 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 b79a1e0..8698b8c 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -524,6 +524,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 ?
@@ -6714,7 +6720,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