]> git.proxmox.com Git - pve-guest-common.git/blobdiff - PVE/AbstractConfig.pm
Add function: swap source and target in replication config
[pve-guest-common.git] / PVE / AbstractConfig.pm
index 08cbb6a43fc4e198d0e54f7fb41ab98a20966161..347398854e1cbb0e585d8aaa5eff2ba056e81e7c 100644 (file)
@@ -8,6 +8,9 @@ use PVE::INotify;
 use PVE::Cluster;
 use PVE::Storage;
 
+use PVE::ReplicationConfig;
+use PVE::Replication;
+
 my $nodename = PVE::INotify::nodename();
 
 # Printable string, currently either "VM" or "CT"
@@ -196,7 +199,7 @@ sub has_feature {
 # $cleanup: for cleanup - simply ignores volumes without replicate feature
 # $norerr: never raise exceptions - return undef instead
 sub get_replicatable_volumes {
-    my ($class, $storecfg, $conf, $cleanup, $noerr) = @_;
+    my ($class, $storecfg, $vmid, $conf, $cleanup, $noerr) = @_;
 
     die "implement me - abstract method\n";
 }
@@ -477,9 +480,13 @@ sub snapshot_delete {
 
     my $prepare = 1;
 
-    my $snap;
     my $unused = [];
 
+    my $conf = $class->load_config($vmid);
+    my $snap = $conf->{snapshots}->{$snapname};
+
+    die "snapshot '$snapname' does not exist\n" if !defined($snap);
+
     $class->set_lock($vmid, 'snapshot-delete')
        if (!$drivehash); # doesn't already have a 'snapshot' lock
 
@@ -592,6 +599,17 @@ sub snapshot_rollback {
        return $res;
     };
 
+    my $repl_conf = PVE::ReplicationConfig->new();
+    if ($repl_conf->check_for_existing_jobs($vmid, 1)) {
+       # remove all replication snapshots
+       my $volumes = $class->get_replicatable_volumes($storecfg, $vmid, $conf, 1);
+       my $sorted_volids = [ sort keys %$volumes ];
+
+       # remove all local replication snapshots (jobid => undef)
+       my $logfunc = sub { my $line = shift; chomp $line; print "$line\n"; };
+       PVE::Replication::prepare($storecfg, $sorted_volids, undef, 0, undef, $logfunc);
+    }
+    
     my $snap = &$get_snapshot_config();
 
     $class->__snapshot_foreach_volume($snap, sub {