otherwise, having multiple ipconfigX entries, can lead to different instance-ids on different startups, which is not desired
Signed-off-by: Dominik Csapak <d.csa...@proxmox.com> --- 2 issues i have with this: * we have a cyclic dependency between PVE::QemuServer and PVE::QemuServer::Cloudinit, and this patch increases that we could fix this by refactoring all relevant code out of QemuServer.pm, but this seems like much work, since the that code depends on many parts of QemuServer, not sure how to proceed here... * i am not sure if using a getter for MAX_NETS is the right way here, or if we should use constants (or something else?)... PVE/QemuServer.pm | 4 ++++ PVE/QemuServer/Cloudinit.pm | 20 +++++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 1b22ff6..8fd917e 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -801,6 +801,10 @@ my $MAX_SERIAL_PORTS = 4; my $MAX_PARALLEL_PORTS = 3; my $MAX_NUMA = 8; +sub get_max_nets { + return $MAX_NETS; +}; + my $numa_fmt = { cpus => { type => "string", diff --git a/PVE/QemuServer/Cloudinit.pm b/PVE/QemuServer/Cloudinit.pm index 07d4d2d..9a9681b 100644 --- a/PVE/QemuServer/Cloudinit.pm +++ b/PVE/QemuServer/Cloudinit.pm @@ -169,9 +169,9 @@ sub configdrive2_network { $content .= " dns_search $searchdomains\n"; } - my @ifaces = grep(/^net(\d+)$/, keys %$conf); - foreach my $iface (@ifaces) { - (my $id = $iface) =~ s/^net//; + my $max_nets = PVE::QemuServer::get_max_nets(); + for (my $id = 0; $id < $max_nets; $id++) { + next if !$conf->{"net$id"}; next if !$conf->{"ipconfig$id"}; my $net = PVE::QemuServer::parse_ipconfig($conf->{"ipconfig$id"}); $id = "eth$id"; @@ -249,9 +249,10 @@ sub nocloud_network_v2 { my $dns_done; - my @ifaces = grep(/^net(\d+)$/, keys %$conf); - foreach my $iface (@ifaces) { - (my $id = $iface) =~ s/^net//; + my $max_nets = PVE::QemuServer::get_max_nets(); + for (my $id = 0; $id < $max_nets; $id++) { + my $iface = "net$id"; + next if !$conf->{$iface}; next if !$conf->{"ipconfig$id"}; # indentation - network interfaces are inside an 'ethernets' hash @@ -320,9 +321,10 @@ sub nocloud_network { my $content = "version: 1\n" . "config:\n"; - my @ifaces = grep(/^net(\d+)$/, keys %$conf); - foreach my $iface (@ifaces) { - (my $id = $iface) =~ s/^net//; + my $max_nets = PVE::QemuServer::get_max_nets(); + for (my $id = 0; $id < $max_nets; $id++) { + my $iface = "net$id"; + next if !$conf->{$iface}; next if !$conf->{"ipconfig$id"}; # indentation - network interfaces are inside an 'ethernets' hash -- 2.20.1 _______________________________________________ pve-devel mailing list pve-devel@pve.proxmox.com https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel