]> git.proxmox.com Git - qemu-server.git/commitdiff
cloud-init: nocloud v1: set ip and netmask instead of cidr
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 6 Jun 2018 14:13:25 +0000 (16:13 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Thu, 7 Jun 2018 10:03:52 +0000 (12:03 +0200)
because of centos7's broken cloud-init version

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

index 3cdf3a6bfeb3ebc06e76d4c9e57995952bf14529..b63d010e60d7a25d166d6812a99c474c706db43a 100644 (file)
@@ -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";
                }