From 862807898c38f45f3fa15f0b51f99332817d78df Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 6 Jun 2018 16:13:25 +0200 Subject: [PATCH] cloud-init: nocloud v1: set ip and netmask instead of cidr because of centos7's broken cloud-init version Signed-off-by: Wolfgang Bumiller --- 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.39.2