config: apply pending: code-style & readability improvements

among other things, avoid one indentation level by returning early
from the eval.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2024-03-10 18:26:52 +01:00
parent 3fde43d2ec
commit 7c0f763d0c

View File

@ -5201,21 +5201,21 @@ sub vmconfig_apply_pending {
if (defined($conf->{$opt}) && is_valid_drivename($opt)) { if (defined($conf->{$opt}) && is_valid_drivename($opt)) {
vmconfig_register_unused_drive($storecfg, $vmid, $conf, parse_drive($opt, $conf->{$opt})) vmconfig_register_unused_drive($storecfg, $vmid, $conf, parse_drive($opt, $conf->{$opt}))
} elsif (defined($conf->{pending}->{$opt}) && $opt =~ m/^net\d+$/) { } elsif (defined($conf->{pending}->{$opt}) && $opt =~ m/^net\d+$/) {
if($have_sdn) { return if !$have_sdn; # return from eval if SDN is not available
my $new_net = PVE::QemuServer::parse_net($conf->{pending}->{$opt});
if ($conf->{$opt}){
my $old_net = PVE::QemuServer::parse_net($conf->{$opt});
if (defined($old_net->{bridge}) && defined($old_net->{macaddr}) && ( my $new_net = PVE::QemuServer::parse_net($conf->{pending}->{$opt});
safe_string_ne($old_net->{bridge}, $new_net->{bridge}) || if ($conf->{$opt}) {
safe_string_ne($old_net->{macaddr}, $new_net->{macaddr}) my $old_net = PVE::QemuServer::parse_net($conf->{$opt});
)) {
PVE::Network::SDN::Vnets::del_ips_from_mac($old_net->{bridge}, $old_net->{macaddr}, $conf->{name}); if (defined($old_net->{bridge}) && defined($old_net->{macaddr}) && (
} safe_string_ne($old_net->{bridge}, $new_net->{bridge}) ||
} safe_string_ne($old_net->{macaddr}, $new_net->{macaddr})
#fixme: reuse ip if mac change && same bridge )) {
PVE::Network::SDN::Vnets::add_next_free_cidr($new_net->{bridge}, $conf->{name}, $new_net->{macaddr}, $vmid, undef, 1); PVE::Network::SDN::Vnets::del_ips_from_mac($old_net->{bridge}, $old_net->{macaddr}, $conf->{name});
}
} }
#fixme: reuse ip if mac change && same bridge
PVE::Network::SDN::Vnets::add_next_free_cidr($new_net->{bridge}, $conf->{name}, $new_net->{macaddr}, $vmid, undef, 1);
} }
}; };
if (my $err = $@) { if (my $err = $@) {