[pve-devel] [PATCH qemu-server 1/2] cloud-init: nocloud v1: set ip and netmask instead of cidr

Wolfgang Bumiller w.bumiller at proxmox.com
Wed Jun 6 16:13:25 CEST 2018


because of centos7's broken cloud-init version

Signed-off-by: Wolfgang Bumiller <w.bumiller at proxmox.com>
---
 PVE/QemuServer/Cloudinit.pm | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/PVE/QemuServer/Cloudinit.pm b/PVE/QemuServer/Cloudinit.pm
index 3cdf3a6..b63d010 100644
--- a/PVE/QemuServer/Cloudinit.pm
+++ b/PVE/QemuServer/Cloudinit.pm
@@ -137,6 +137,13 @@ sub cloudinit_userdata {
     return $content;
 }
 
+sub split_ip4 {
+    my ($ip) = @_;
+    my ($addr, $mask) = split('/', $ip);
+    die "not a CIDR: $ip\n" if !defined $mask;
+    return ($addr, $PVE::Network::ipv4_reverse_mask->[$mask]);
+}
+
 sub configdrive2_network {
     my ($conf) = @_;
 
@@ -165,10 +172,10 @@ sub configdrive2_network {
 	    if ($net->{ip} eq 'dhcp') {
 		$content .= "iface $id inet dhcp\n";
 	    } else {
-		my ($addr, $mask) = split('/', $net->{ip});
+		my ($addr, $mask) = split_ip4($net->{ip});
 		$content .= "iface $id inet static\n";
 		$content .= "        address $addr\n";
-		$content .= "        netmask $PVE::Network::ipv4_reverse_mask->[$mask]\n";
+		$content .= "        netmask $mask\n";
 		$content .= "        gateway $net->{gw}\n" if $net->{gw};
 	    }
 	}
@@ -321,8 +328,10 @@ sub nocloud_network {
 	    if ($ip eq 'dhcp') {
 		$content .= "${i}- type: dhcp4\n";
 	    } else {
+		my ($addr, $mask) = split_ip4($ip);
 		$content .= "${i}- type: static\n"
-		       . "${i}  address: $ip\n";
+		          . "${i}  address: $addr\n"
+		          . "${i}  netmask: $mask\n";
 		if (defined(my $gw = $ipconfig->{gw})) {
 		    $content .= "${i}  gateway: $gw\n";
 		}
-- 
2.11.0





More information about the pve-devel mailing list