if ($id =~ m/^(\d+)-(\d+)$/) {
my ($guest, $jobnum) = (int($1), int($2));
- die "$msg (guest IDs < 100 are reseved)\n" if $guest < 100;
+ die "$msg (guest IDs < 100 are reserved)\n" if $guest < 100;
my $parsed_id = "$guest-$jobnum"; # use parsed integers
return wantarray ? ($guest, $jobnum, $parsed_id) : $parsed_id;
}
optional => 1,
},
schedule => {
- description => "Storage replication schedule. The format is a subset of `systemd` calender events.",
+ description => "Storage replication schedule. The format is a subset of `systemd` calendar events.",
type => 'string', format => 'pve-calendar-event',
maxLength => 128,
default => '*/15',
optional => 1,
},
+ source => {
+ description => "Source of the replication.",
+ type => 'string', format => 'pve-node',
+ optional => 1,
+ },
},
};
$data->{guest} = $guest;
$data->{jobnum} = $jobnum;
+ $data->{id} = $id;
$data->{comment} = PVE::Tools::decode_text($data->{comment})
if defined($data->{comment});
if defined($data->{comment});
}
- $class->SUPER::write_config($filename, $cfg);
+ return $class->SUPER::write_config($filename, $cfg);
}
sub new {
return undef;
}
+sub find_local_replication_job {
+ my ($cfg, $vmid, $target) = @_;
+
+ foreach my $id (keys %{$cfg->{ids}}) {
+ my $data = $cfg->{ids}->{$id};
+
+ return $data if $data->{type} eq 'local' &&
+ $data->{guest} == $vmid && $data->{target} eq $target;
+ }
+
+ return undef;
+}
+
+# switch local replication job target
+sub switch_replication_job_target {
+ my ($vmid, $old_target, $new_target) = @_;
+
+ my $transfer_job = sub {
+ my $cfg = PVE::ReplicationConfig->new();
+ my $jobcfg = find_local_replication_job($cfg, $vmid, $old_target);
+
+ return if !$jobcfg;
+
+ $jobcfg->{target} = $new_target;
+
+ $cfg->write();
+ };
+
+ lock($transfer_job);
+};
+
sub delete_job {
my ($jobid) = @_;
lock($code);
}
+sub remove_vmid_jobs {
+ my ($vmid) = @_;
+
+ my $code = sub {
+ my $cfg = __PACKAGE__->new();
+ foreach my $id (keys %{$cfg->{ids}}) {
+ delete $cfg->{ids}->{$id} if ($cfg->{ids}->{$id}->{guest} == $vmid);
+ }
+ $cfg->write();
+ };
+
+ lock($code);
+}
+
+sub swap_source_target_nolock {
+ my ($jobid) = @_;
+
+ my $cfg = __PACKAGE__->new();
+ my $job = $cfg->{ids}->{$jobid};
+ my $tmp = $job->{source};
+ $job->{source} = $job->{target};
+ $job->{target} = $tmp;
+ $cfg->write();
+
+ return $cfg->{ids}->{$jobid};
+}
+
package PVE::ReplicationConfig::Cluster;
use base qw(PVE::ReplicationConfig);
rate => { optional => 1 },
schedule => { optional => 1 },
remove_job => { optional => 1 },
+ source => { optional => 1 },
};
}