github.com/vmware/govmomi@v0.37.1/task/manager.go (about)

     1  /*
     2  Copyright (c) 2014-2022 VMware, Inc. All Rights Reserved.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package task
    18  
    19  import (
    20  	"context"
    21  
    22  	"github.com/vmware/govmomi/vim25"
    23  	"github.com/vmware/govmomi/vim25/methods"
    24  	"github.com/vmware/govmomi/vim25/types"
    25  )
    26  
    27  type Manager struct {
    28  	r types.ManagedObjectReference
    29  	c *vim25.Client
    30  }
    31  
    32  // NewManager creates a new task manager
    33  func NewManager(c *vim25.Client) *Manager {
    34  	m := Manager{
    35  		r: *c.ServiceContent.TaskManager,
    36  		c: c,
    37  	}
    38  
    39  	return &m
    40  }
    41  
    42  // Reference returns the task.Manager MOID
    43  func (m Manager) Reference() types.ManagedObjectReference {
    44  	return m.r
    45  }
    46  
    47  // CreateCollectorForTasks returns a task history collector, a specialized
    48  // history collector that gathers TaskInfo data objects.
    49  func (m Manager) CreateCollectorForTasks(ctx context.Context, filter types.TaskFilterSpec) (*HistoryCollector, error) {
    50  	req := types.CreateCollectorForTasks{
    51  		This:   m.r,
    52  		Filter: filter,
    53  	}
    54  
    55  	res, err := methods.CreateCollectorForTasks(ctx, m.c, &req)
    56  	if err != nil {
    57  		return nil, err
    58  	}
    59  
    60  	return newHistoryCollector(m.c, res.Returnval), nil
    61  }