task_manager.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. Copyright (c) 2017 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 simulator
  14. import (
  15. "sync"
  16. "github.com/vmware/govmomi/object"
  17. "github.com/vmware/govmomi/simulator/esx"
  18. "github.com/vmware/govmomi/simulator/vpx"
  19. "github.com/vmware/govmomi/vim25/mo"
  20. "github.com/vmware/govmomi/vim25/types"
  21. )
  22. var recentTaskMax = 200 // the VC limit
  23. type TaskManager struct {
  24. mo.TaskManager
  25. sync.Mutex
  26. }
  27. func NewTaskManager(ref types.ManagedObjectReference) object.Reference {
  28. s := &TaskManager{}
  29. s.Self = ref
  30. if Map.IsESX() {
  31. s.Description = esx.Description
  32. } else {
  33. s.Description = vpx.Description
  34. }
  35. Map.AddHandler(s)
  36. return s
  37. }
  38. func (m *TaskManager) PutObject(obj mo.Reference) {
  39. ref := obj.Reference()
  40. if ref.Type != "Task" {
  41. return
  42. }
  43. m.Lock()
  44. recent := append(m.RecentTask, ref)
  45. if len(recent) > recentTaskMax {
  46. recent = recent[1:]
  47. }
  48. Map.Update(m, []types.PropertyChange{{Name: "recentTask", Val: recent}})
  49. m.Unlock()
  50. }
  51. func (*TaskManager) RemoveObject(types.ManagedObjectReference) {}
  52. func (*TaskManager) UpdateObject(mo.Reference, []types.PropertyChange) {}