[pve-devel] [PATCH v2 qemu-server 9/9] ipam : add destroy vm support

Alexandre Derumier aderumier at odiso.com
Mon Jul 12 00:47:07 CEST 2021


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuServer.pm | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 7d34a74..f6f14a6 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2215,6 +2215,8 @@ sub destroy_vm {
     };
     PVE::QemuConfig->foreach_volume_full($conf, $include_opts, $remove_owned_drive);
 
+    PVE::QemuServer::vmconfig_destroy_nets_ip($conf);
+
     for my $snap (values %{$conf->{snapshots}}) {
 	next if !defined($snap->{vmstate});
 	my $drive = PVE::QemuConfig->parse_volume('vmstate', $snap->{vmstate}, 1);
@@ -4922,7 +4924,6 @@ sub vmconfig_update_net_ip {
     $ipconfig->{gw6} = $net->{gw6} if $net->{gw6};
     my $value = PVE::QemuServer::print_ipconfig($ipconfig);
     $conf->{pending}->{$ipconfigid} = $value;
-
 }
 
 sub vmconfig_delete_net_ip {
@@ -5028,6 +5029,37 @@ sub vmconfig_delete_pendingnet_ip {
     }
 }
 
+sub vmconfig_destroy_nets_ip {
+    my ($conf) = @_;
+
+    foreach my $snapname (keys %{$conf->{snapshots}}) {
+	my $snapconf = $conf->{snapshots}->{$snapname};
+	foreach my $opt (keys %{$snapconf}) {
+	    next if $opt !~ m/^net(\d+)$/;
+	    my $hostname = $snapconf->{name};
+	    my $net = PVE::QemuServer::parse_net($snapconf->{$opt});
+	    eval {
+		PVE::QemuServer::Ipam::delete_net_ip(4, $net, $hostname);
+	    };
+	    eval {
+		PVE::QemuServer::Ipam::delete_net_ip(6, $net, $hostname);
+	    };
+        }
+    }
+
+    foreach my $opt (keys %{$conf}) {
+	next if $opt !~ m/^net(\d+)$/;
+	my $net = PVE::QemuServer::parse_net($conf->{$opt});
+	my $hostname = $conf->{name};
+	eval {
+	    PVE::QemuServer::Ipam::delete_net_ip(4, $net, $hostname);
+	};
+	eval {
+	    PVE::QemuServer::Ipam::delete_net_ip(6, $net, $hostname);
+	};
+    }
+}
+
 sub vmconfig_update_net {
     my ($storecfg, $conf, $hotplug, $vmid, $opt, $value, $arch, $machine_type) = @_;
 
@@ -6121,6 +6153,7 @@ my $restore_cleanup_oldconf = sub {
 	    }
 	}
     }
+
 };
 
 # Helper to parse vzdump backup device hints
-- 
2.30.2





More information about the pve-devel mailing list