From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager 3/5] api: cluster: add jobs/schedule-analyze api call
Date: Thu, 11 Nov 2021 12:07:07 +0100 [thread overview]
Message-ID: <20211111110709.633855-7-d.csapak@proxmox.com> (raw)
In-Reply-To: <20211111110709.633855-1-d.csapak@proxmox.com>
a simple api call to simulate calendar event triggers
takes a schedule, an optional number (default 10), an optional starttime
(default 'now') and returns a list with unix timestamps, as well as
humanly readable utc timestamps.
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
PVE/API2/Cluster.pm | 5 ++
PVE/API2/Cluster/Jobs.pm | 107 ++++++++++++++++++++++++++++++++++++++
PVE/API2/Cluster/Makefile | 1 +
3 files changed, 113 insertions(+)
create mode 100644 PVE/API2/Cluster/Jobs.pm
diff --git a/PVE/API2/Cluster.pm b/PVE/API2/Cluster.pm
index 3b918e55..205f9883 100644
--- a/PVE/API2/Cluster.pm
+++ b/PVE/API2/Cluster.pm
@@ -25,6 +25,7 @@ use PVE::API2::ACMEPlugin;
use PVE::API2::Backup;
use PVE::API2::Cluster::BackupInfo;
use PVE::API2::Cluster::Ceph;
+use PVE::API2::Cluster::Jobs;
use PVE::API2::Cluster::MetricServer;
use PVE::API2::ClusterConfig;
use PVE::API2::Firewall::Cluster;
@@ -84,6 +85,10 @@ __PACKAGE__->register_method ({
path => 'ceph',
});
+__PACKAGE__->register_method ({
+ subclass => "PVE::API2::Cluster::Jobs",
+ path => 'jobs',
+});
if ($have_sdn) {
__PACKAGE__->register_method ({
subclass => "PVE::API2::Network::SDN",
diff --git a/PVE/API2/Cluster/Jobs.pm b/PVE/API2/Cluster/Jobs.pm
new file mode 100644
index 00000000..79a6e85e
--- /dev/null
+++ b/PVE/API2/Cluster/Jobs.pm
@@ -0,0 +1,107 @@
+package PVE::API2::Cluster::Jobs;
+
+use strict;
+use warnings;
+
+use PVE::RESTHandler;
+use PVE::CalendarEvent;
+
+use base qw(PVE::RESTHandler);
+
+__PACKAGE__->register_method({
+ name => 'index',
+ path => '',
+ method => 'GET',
+ description => "Index for jobs related endpoints.",
+ parameters => {
+ additionalProperties => 0,
+ properties => {},
+ },
+ returns => {
+ type => 'array',
+ description => 'Directory index.',
+ items => {
+ type => "object",
+ properties => {
+ subdir => {
+ type => 'string',
+ description => 'API sub-directory endpoint',
+ },
+ },
+ },
+ links => [ { rel => 'child', href => "{subdir}" } ],
+ },
+ code => sub {
+ return [
+ { subdir => 'schedule-analyze' },
+ ];
+ }});
+
+__PACKAGE__->register_method({
+ name => 'schedule-analyze',
+ path => 'schedule-analyze',
+ method => 'GET',
+ description => "Returns a list of future schedule runtimes.",
+ permissions => { user => 'all' },
+ parameters => {
+ additionalProperties => 0,
+ properties => {
+ schedule => {
+ description => "Backup schedule. The format is a subset of `systemd` calendar events.",
+ type => 'string', format => 'pve-calendar-event',
+ maxLength => 128,
+ },
+ starttime => {
+ description => "UNIX timestamp to start the calculation from. Defaults to the current time.",
+ optional => 1,
+ type => 'integer',
+ },
+ number => {
+ description => "Number of timestamps to return.",
+ optional => 1,
+ type => 'integer',
+ minimum => 1,
+ maximum => 100,
+ default => 10,
+ },
+ },
+ },
+ returns => {
+ type => 'array',
+ description => 'Contains the guest objects.',
+ items => {
+ type => 'object',
+ properties => {
+ timestamp => {
+ type => 'integer',
+ description => 'UNIX timestamp for the run.',
+ },
+ utc => {
+ type => 'string',
+ description => "UTC timestamp for the run.",
+ },
+ },
+ },
+ },
+ code => sub {
+ my ($param) = @_;
+
+ my $starttime = $param->{starttime} // time();
+ my $number = $param->{number} // 10;
+ my $schedule = $param->{schedule};
+
+ my $result = [];
+
+ my $event = PVE::CalendarEvent::parse_calendar_event($schedule);
+
+ for (my $count = 0; $count < $number; $count++) {
+ my $next = PVE::CalendarEvent::compute_next_event($event, $starttime);
+ push @$result, {
+ timestamp => $next,
+ utc => scalar(gmtime($next)),
+ };
+ $starttime = $next;
+ }
+
+ return $result;
+ }});
diff --git a/PVE/API2/Cluster/Makefile b/PVE/API2/Cluster/Makefile
index 742a1007..8d306507 100644
--- a/PVE/API2/Cluster/Makefile
+++ b/PVE/API2/Cluster/Makefile
@@ -5,6 +5,7 @@ include ../../../defines.mk
PERLSOURCE= \
BackupInfo.pm \
MetricServer.pm \
+ Jobs.pm \
Ceph.pm
all:
--
2.30.2
next prev parent reply other threads:[~2021-11-11 11:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-11 11:07 [pve-devel] [PATCH docs/manager] add pvescheduler docs, improve vzdump job gui Dominik Csapak
2021-11-11 11:07 ` [pve-devel] [PATCH docs 1/3] refactor calendar events into appendix Dominik Csapak
2021-11-11 17:03 ` [pve-devel] applied-series: " Thomas Lamprecht
2021-11-11 11:07 ` [pve-devel] [PATCH docs 2/3] vzdump: change vzdump.cron to pvescheduler Dominik Csapak
2021-11-11 11:07 ` [pve-devel] [PATCH docs 3/3] add pvescheduler docs and manpage Dominik Csapak
2021-11-11 11:07 ` [pve-devel] [PATCH manager 1/5] ui: dc/Backup: never show id input field, autogenerate id Dominik Csapak
2021-11-11 11:07 ` [pve-devel] [PATCH manager 2/5] ui: dc/Backup: fix comment sort Dominik Csapak
2021-11-11 11:07 ` Dominik Csapak [this message]
2021-11-11 11:07 ` [pve-devel] [PATCH manager 4/5] ui: dc/Backup: add schedule simulator button Dominik Csapak
2021-11-11 11:07 ` [pve-devel] [PATCH manager 5/5] remove pvescheduler manpage generation Dominik Csapak
2021-11-11 20:04 ` [pve-devel] applied-series: [PATCH docs/manager] add pvescheduler docs, improve vzdump job gui Thomas Lamprecht
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=20211111110709.633855-7-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal