From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <d.csapak@proxmox.com>
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 178577E572
 for <pve-devel@lists.proxmox.com>; Wed, 10 Nov 2021 15:03:29 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
 by firstgate.proxmox.com (Proxmox) with ESMTP id 0E1C91D801
 for <pve-devel@lists.proxmox.com>; Wed, 10 Nov 2021 15:02:59 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
 [94.136.29.106])
 (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 B75221D7E8
 for <pve-devel@lists.proxmox.com>; Wed, 10 Nov 2021 15:02:57 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
 by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 8E67A41F74
 for <pve-devel@lists.proxmox.com>; Wed, 10 Nov 2021 15:02:57 +0100 (CET)
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Wed, 10 Nov 2021 15:02:55 +0100
Message-Id: <20211110140256.1863209-4-d.csapak@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20211110140256.1863209-1-d.csapak@proxmox.com>
References: <20211110140256.1863209-1-d.csapak@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results:  0
 AWL 0.227 Adjusted score from AWL reputation of From: address
 BAYES_00                 -1.9 Bayes spam probability is 0 to 1%
 KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches 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. [plugin.pm, vzdump.pm, backup.pm]
Subject: [pve-devel] [PATCH manager 3/4] api: backup/jobs: add comment field
 to jobs
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, 
 <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Wed, 10 Nov 2021 14:03:29 -0000

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