[pve-devel] [PATCH v2 qemu-server 6/9] ipam : add snapshot rollback support

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


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

diff --git a/PVE/QemuConfig.pm b/PVE/QemuConfig.pm
index 7ee8876..6627e2f 100644
--- a/PVE/QemuConfig.pm
+++ b/PVE/QemuConfig.pm
@@ -12,6 +12,7 @@ use PVE::QemuServer::Helpers;
 use PVE::QemuServer::Monitor qw(mon_cmd);
 use PVE::QemuServer;
 use PVE::QemuServer::Machine;
+use PVE::QemuServer::Ipam;
 use PVE::Storage;
 use PVE::Tools;
 use PVE::Format qw(render_bytes render_duration);
@@ -397,6 +398,7 @@ sub __snapshot_rollback_hook {
     if ($prepare) {
 	# we save the machine of the current config
 	$data->{oldmachine} = $conf->{machine};
+	$data->{oldconf} = $conf;
     } else {
 	# if we have a 'runningmachine' entry in the snapshot we use that
 	# for the forcemachine parameter, else we use the old logic
@@ -424,6 +426,36 @@ sub __snapshot_rollback_hook {
 	    # re-initializing its random number generator
 	    $conf->{vmgenid} = PVE::QemuServer::generate_uuid();
 	}
+
+	my $oldconf = $data->{oldconf};
+	my $pendingoldconf = $oldconf->{pending};
+
+	#remove ip from current pending net interfaces
+	foreach my $opt (keys %$pendingoldconf) {
+	    next if $opt !~ m/^net(\d+)$/;
+	    my $net = PVE::QemuServer::parse_net($pendingoldconf->{$opt});
+	    PVE::QemuServer::vmconfig_delete_net_ip($conf, $net);
+	}
+
+	#remove ip from net current conf
+	foreach my $opt (keys %$oldconf) {
+	    next if $opt !~ m/^net(\d+)$/;
+	    my $net = PVE::QemuServer::parse_net($oldconf->{$opt});
+	    PVE::QemuServer::vmconfig_delete_net_ip($oldconf, $net);
+	}
+
+	#update ipam description/dns
+	foreach my $opt (keys %$conf) {
+	    next if $opt !~ m/^net(\d+)$/;
+	    my $netid = $1;
+	    my $net = PVE::QemuServer::parse_net($conf->{$opt});
+	    my $hostname = $conf->{name};
+	    my $oldhostname = $oldconf->{name};
+	    PVE::QemuServer::Ipam::update_net_ip(4,$net, $hostname, $oldhostname, "vm:$vmid net:$opt");
+	    PVE::QemuServer::Ipam::update_net_ip(6,$net, $hostname, $oldhostname, "vm:$vmid net:$opt");
+
+	    $conf->{$opt} = PVE::QemuServer::print_net($net);
+	}
     }
 
     return;
-- 
2.30.2





More information about the pve-devel mailing list