]> git.proxmox.com Git - pmg-api.git/commitdiff
api: tasks: add 'status' filter
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 24 Jun 2021 07:10:16 +0000 (09:10 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 28 Jun 2021 14:01:03 +0000 (16:01 +0200)
like in PVE/PBS

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
 [ Thomas: adapt to renamed PVE::Tools helper method ]
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/PMG/API2/Tasks.pm

index a369c2a7bc2c9d58ee20c3b9fb135dc2558b4156..598fb4d2389898b4d1afab23eaa33dce6324db8d 100644 (file)
@@ -58,6 +58,12 @@ __PACKAGE__->register_method({
                description => "Only list tasks until this UNIX epoch.",
                optional => 1,
            },
+           statusfilter => {
+               type => 'string',
+               format => 'pve-task-status-type-list',
+               optional => 1,
+               description => 'List of Task States that should be returned.',
+           },
        },
     },
     returns => {
@@ -88,6 +94,27 @@ __PACKAGE__->register_method({
        my $until = $param->{until};
        my $errors = $param->{errors};
 
+       my $statusfilter = {
+           ok => 1,
+           warning => 1,
+           error => 1,
+           unknown => 1,
+       };
+
+       if (defined($param->{statusfilter}) && !$errors) {
+           $statusfilter = {
+               ok => 0,
+               warning => 0,
+               error => 0,
+               unknown => 0,
+           };
+           for my $filter (PVE::Tools::split_list($param->{statusfilter})) {
+               $statusfilter->{lc($filter)} = 1 ;
+           }
+       } elsif ($errors) {
+           $statusfilter->{ok} = 0;
+       }
+
        my $count = 0;
        my $line;
 
@@ -98,11 +125,13 @@ __PACKAGE__->register_method({
                my $status = $5;
                if ((my $task = PVE::Tools::upid_decode($upid, 1))) {
                    return if $userfilter && $task->{user} !~ m/\Q$userfilter\E/i;
-                   return if $errors && $status && $status eq 'OK';
                    return if defined($since) && $task->{starttime} < $since;
                    return if defined($until) && $task->{starttime} > $until;
                    return if $typefilter && $task->{type} ne $typefilter;
 
+                   my $statustype = PVE::Tools::upid_normalize_status_type($status);
+                   return if !$statusfilter->{$statustype};
+
                    return if $count++ < $start;
                    return if $limit <= 0;