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 manager 3/4] api: backup/jobs: add comment field to jobs
Date: Wed, 10 Nov 2021 15:02:55 +0100	[thread overview]
Message-ID: <20211110140256.1863209-4-d.csapak@proxmox.com> (raw)
In-Reply-To: <20211110140256.1863209-1-d.csapak@proxmox.com>

and encode them with PVE::Tools::encode_text in the config

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 PVE/API2/Backup.pm | 14 +++++++++++++-
 PVE/Jobs/Plugin.pm | 22 ++++++++++++++++++++++
 PVE/Jobs/VZDump.pm |  1 +
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/PVE/API2/Backup.pm b/PVE/API2/Backup.pm
index 3fa2eba3..428f4cb3 100644
--- a/PVE/API2/Backup.pm
+++ b/PVE/API2/Backup.pm
@@ -168,6 +168,12 @@ __PACKAGE__->register_method({
 		description => "Enable or disable the job.",
 		default => '1',
 	    },
+	    comment => {
+		optional => 1,
+		type => 'string',
+		description => "Description for the Job.",
+		maxLength => 512,
+	    },
        }),
     },
     returns => { type => 'null' },
@@ -363,6 +369,12 @@ __PACKAGE__->register_method({
 		description => "Enable or disable the job.",
 		default => '1',
 	    },
+	    comment => {
+		optional => 1,
+		type => 'string',
+		description => "Description for the Job.",
+		maxLength => 512,
+	    },
        }),
     },
     returns => { type => 'null' },
@@ -417,7 +429,7 @@ __PACKAGE__->register_method({
 	    }
 
 	    foreach my $k (@$delete) {
-		if (!PVE::VZDump::option_exists($k)) {
+		if (!PVE::VZDump::option_exists($k) && $k ne 'comment') {
 		    raise_param_exc({ delete => "unknown option '$k'" });
 		}
 
diff --git a/PVE/Jobs/Plugin.pm b/PVE/Jobs/Plugin.pm
index 9cf7f98d..cc282850 100644
--- a/PVE/Jobs/Plugin.pm
+++ b/PVE/Jobs/Plugin.pm
@@ -30,6 +30,12 @@ my $defaultData = {
 	    type => 'string', format => 'pve-calendar-event',
 	    maxLength => 128,
 	},
+	comment => {
+	    optional => 1,
+	    type => 'string',
+	    description => "Description for the Job.",
+	    maxLength => 512,
+	},
     },
 };
 
@@ -47,6 +53,10 @@ sub parse_config {
 
 	$data->{id} = $id;
 	$data->{enabled}  //= 1;
+
+	if (defined($data->{comment})) {
+	    $data->{comment} = PVE::Tools::decode_text($data->{comment});
+	}
    }
 
    return $cfg;
@@ -67,6 +77,18 @@ sub encode_value {
     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
diff --git a/PVE/Jobs/VZDump.pm b/PVE/Jobs/VZDump.pm
index 87733e74..92b81147 100644
--- a/PVE/Jobs/VZDump.pm
+++ b/PVE/Jobs/VZDump.pm
@@ -25,6 +25,7 @@ sub options {
     my $options = {
 	enabled => { optional => 1 },
 	schedule => {},
+	comment => { optional => 1 },
     };
     foreach my $opt (keys %$props) {
 	if ($props->{$opt}->{optional}) {
-- 
2.30.2





  parent reply	other threads:[~2021-11-10 14:03 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-10 14:02 [pve-devel] [PATCH manager 0/4] followups for vzdump scheduling2 Dominik Csapak
2021-11-10 14:02 ` [pve-devel] [PATCH manager 1/4] Jobs/VZDump: encode/decode 'prune-backups' where needed Dominik Csapak
2021-11-10 14:02 ` [pve-devel] [PATCH manager 2/4] ui: dc/BackupEdit: use correct validation Dominik Csapak
2021-11-10 14:02 ` Dominik Csapak [this message]
2021-11-10 14:02 ` [pve-devel] [PATCH manager 4/4] ui: dc/Backup: add comment field and column Dominik Csapak
2021-11-10 17:18 ` [pve-devel] [PATCH manager 0/4] followups for vzdump scheduling2 Thomas Lamprecht
2021-11-10 20:37 ` [pve-devel] applied-series: " 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=20211110140256.1863209-4-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