public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Hannes Laimer <h.laimer@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-cluster 1/3] jobs: move base plugin from pve-manager
Date: Tue, 22 Mar 2022 07:34:10 +0000	[thread overview]
Message-ID: <20220322073412.30562-2-h.laimer@proxmox.com> (raw)
In-Reply-To: <20220322073412.30562-1-h.laimer@proxmox.com>

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
 data/PVE/Jobs/Makefile     |  11 ++++
 data/PVE/Jobs/Plugin.pm    | 101 +++++++++++++++++++++++++++++++++++++
 data/PVE/Makefile          |   2 +-
 debian/pve-cluster.install |   1 +
 4 files changed, 114 insertions(+), 1 deletion(-)
 create mode 100644 data/PVE/Jobs/Makefile
 create mode 100644 data/PVE/Jobs/Plugin.pm

diff --git a/data/PVE/Jobs/Makefile b/data/PVE/Jobs/Makefile
new file mode 100644
index 0000000..4320369
--- /dev/null
+++ b/data/PVE/Jobs/Makefile
@@ -0,0 +1,11 @@
+PVEDIR=${DESTDIR}/usr/share/perl5/PVE
+
+SOURCES=Plugin.pm
+
+.PHONY: install
+install: ${SOURCES}
+	install -d -m 0755 ${PVEDIR}/Jobs
+	for f in ${SOURCES}; do install -D -m 0644 $$f ${PVEDIR}/Jobs/$$f; done
+
+.PHONY: clean
+clean:
diff --git a/data/PVE/Jobs/Plugin.pm b/data/PVE/Jobs/Plugin.pm
new file mode 100644
index 0000000..6098360
--- /dev/null
+++ b/data/PVE/Jobs/Plugin.pm
@@ -0,0 +1,101 @@
+package PVE::Jobs::Plugin;
+
+use strict;
+use warnings;
+
+use PVE::Cluster qw(cfs_register_file);
+
+use base qw(PVE::SectionConfig);
+
+cfs_register_file(
+    'jobs.cfg',
+     sub { __PACKAGE__->parse_config(@_); },
+     sub { __PACKAGE__->write_config(@_); }
+);
+
+my $defaultData = {
+    propertyList => {
+	type => { description => "Section type." },
+	id => {
+	    description => "The ID of the VZDump job.",
+	    type => 'string',
+	    format => 'pve-configid',
+	    maxLength => 64,
+	},
+	enabled => {
+	    description => "Determines if the job is enabled.",
+	    type => 'boolean',
+	    default => 1,
+	    optional => 1,
+	},
+	schedule => {
+	    description => "Backup schedule. The format is a subset of `systemd` calendar events.",
+	    type => 'string', format => 'pve-calendar-event',
+	    maxLength => 128,
+	},
+	comment => {
+	    optional => 1,
+	    type => 'string',
+	    description => "Description for the Job.",
+	    maxLength => 512,
+	},
+    },
+};
+
+sub private {
+    return $defaultData;
+}
+
+sub parse_config {
+    my ($class, $filename, $raw) = @_;
+
+    my $cfg = $class->SUPER::parse_config($filename, $raw);
+
+    foreach my $id (sort keys %{$cfg->{ids}}) {
+	my $data = $cfg->{ids}->{$id};
+
+	$data->{id} = $id;
+	$data->{enabled}  //= 1;
+
+	if (defined($data->{comment})) {
+	    $data->{comment} = PVE::Tools::decode_text($data->{comment});
+	}
+   }
+
+   return $cfg;
+}
+
+# call the plugin specific decode/encode code
+sub decode_value {
+    my ($class, $type, $key, $value) = @_;
+
+    my $plugin = __PACKAGE__->lookup($type);
+    return $plugin->decode_value($type, $key, $value);
+}
+
+sub encode_value {
+    my ($class, $type, $key, $value) = @_;
+
+    my $plugin = __PACKAGE__->lookup($type);
+    return $plugin->encode_value($type, $key, $value);
+}
+
+sub write_config {
+    my ($class, $filename, $cfg) = @_;
+
+    for my $job (values $cfg->{ids}->%*) {
+	if (defined($job->{comment})) {
+	    $job->{comment} = PVE::Tools::encode_text($job->{comment});
+	}
+    }
+
+    $class->SUPER::write_config($filename, $cfg);
+}
+
+sub run {
+    my ($class, $cfg) = @_;
+    # implement in subclass
+    die "not implemented";
+}
+
+1;
diff --git a/data/PVE/Makefile b/data/PVE/Makefile
index 8ea5383..eecf9f9 100644
--- a/data/PVE/Makefile
+++ b/data/PVE/Makefile
@@ -10,7 +10,7 @@ PVE_VENDORARCH=${DESTDIR}/${PERL_VENDORARCH}/auto/PVE/IPCC
 
 PERL_DOC_INC_DIRS:=..
 
-SUBDIRS=Cluster CLI API2
+SUBDIRS=Cluster CLI API2 Jobs
 SOURCES=IPCC.pm Cluster.pm Corosync.pm RRD.pm DataCenterConfig.pm SSHInfo.pm
 
 all:
diff --git a/debian/pve-cluster.install b/debian/pve-cluster.install
index f66cd06..eb15b55 100644
--- a/debian/pve-cluster.install
+++ b/debian/pve-cluster.install
@@ -3,6 +3,7 @@ usr/bin/create_pmxcfs_db
 usr/bin/pmxcfs
 usr/lib/
 usr/share/man/man8/pmxcfs.8
+usr/share/perl5/PVE/Jobs/Plugin.pm
 usr/share/perl5/PVE/Cluster.pm
 usr/share/perl5/PVE/Cluster/IPCConst.pm
 usr/share/perl5/PVE/IPCC.pm
-- 
2.30.2





  reply	other threads:[~2022-03-22  7:35 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-22  7:34 [pve-devel] [PATCH-SERIES] move jobs " Hannes Laimer
2022-03-22  7:34 ` Hannes Laimer [this message]
     [not found]   ` <<20220322073412.30562-2-h.laimer@proxmox.com>
2022-04-08  7:40     ` [pve-devel] [PATCH pve-cluster 1/3] jobs: move base plugin " Fabian Grünbichler
2022-03-22  7:34 ` [pve-devel] [PATCH pve-guest-common 2/3] jobs: move VZDump " Hannes Laimer
2022-04-08  7:40   ` Fabian Grünbichler
2022-03-22  7:34 ` [pve-devel] [PATCH pve-manager 3/3] jobs: move to pve-cluster and pve-guest-common Hannes Laimer
2022-04-08  7:44 ` [pve-devel] [PATCH-SERIES] move jobs from pve-manager Fabian Grünbichler

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=20220322073412.30562-2-h.laimer@proxmox.com \
    --to=h.laimer@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