[pve-devel] [PATCH manager 3/4] api: backup/jobs: add comment field to jobs
Dominik Csapak
d.csapak at proxmox.com
Wed Nov 10 15:02:55 CET 2021
and encode them with PVE::Tools::encode_text in the config
Signed-off-by: Dominik Csapak <d.csapak at 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
More information about the pve-devel
mailing list