cloud-init: nocloud v1: set ip and netmask instead of cidr

because of centos7's broken cloud-init version

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller 2018-06-06 16:13:25 +02:00 committed by Thomas Lamprecht
parent 616aecc100
commit 862807898c

View 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";
}