public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH RFC guest-common 1/1] ReplicationConfig: transform schedules to include always hours
Date: Thu, 10 Sep 2020 14:57:07 +0200	[thread overview]
Message-ID: <20200910125711.28369-2-d.csapak@proxmox.com> (raw)
In-Reply-To: <20200910125711.28369-1-d.csapak@proxmox.com>

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@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





  reply	other threads:[~2020-09-10 12:57 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-10 12:57 [pve-devel] [PATCH RFC guest-common/manager/docs] adapt calendar events to pbs/systemd style Dominik Csapak
2020-09-10 12:57 ` Dominik Csapak [this message]
2020-09-10 12:57 ` [pve-devel] [PATCH RFC manager 1/2] ui: adapt/optimize calendar event examples Dominik Csapak
2020-09-10 12:57 ` [pve-devel] [PATCH RFC manager 2/2] ui: grid/Replication: change the default format of schedule text Dominik Csapak
2020-09-10 12:57 ` [pve-devel] [PATCH docs 1/2] pvesr: fix calendar event examples Dominik Csapak
2020-09-10 12:57 ` [pve-devel] [PATCH RFC docs 2/2] pvesr: modify examples to fit with pbs style Dominik Csapak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200910125711.28369-2-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal