]> git.proxmox.com Git - pve-manager.git/commitdiff
api: backup/jobs: add comment field to jobs
authorDominik Csapak <d.csapak@proxmox.com>
Wed, 10 Nov 2021 14:02:55 +0000 (15:02 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 10 Nov 2021 15:11:42 +0000 (16:11 +0100)
and encode them with PVE::Tools::encode_text in the config

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
PVE/API2/Backup.pm
PVE/Jobs/Plugin.pm
PVE/Jobs/VZDump.pm

index 3fa2eba3c6f32a1e1e47f2e42fc4c43967ccce64..428f4cb390bd7a7199c163b02362725237e2ffc5 100644 (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'" });
                }
 
index 9cf7f98de1c5a5d66370368f073ff30bf305aec6..cc28285022a00ec7ef011be46f604fd8ce0a1274 100644 (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
index 87733e74f63ca7ae2ac251a0cca3429596ffd338..92b81147c49609f85da53bf140434cfc237711e7 100644 (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}) {