github.com/vmware/govmomi@v0.37.1/history/collector.go (about)

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