collector.go 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. Copyright (c) 2015 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 history
  14. import (
  15. "context"
  16. "github.com/vmware/govmomi/property"
  17. "github.com/vmware/govmomi/vim25"
  18. "github.com/vmware/govmomi/vim25/methods"
  19. "github.com/vmware/govmomi/vim25/types"
  20. )
  21. type Collector struct {
  22. r types.ManagedObjectReference
  23. c *vim25.Client
  24. }
  25. func NewCollector(c *vim25.Client, ref types.ManagedObjectReference) *Collector {
  26. return &Collector{
  27. r: ref,
  28. c: c,
  29. }
  30. }
  31. // Reference returns the managed object reference of this collector
  32. func (c Collector) Reference() types.ManagedObjectReference {
  33. return c.r
  34. }
  35. // Client returns the vim25 client used by this collector
  36. func (c Collector) Client() *vim25.Client {
  37. return c.c
  38. }
  39. // Properties wraps property.DefaultCollector().RetrieveOne() and returns
  40. // properties for the specified managed object reference
  41. func (c Collector) Properties(ctx context.Context, r types.ManagedObjectReference, ps []string, dst interface{}) error {
  42. return property.DefaultCollector(c.c).RetrieveOne(ctx, r, ps, dst)
  43. }
  44. func (c Collector) Destroy(ctx context.Context) error {
  45. req := types.DestroyCollector{
  46. This: c.r,
  47. }
  48. _, err := methods.DestroyCollector(ctx, c.c, &req)
  49. return err
  50. }
  51. func (c Collector) Reset(ctx context.Context) error {
  52. req := types.ResetCollector{
  53. This: c.r,
  54. }
  55. _, err := methods.ResetCollector(ctx, c.c, &req)
  56. return err
  57. }
  58. func (c Collector) Rewind(ctx context.Context) error {
  59. req := types.RewindCollector{
  60. This: c.r,
  61. }
  62. _, err := methods.RewindCollector(ctx, c.c, &req)
  63. return err
  64. }
  65. func (c Collector) SetPageSize(ctx context.Context, maxCount int32) error {
  66. req := types.SetCollectorPageSize{
  67. This: c.r,
  68. MaxCount: maxCount,
  69. }
  70. _, err := methods.SetCollectorPageSize(ctx, c.c, &req)
  71. return err
  72. }