Documentation ¶
Index ¶
- func Wait(ctx context.Context, c *Collector, obj types.ManagedObjectReference, ...) error
- func WaitForUpdates(ctx context.Context, c *Collector, filter *WaitFilter, ...) error
- type Collector
- func (p *Collector) CancelWaitForUpdates(ctx context.Context) error
- func (p *Collector) Create(ctx context.Context) (*Collector, error)
- func (p *Collector) CreateFilter(ctx context.Context, req types.CreateFilter) error
- func (p *Collector) Destroy(ctx context.Context) error
- func (p Collector) Reference() types.ManagedObjectReference
- func (p *Collector) Retrieve(ctx context.Context, objs []types.ManagedObjectReference, ps []string, ...) error
- func (p *Collector) RetrieveOne(ctx context.Context, obj types.ManagedObjectReference, ps []string, ...) error
- func (p *Collector) RetrieveProperties(ctx context.Context, req types.RetrieveProperties) (*types.RetrievePropertiesResponse, error)
- func (p *Collector) RetrieveWithFilter(ctx context.Context, objs []types.ManagedObjectReference, ps []string, ...) error
- func (p *Collector) WaitForUpdates(ctx context.Context, version string, opts ...*types.WaitOptions) (*types.UpdateSet, error)
- type Filter
- func (f Filter) Keys() []string
- func (f Filter) MatchAnyObjectContent(objects []types.ObjectContent) []types.ManagedObjectReference
- func (f Filter) MatchAnyPropertyList(props []types.DynamicProperty) bool
- func (f Filter) MatchObjectContent(objects []types.ObjectContent) []types.ManagedObjectReference
- func (f Filter) MatchProperty(prop types.DynamicProperty) bool
- func (f Filter) MatchPropertyList(props []types.DynamicProperty) bool
- type WaitFilter
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Wait ¶
func Wait(ctx context.Context, c *Collector, obj types.ManagedObjectReference, ps []string, f func([]types.PropertyChange) bool) error
Wait creates a new WaitFilter and calls the specified function for each ObjectUpdate via WaitForUpdates
Example ¶
package main import ( "context" "fmt" "time" "github.com/vmware/govmomi/find" "github.com/vmware/govmomi/property" "github.com/vmware/govmomi/simulator" "github.com/vmware/govmomi/vim25" "github.com/vmware/govmomi/vim25/types" ) func main() { simulator.Run(func(ctx context.Context, c *vim25.Client) error { pc := property.DefaultCollector(c) vm, err := find.NewFinder(c).VirtualMachine(ctx, "DC0_H0_VM0") if err != nil { return err } // power off VM after some time go func() { time.Sleep(time.Millisecond * 100) _, err := vm.PowerOff(ctx) if err != nil { panic(err) } }() return property.Wait(ctx, pc, vm.Reference(), []string{"runtime.powerState"}, func(changes []types.PropertyChange) bool { for _, change := range changes { state := change.Val.(types.VirtualMachinePowerState) fmt.Println(state) if state == types.VirtualMachinePowerStatePoweredOff { return true } } // continue polling return false }) }) }
Output: poweredOn poweredOff
func WaitForUpdates ¶ added in v0.16.0
func WaitForUpdates(ctx context.Context, c *Collector, filter *WaitFilter, f func([]types.ObjectUpdate) bool) error
WaitForUpdates waits for any of the specified properties of the specified managed object to change. It calls the specified function for every update it receives. If this function returns false, it continues waiting for subsequent updates. If this function returns true, it stops waiting and returns.
To only receive updates for the specified managed object, the function creates a new property collector and calls CreateFilter. A new property collector is required because filters can only be added, not removed.
If the Context is canceled, a call to CancelWaitForUpdates() is made and its error value is returned. The newly created collector is destroyed before this function returns (both in case of success or error).
By default, ObjectUpdate.MissingSet faults are not propagated to the returned error, set WaitFilter.PropagateMissing=true to enable MissingSet fault propagation.
Types ¶
type Collector ¶
type Collector struct {
// contains filtered or unexported fields
}
Collector models the PropertyCollector managed object.
For more information, see: http://pubs.vmware.com/vsphere-60/index.jsp?topic=%2Fcom.vmware.wssdk.apiref.doc%2Fvmodl.query.PropertyCollector.html
func DefaultCollector ¶
DefaultCollector returns the session's default property collector.
func (*Collector) CancelWaitForUpdates ¶ added in v0.19.0
func (*Collector) Create ¶
Create creates a new session-specific Collector that can be used to retrieve property updates independent of any other Collector.
func (*Collector) CreateFilter ¶
func (Collector) Reference ¶
func (p Collector) Reference() types.ManagedObjectReference
func (*Collector) Retrieve ¶
func (p *Collector) Retrieve(ctx context.Context, objs []types.ManagedObjectReference, ps []string, dst interface{}) error
Retrieve loads properties for a slice of managed objects. The dst argument must be a pointer to a []interface{}, which is populated with the instances of the specified managed objects, with the relevant properties filled in. If the properties slice is nil, all properties are loaded. Note that pointer types are optional fields that may be left as a nil value. The caller should check such fields for a nil value before dereferencing.
Example ¶
package main import ( "context" "fmt" "github.com/vmware/govmomi/find" "github.com/vmware/govmomi/property" "github.com/vmware/govmomi/simulator" "github.com/vmware/govmomi/vim25" "github.com/vmware/govmomi/vim25/mo" ) func main() { simulator.Run(func(ctx context.Context, c *vim25.Client) error { pc := property.DefaultCollector(c) obj, err := find.NewFinder(c).HostSystem(ctx, "DC0_H0") if err != nil { return err } var host mo.HostSystem err = pc.RetrieveOne(ctx, obj.Reference(), []string{"vm"}, &host) if err != nil { return err } var vms []mo.VirtualMachine err = pc.Retrieve(ctx, host.Vm, []string{"name"}, &vms) if err != nil { return err } fmt.Printf("host has %d vms:", len(vms)) for i := range vms { fmt.Print(" ", vms[i].Name) } return nil }) }
Output: host has 2 vms: DC0_H0_VM0 DC0_H0_VM1
func (*Collector) RetrieveOne ¶
func (p *Collector) RetrieveOne(ctx context.Context, obj types.ManagedObjectReference, ps []string, dst interface{}) error
RetrieveOne calls Retrieve with a single managed object reference via Collector.Retrieve().
Example ¶
Example to retrieve properties from a single object
package main import ( "context" "fmt" "github.com/vmware/govmomi/find" "github.com/vmware/govmomi/property" "github.com/vmware/govmomi/simulator" "github.com/vmware/govmomi/vim25" "github.com/vmware/govmomi/vim25/mo" ) func main() { simulator.Run(func(ctx context.Context, c *vim25.Client) error { pc := property.DefaultCollector(c) obj, err := find.NewFinder(c).VirtualMachine(ctx, "DC0_H0_VM0") if err != nil { return err } var vm mo.VirtualMachine err = pc.RetrieveOne(ctx, obj.Reference(), []string{"config.version"}, &vm) if err != nil { return err } fmt.Printf("hardware version %s", vm.Config.Version) return nil }) }
Output: hardware version vmx-13
func (*Collector) RetrieveProperties ¶
func (p *Collector) RetrieveProperties(ctx context.Context, req types.RetrieveProperties) (*types.RetrievePropertiesResponse, error)
func (*Collector) RetrieveWithFilter ¶ added in v0.14.0
func (p *Collector) RetrieveWithFilter(ctx context.Context, objs []types.ManagedObjectReference, ps []string, dst interface{}, filter Filter) error
RetrieveWithFilter populates dst as Retrieve does, but only for entities matching the given filter.
type Filter ¶ added in v0.14.0
Filter provides methods for matching against types.DynamicProperty
func (Filter) MatchAnyObjectContent ¶ added in v0.27.1
func (f Filter) MatchAnyObjectContent(objects []types.ObjectContent) []types.ManagedObjectReference
MatchAnyObjectContent returns a list of ObjectContent.Obj where the ObjectContent.PropSet matches any property in the Filter.
func (Filter) MatchAnyPropertyList ¶ added in v0.27.1
func (f Filter) MatchAnyPropertyList(props []types.DynamicProperty) bool
MatchAnyPropertyList returns true if any given props match the Filter.
func (Filter) MatchObjectContent ¶ added in v0.14.0
func (f Filter) MatchObjectContent(objects []types.ObjectContent) []types.ManagedObjectReference
MatchObjectContent returns a list of ObjectContent.Obj where the ObjectContent.PropSet matches all properties the Filter.
func (Filter) MatchProperty ¶ added in v0.14.0
func (f Filter) MatchProperty(prop types.DynamicProperty) bool
MatchProperty returns true if a Filter entry matches the given prop.
func (Filter) MatchPropertyList ¶ added in v0.14.0
func (f Filter) MatchPropertyList(props []types.DynamicProperty) bool
MatchPropertyList returns true if all given props match the Filter.
type WaitFilter ¶ added in v0.16.0
type WaitFilter struct { types.CreateFilter Options *types.WaitOptions PropagateMissing bool Truncated bool }
WaitFilter provides helpers to construct a types.CreateFilter for use with property.Wait
func (*WaitFilter) Add ¶ added in v0.16.0
func (f *WaitFilter) Add(obj types.ManagedObjectReference, kind string, ps []string, set ...types.BaseSelectionSpec) *WaitFilter
Add a new ObjectSpec and PropertySpec to the WaitFilter