api: backup/jobs: add comment field to jobs

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

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
This commit is contained in:
Dominik Csapak 2021-11-10 15:02:55 +01:00 committed by Thomas Lamprecht
parent e177268741
commit 998b61fbff
3 changed files with 36 additions and 1 deletions

View File

@ -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'" });
}

View File

@ -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

View File

@ -25,6 +25,7 @@ sub options {
my $options = {
enabled => { optional => 1 },
schedule => {},
comment => { optional => 1 },
};
foreach my $opt (keys %$props) {
if ($props->{$opt}->{optional}) {