Signed-off-by: Fabian Ebner <f.eb...@proxmox.com>
---

Changes from v1:
    * iterate over values directly

 PVE/ReplicationConfig.pm | 20 +++++++++++---------
 1 file changed, 11 insertions(+), 9 deletions(-)

diff --git a/PVE/ReplicationConfig.pm b/PVE/ReplicationConfig.pm
index 65436ea..9dfb9da 100644
--- a/PVE/ReplicationConfig.pm
+++ b/PVE/ReplicationConfig.pm
@@ -228,23 +228,25 @@ sub find_local_replication_job {
     return undef;
 }
 
-# switch local replication job target
+# makes old_target the new source for all local jobs of this guest
+# makes new_target the target for the single local job with target old_target
 sub switch_replication_job_target {
     my ($vmid, $old_target, $new_target) = @_;
 
-    my $transfer_job = sub {
+    my $update_jobs = sub {
        my $cfg = PVE::ReplicationConfig->new();
-       my $jobcfg = find_local_replication_job($cfg, $vmid, $old_target);
-
-       return if !$jobcfg;
-
-       $jobcfg->{target} = $new_target;
+       foreach my $jobcfg (values %{$cfg->{ids}}) {
+           next if $jobcfg->{guest} ne $vmid;
+           next if $jobcfg->{type} ne 'local';
 
+           $jobcfg->{target} = $new_target if $jobcfg->{target} eq $old_target;
+           $jobcfg->{source} = $old_target;
+       }
        $cfg->write();
     };
 
-    lock($transfer_job);
-};
+    lock($update_jobs);
+}
 
 sub delete_job {
     my ($jobid) = @_;
-- 
2.20.1



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

Reply via email to