]> git.proxmox.com Git - pve-manager.git/commitdiff
api: tasks: add 'statusfilter' to task list endpoint
authorDominik Csapak <d.csapak@proxmox.com>
Thu, 24 Jun 2021 07:10:13 +0000 (09:10 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Mon, 28 Jun 2021 15:51:25 +0000 (17:51 +0200)
Similar to PBS. The 'errors' filter parameter still takes precedence
(overrides this)

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>
PVE/API2/Tasks.pm

index 8df701e5264c83308370ce4a58efccaee940e8c8..085f9b95530464ae3d3921507b07b3d6be6443b9 100644 (file)
@@ -100,6 +100,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 => {
@@ -140,6 +146,26 @@ __PACKAGE__->register_method({
        my $source = $param->{source} // 'archive';
        my $since = $param->{since};
        my $until = $param->{until};
+       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;
@@ -154,12 +180,14 @@ __PACKAGE__->register_method({
 
            return 1 if $typefilter && $task->{type} ne $typefilter;
 
-           return 1 if $errors && $task->{status} && $task->{status} eq 'OK';
            return 1 if $param->{vmid} && (!$task->{id} || $task->{id} ne $param->{vmid});
 
            return 1 if defined($since) && $task->{starttime} < $since;
            return 1 if defined($until) && $task->{starttime} > $until;
 
+           my $type = PVE::Tools::upid_normalize_status_type($task->{status});
+           return 1 if !$statusfilter->{$type};
+
            return 1 if $count++ < $start;
            return 1 if $limit <= 0;