[pve-devel] [PATCH manager 2/2] task index: allow filtering by task type

Fabian Grünbichler f.gruenbichler at proxmox.com
Fri Jan 4 13:43:53 CET 2019


On Fri, Dec 28, 2018 at 10:34:55AM +0100, Wolfgang Bumiller wrote:
> On Wed, Dec 19, 2018 at 09:37:21AM +0100, Fabian Grünbichler wrote:
> > convenience filter if caller is only interested in certain actions
> > 
> > Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
> > ---
> >  PVE/API2/Tasks.pm | 8 ++++++++
> >  1 file changed, 8 insertions(+)
> > 
> > diff --git a/PVE/API2/Tasks.pm b/PVE/API2/Tasks.pm
> > index 95a13c56..dfa3cc04 100644
> > --- a/PVE/API2/Tasks.pm
> > +++ b/PVE/API2/Tasks.pm
> > @@ -49,6 +49,11 @@ __PACKAGE__->register_method({
> >  		optional => 1,
> >  		description => "Only list tasks from this user.",
> >  	    },
> > +	    typefilter => {
> > +		type => 'string',
> > +		optional => 1,
> > +		description => 'Only list tasks of this type (e.g., vzstart, vzdump).',
> > +	    },
> >  	    vmid => get_standard_option('pve-vmid', {
> >  		description => "Only list tasks for this VM.",
> >  		optional => 1,
> > @@ -99,6 +104,7 @@ __PACKAGE__->register_method({
> >  	my $start = $param->{start} // 0;
> >  	my $limit = $param->{limit} // 50;
> >  	my $userfilter = $param->{userfilter};
> > +	my $typefilter = $param->{typefilter};
> >  	my $errors = $param->{errors} // 0;
> >  	my $include_active = $param->{active} // 0;
> >  
> > @@ -113,6 +119,8 @@ __PACKAGE__->register_method({
> >  	    return 1 if $userfilter && $task->{user} !~ m/\Q$userfilter\E/i;
> >  	    return 1 if !($auditor || $user eq $task->{user});
> >  
> > +	    return 1 if $typefilter && $task->{type} ne $typefilter;
> 
> $task->{type} is defined as optional in the return schema so we should
> probably check it for defined()ness before using it?

I think the return schema is wrong here - type is initialized in
fork_worker if undef, and the decoder used here only decodes upids with
a type of at least one character ;)

v2 with updated return schema? most of the other fields are not optional
either AFAICT.. maybe they were at some point in the past?

> 
> > +
> >  	    return 1 if $errors && $task->{status} && $task->{status} eq 'OK';
> >  	    return 1 if $param->{vmid} && (!$task->{id} || $task->{id} ne $param->{vmid});
> >  
> > -- 
> > 2.19.2




More information about the pve-devel mailing list