From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id B12F560BCC for ; Thu, 10 Sep 2020 14:57:44 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 965351C573 for ; Thu, 10 Sep 2020 14:57:14 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id EB0251C544 for ; Thu, 10 Sep 2020 14:57:12 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id B154844AFC for ; Thu, 10 Sep 2020 14:57:12 +0200 (CEST) From: Dominik Csapak To: pve-devel@lists.proxmox.com Date: Thu, 10 Sep 2020 14:57:07 +0200 Message-Id: <20200910125711.28369-2-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20200910125711.28369-1-d.csapak@proxmox.com> References: <20200910125711.28369-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.122 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment KAM_LAZY_DOMAIN_SECURITY 1 Sending domain does not have any anti-forgery methods NO_DNS_FOR_FROM 0.379 Envelope sender has no MX or A DNS records RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_NONE 0.001 SPF: sender does not publish an SPF Record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [replicationconfig.pm] Subject: [pve-devel] [PATCH RFC guest-common 1/1] ReplicationConfig: transform schedules to include always hours X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 10 Sep 2020 12:57:44 -0000 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 --- 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