[pve-devel] [PATCH RFC guest-common 1/1] ReplicationConfig: transform schedules to include always hours
Dominik Csapak
d.csapak at proxmox.com
Thu Sep 10 14:57:07 CEST 2020
systemd and pbs require the hour for schedules. so to be compatible
in the future, transform all schedules that omit the hour to '*:MINSPEC'
(where MINSPEC is the given spec for the minutes)
we do this now, so we can drop the 'minutes only' syntax in the future
sometimes
also adapt the default value
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
PVE/ReplicationConfig.pm | 31 ++++++++++++++++++++++++++++++-
1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/PVE/ReplicationConfig.pm b/PVE/ReplicationConfig.pm
index 66ef842..842aa63 100644
--- a/PVE/ReplicationConfig.pm
+++ b/PVE/ReplicationConfig.pm
@@ -76,7 +76,7 @@ my $defaultData = {
description => "Storage replication schedule. The format is a subset of `systemd` calendar events.",
type => 'string', format => 'pve-calendar-event',
maxLength => 128,
- default => '*/15',
+ default => '*:*/15',
optional => 1,
},
source => {
@@ -115,6 +115,31 @@ sub get_unique_target_id {
die "please overwrite in subclass";
}
+# to have better compatibility with PBS/Systemd, we write
+# out 'minute' only calendar events with hours as *
+my $transform_calendar_event = sub {
+ my $event = shift;
+
+ my @parts = split(/\s+/, $event);
+ my $utc = (@parts && uc($parts[-1]) eq 'UTC');
+ pop @parts if $utc;
+
+ return $event if @parts < 1;
+ my $potential_time_spec = pop @parts;
+
+ # if it contains an : it already has an hour,
+ # and if it contains any charactor from a-z it is a weekday spec
+ if ($potential_time_spec !~ m/:/ && $potential_time_spec !~ m/[a-zA-Z]/) {
+ $potential_time_spec = "*:" . $potential_time_spec;
+ }
+
+ push @parts, $potential_time_spec;
+
+ push @parts, 'UTC' if $utc;
+
+ return join(' ', @parts);
+};
+
sub parse_config {
my ($class, $filename, $raw) = @_;
@@ -161,6 +186,10 @@ sub write_config {
my $tid = $plugin->get_unique_target_id($data);
my $vmid = $data->{guest};
+ if (defined($data->{schedule})) {
+ $data->{schedule} = $transform_calendar_event->($data->{schedule});
+ }
+
die "property 'guest' has wrong value\n" if $id !~ m/^\Q$vmid\E-/;
die "replication job for guest '$vmid' to target '$tid' already exists\n"
if defined($target_hash->{$vmid}->{$tid});
--
2.20.1
More information about the pve-devel
mailing list