manager.go 1.5 KB

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