[pve-devel] [PATCH manager 2/2] PVE/API2/Tasks: add statusfilter to task list
Dominik Csapak
d.csapak at proxmox.com
Thu Jun 24 09:10:13 CEST 2021
similar to pbs. the 'errors' filter parameter still overrides this
Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
PVE/API2/Tasks.pm | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/PVE/API2/Tasks.pm b/PVE/API2/Tasks.pm
index 8df701e5..eca92715 100644
--- a/PVE/API2/Tasks.pm
+++ b/PVE/API2/Tasks.pm
@@ -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_get_status_type($task->{status});
+ return 1 if !$statusfilter->{$type};
+
return 1 if $count++ < $start;
return 1 if $limit <= 0;
--
2.20.1
More information about the pve-devel
mailing list