X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=PVE%2FQemuServer%2FCloudinit.pm;h=5be820c22d58b0cc0014e7dab6412f8d2db9132d;hb=c701be32431405e7b45c966d65a1825594e44288;hp=3cdf3a6bfeb3ebc06e76d4c9e57995952bf14529;hpb=9be87f4eea496e27c54f2c6555df6f1262d90bd7;p=qemu-server.git diff --git a/PVE/QemuServer/Cloudinit.pm b/PVE/QemuServer/Cloudinit.pm index 3cdf3a6..5be820c 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}; } } @@ -309,7 +316,7 @@ sub nocloud_network { my $net = PVE::QemuServer::parse_net($conf->{$iface}); my $ipconfig = PVE::QemuServer::parse_ipconfig($conf->{"ipconfig$id"}); - my $mac = $net->{macaddr} + my $mac = lc($net->{macaddr}) or die "network interface '$iface' has no mac address\n"; $content .= "${i}- type: physical\n" @@ -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"; } @@ -331,8 +340,11 @@ sub nocloud_network { if (defined(my $ip = $ipconfig->{ip6})) { if ($ip eq 'dhcp') { $content .= "${i}- type: dhcp6\n"; + } elsif ($ip eq 'auto') { + # SLAAC is not supported by cloud-init, this fallback should work with an up-to-date netplan at least + $content .= "${i}- type: dhcp6\n"; } else { - $content .= "${i}- type: static6\n" + $content .= "${i}- type: static\n" . "${i} address: $ip\n"; if (defined(my $gw = $ipconfig->{gw6})) { $content .= "${i} gateway: $gw\n";