Update osbuild/images to v0.40.0
In addition, simplify the SPEC file to not have to update the minimum required osbuild version gazillion times, but just once. Update the minimum required osbuild version to v109, due to changes in grub2 stages required by the new osbuild/images version. Update osbild SHA in Schutzfile to v109. Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
parent
c138ea6939
commit
2f087f1a6c
190 changed files with 57031 additions and 52810 deletions
115
vendor/github.com/vmware/govmomi/property/collector.go
generated
vendored
115
vendor/github.com/vmware/govmomi/property/collector.go
generated
vendored
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (c) 2015-2023 VMware, Inc. All Rights Reserved.
|
||||
Copyright (c) 2015-2024 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
@ -19,6 +19,8 @@ package property
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/vmware/govmomi/vim25"
|
||||
"github.com/vmware/govmomi/vim25/methods"
|
||||
|
|
@ -27,11 +29,19 @@ import (
|
|||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
// ErrConcurrentCollector is returned from WaitForUpdates, WaitForUpdatesEx,
|
||||
// or CheckForUpdates if any of those calls are unable to obtain an exclusive
|
||||
// lock for the property collector.
|
||||
var ErrConcurrentCollector = fmt.Errorf(
|
||||
"only one goroutine may invoke WaitForUpdates, WaitForUpdatesEx, " +
|
||||
"or CheckForUpdates on a given PropertyCollector")
|
||||
|
||||
// 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
|
||||
type Collector struct {
|
||||
mu sync.Mutex
|
||||
roundTripper soap.RoundTripper
|
||||
reference types.ManagedObjectReference
|
||||
}
|
||||
|
|
@ -46,7 +56,7 @@ func DefaultCollector(c *vim25.Client) *Collector {
|
|||
return &p
|
||||
}
|
||||
|
||||
func (p Collector) Reference() types.ManagedObjectReference {
|
||||
func (p *Collector) Reference() types.ManagedObjectReference {
|
||||
return p.reference
|
||||
}
|
||||
|
||||
|
|
@ -85,18 +95,28 @@ func (p *Collector) Destroy(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (p *Collector) CreateFilter(ctx context.Context, req types.CreateFilter) error {
|
||||
func (p *Collector) CreateFilter(ctx context.Context, req types.CreateFilter) (*Filter, error) {
|
||||
req.This = p.Reference()
|
||||
|
||||
_, err := methods.CreateFilter(ctx, p.roundTripper, &req)
|
||||
resp, err := methods.CreateFilter(ctx, p.roundTripper, &req)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return nil
|
||||
return &Filter{roundTripper: p.roundTripper, reference: resp.Returnval}, nil
|
||||
}
|
||||
|
||||
func (p *Collector) WaitForUpdates(ctx context.Context, version string, opts ...*types.WaitOptions) (*types.UpdateSet, error) {
|
||||
// Deprecated: Please use WaitForUpdatesEx instead.
|
||||
func (p *Collector) WaitForUpdates(
|
||||
ctx context.Context,
|
||||
version string,
|
||||
opts ...*types.WaitOptions) (*types.UpdateSet, error) {
|
||||
|
||||
if !p.mu.TryLock() {
|
||||
return nil, ErrConcurrentCollector
|
||||
}
|
||||
defer p.mu.Unlock()
|
||||
|
||||
req := types.WaitForUpdatesEx{
|
||||
This: p.Reference(),
|
||||
Version: version,
|
||||
|
|
@ -187,8 +207,15 @@ func (p *Collector) Retrieve(ctx context.Context, objs []types.ManagedObjectRefe
|
|||
return mo.LoadObjectContent(res.Returnval, dst)
|
||||
}
|
||||
|
||||
// RetrieveWithFilter populates dst as Retrieve does, but only for entities matching the given filter.
|
||||
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
|
||||
// that match the specified filter.
|
||||
func (p *Collector) RetrieveWithFilter(
|
||||
ctx context.Context,
|
||||
objs []types.ManagedObjectReference,
|
||||
ps []string,
|
||||
dst interface{},
|
||||
filter Match) error {
|
||||
|
||||
if len(filter) == 0 {
|
||||
return p.Retrieve(ctx, objs, ps, dst)
|
||||
}
|
||||
|
|
@ -200,7 +227,7 @@ func (p *Collector) RetrieveWithFilter(ctx context.Context, objs []types.Managed
|
|||
return err
|
||||
}
|
||||
|
||||
objs = filter.MatchObjectContent(content)
|
||||
objs = filter.ObjectContent(content)
|
||||
|
||||
if len(objs) == 0 {
|
||||
return nil
|
||||
|
|
@ -214,3 +241,71 @@ func (p *Collector) RetrieveOne(ctx context.Context, obj types.ManagedObjectRefe
|
|||
var objs = []types.ManagedObjectReference{obj}
|
||||
return p.Retrieve(ctx, objs, ps, dst)
|
||||
}
|
||||
|
||||
// WaitForUpdatesEx 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.
|
||||
//
|
||||
// If the Context is canceled, a call to CancelWaitForUpdates() is made and its
|
||||
// error value is returned.
|
||||
//
|
||||
// By default, ObjectUpdate.MissingSet faults are not propagated to the returned
|
||||
// error, set WaitFilter.PropagateMissing=true to enable MissingSet fault
|
||||
// propagation.
|
||||
func (p *Collector) WaitForUpdatesEx(
|
||||
ctx context.Context,
|
||||
opts WaitOptions,
|
||||
onUpdatesFn func([]types.ObjectUpdate) bool) error {
|
||||
|
||||
if !p.mu.TryLock() {
|
||||
return ErrConcurrentCollector
|
||||
}
|
||||
defer p.mu.Unlock()
|
||||
|
||||
req := types.WaitForUpdatesEx{
|
||||
This: p.Reference(),
|
||||
Options: opts.Options,
|
||||
}
|
||||
|
||||
for {
|
||||
res, err := methods.WaitForUpdatesEx(ctx, p.roundTripper, &req)
|
||||
if err != nil {
|
||||
if ctx.Err() == context.Canceled {
|
||||
return p.CancelWaitForUpdates(context.Background())
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
set := res.Returnval
|
||||
if set == nil {
|
||||
if req.Options != nil && req.Options.MaxWaitSeconds != nil {
|
||||
return nil // WaitOptions.MaxWaitSeconds exceeded
|
||||
}
|
||||
// Retry if the result came back empty
|
||||
continue
|
||||
}
|
||||
|
||||
req.Version = set.Version
|
||||
opts.Truncated = false
|
||||
if set.Truncated != nil {
|
||||
opts.Truncated = *set.Truncated
|
||||
}
|
||||
|
||||
for _, fs := range set.FilterSet {
|
||||
if opts.PropagateMissing {
|
||||
for i := range fs.ObjectSet {
|
||||
for _, p := range fs.ObjectSet[i].MissingSet {
|
||||
// Same behavior as mo.ObjectContentToType()
|
||||
return soap.WrapVimFault(p.Fault.Fault)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if onUpdatesFn(fs.ObjectSet) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
166
vendor/github.com/vmware/govmomi/property/filter.go
generated
vendored
166
vendor/github.com/vmware/govmomi/property/filter.go
generated
vendored
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
|
||||
Copyright (c) 2017-2024 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
@ -17,152 +17,38 @@ limitations under the License.
|
|||
package property
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"context"
|
||||
|
||||
"github.com/vmware/govmomi/vim25/methods"
|
||||
"github.com/vmware/govmomi/vim25/soap"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
// Filter provides methods for matching against types.DynamicProperty
|
||||
type Filter map[string]types.AnyType
|
||||
|
||||
// Keys returns the Filter map keys as a []string
|
||||
func (f Filter) Keys() []string {
|
||||
keys := make([]string, 0, len(f))
|
||||
|
||||
for key := range f {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
|
||||
return keys
|
||||
// Filter models the Filter managed object.
|
||||
//
|
||||
// For more information, see:
|
||||
// https://vdc-download.vmware.com/vmwb-repository/dcr-public/184bb3ba-6fa8-4574-a767-d0c96e2a38f4/ba9422ef-405c-47dd-8553-e11b619185b2/SDK/vsphere-ws/docs/ReferenceGuide/vmodl.query.PropertyCollector.Filter.html.
|
||||
type Filter struct {
|
||||
roundTripper soap.RoundTripper
|
||||
reference types.ManagedObjectReference
|
||||
}
|
||||
|
||||
// MatchProperty returns true if a Filter entry matches the given prop.
|
||||
func (f Filter) MatchProperty(prop types.DynamicProperty) bool {
|
||||
if prop.Val == nil {
|
||||
return false
|
||||
}
|
||||
match, ok := f[prop.Name]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
if match == prop.Val {
|
||||
return true
|
||||
}
|
||||
|
||||
ptype := reflect.TypeOf(prop.Val)
|
||||
|
||||
if strings.HasPrefix(ptype.Name(), "ArrayOf") {
|
||||
pval := reflect.ValueOf(prop.Val).Field(0)
|
||||
|
||||
for i := 0; i < pval.Len(); i++ {
|
||||
prop.Val = pval.Index(i).Interface()
|
||||
|
||||
if f.MatchProperty(prop) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
if reflect.TypeOf(match) != ptype {
|
||||
s, ok := match.(string)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
// convert if we can
|
||||
switch val := prop.Val.(type) {
|
||||
case bool:
|
||||
match, _ = strconv.ParseBool(s)
|
||||
case int16:
|
||||
x, _ := strconv.ParseInt(s, 10, 16)
|
||||
match = int16(x)
|
||||
case int32:
|
||||
x, _ := strconv.ParseInt(s, 10, 32)
|
||||
match = int32(x)
|
||||
case int64:
|
||||
match, _ = strconv.ParseInt(s, 10, 64)
|
||||
case float32:
|
||||
x, _ := strconv.ParseFloat(s, 32)
|
||||
match = float32(x)
|
||||
case float64:
|
||||
match, _ = strconv.ParseFloat(s, 64)
|
||||
case fmt.Stringer:
|
||||
prop.Val = val.String()
|
||||
case *types.CustomFieldStringValue:
|
||||
prop.Val = fmt.Sprintf("%d:%s", val.Key, val.Value)
|
||||
default:
|
||||
if ptype.Kind() != reflect.String {
|
||||
return false
|
||||
}
|
||||
// An enum type we can convert to a string type
|
||||
prop.Val = reflect.ValueOf(prop.Val).String()
|
||||
}
|
||||
}
|
||||
|
||||
switch pval := prop.Val.(type) {
|
||||
case string:
|
||||
s := match.(string)
|
||||
if s == "*" {
|
||||
return true // TODO: path.Match fails if s contains a '/'
|
||||
}
|
||||
m, _ := path.Match(s, pval)
|
||||
return m
|
||||
default:
|
||||
return reflect.DeepEqual(match, pval)
|
||||
}
|
||||
func (f Filter) Reference() types.ManagedObjectReference {
|
||||
return f.reference
|
||||
}
|
||||
|
||||
// MatchPropertyList returns true if all given props match the Filter.
|
||||
func (f Filter) MatchPropertyList(props []types.DynamicProperty) bool {
|
||||
for _, p := range props {
|
||||
if !f.MatchProperty(p) {
|
||||
return false
|
||||
}
|
||||
// Destroy destroys this filter.
|
||||
//
|
||||
// This operation can be called explicitly, or it can take place implicitly when
|
||||
// the session that created the filter is closed.
|
||||
func (f *Filter) Destroy(ctx context.Context) error {
|
||||
if _, err := methods.DestroyPropertyFilter(
|
||||
ctx,
|
||||
f.roundTripper,
|
||||
&types.DestroyPropertyFilter{This: f.Reference()}); err != nil {
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
return len(f) == len(props) // false if a property such as VM "guest" is unset
|
||||
}
|
||||
|
||||
// MatchObjectContent returns a list of ObjectContent.Obj where the ObjectContent.PropSet matches all properties the Filter.
|
||||
func (f Filter) MatchObjectContent(objects []types.ObjectContent) []types.ManagedObjectReference {
|
||||
var refs []types.ManagedObjectReference
|
||||
|
||||
for _, o := range objects {
|
||||
if f.MatchPropertyList(o.PropSet) {
|
||||
refs = append(refs, o.Obj)
|
||||
}
|
||||
}
|
||||
|
||||
return refs
|
||||
}
|
||||
|
||||
// MatchAnyPropertyList returns true if any given props match the Filter.
|
||||
func (f Filter) MatchAnyPropertyList(props []types.DynamicProperty) bool {
|
||||
for _, p := range props {
|
||||
if f.MatchProperty(p) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// MatchAnyObjectContent returns a list of ObjectContent.Obj where the ObjectContent.PropSet matches any property in the Filter.
|
||||
func (f Filter) MatchAnyObjectContent(objects []types.ObjectContent) []types.ManagedObjectReference {
|
||||
var refs []types.ManagedObjectReference
|
||||
|
||||
for _, o := range objects {
|
||||
if f.MatchAnyPropertyList(o.PropSet) {
|
||||
refs = append(refs, o.Obj)
|
||||
}
|
||||
}
|
||||
|
||||
return refs
|
||||
f.reference = types.ManagedObjectReference{}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
170
vendor/github.com/vmware/govmomi/property/match.go
generated
vendored
Normal file
170
vendor/github.com/vmware/govmomi/property/match.go
generated
vendored
Normal file
|
|
@ -0,0 +1,170 @@
|
|||
/*
|
||||
Copyright (c) 2017-2024 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package property
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
// Match provides methods for matching against types.DynamicProperty
|
||||
type Match map[string]types.AnyType
|
||||
|
||||
// Keys returns the Match map keys as a []string
|
||||
func (m Match) Keys() []string {
|
||||
keys := make([]string, 0, len(m))
|
||||
|
||||
for key := range m {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
|
||||
return keys
|
||||
}
|
||||
|
||||
// Property returns true if an entry matches the given prop.
|
||||
func (m Match) Property(prop types.DynamicProperty) bool {
|
||||
if prop.Val == nil {
|
||||
return false
|
||||
}
|
||||
match, ok := m[prop.Name]
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
if match == prop.Val {
|
||||
return true
|
||||
}
|
||||
|
||||
ptype := reflect.TypeOf(prop.Val)
|
||||
|
||||
if strings.HasPrefix(ptype.Name(), "ArrayOf") {
|
||||
pval := reflect.ValueOf(prop.Val).Field(0)
|
||||
|
||||
for i := 0; i < pval.Len(); i++ {
|
||||
prop.Val = pval.Index(i).Interface()
|
||||
|
||||
if m.Property(prop) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
if reflect.TypeOf(match) != ptype {
|
||||
s, ok := match.(string)
|
||||
if !ok {
|
||||
return false
|
||||
}
|
||||
|
||||
// convert if we can
|
||||
switch val := prop.Val.(type) {
|
||||
case bool:
|
||||
match, _ = strconv.ParseBool(s)
|
||||
case int16:
|
||||
x, _ := strconv.ParseInt(s, 10, 16)
|
||||
match = int16(x)
|
||||
case int32:
|
||||
x, _ := strconv.ParseInt(s, 10, 32)
|
||||
match = int32(x)
|
||||
case int64:
|
||||
match, _ = strconv.ParseInt(s, 10, 64)
|
||||
case float32:
|
||||
x, _ := strconv.ParseFloat(s, 32)
|
||||
match = float32(x)
|
||||
case float64:
|
||||
match, _ = strconv.ParseFloat(s, 64)
|
||||
case fmt.Stringer:
|
||||
prop.Val = val.String()
|
||||
case *types.CustomFieldStringValue:
|
||||
prop.Val = fmt.Sprintf("%d:%s", val.Key, val.Value)
|
||||
default:
|
||||
if ptype.Kind() != reflect.String {
|
||||
return false
|
||||
}
|
||||
// An enum type we can convert to a string type
|
||||
prop.Val = reflect.ValueOf(prop.Val).String()
|
||||
}
|
||||
}
|
||||
|
||||
switch pval := prop.Val.(type) {
|
||||
case string:
|
||||
s := match.(string)
|
||||
if s == "*" {
|
||||
return true // TODO: path.Match fails if s contains a '/'
|
||||
}
|
||||
m, _ := path.Match(s, pval)
|
||||
return m
|
||||
default:
|
||||
return reflect.DeepEqual(match, pval)
|
||||
}
|
||||
}
|
||||
|
||||
// List returns true if all given props match.
|
||||
func (m Match) List(props []types.DynamicProperty) bool {
|
||||
for _, p := range props {
|
||||
if !m.Property(p) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return len(m) == len(props) // false if a property such as VM "guest" is unset
|
||||
}
|
||||
|
||||
// ObjectContent returns a list of ObjectContent.Obj where the
|
||||
// ObjectContent.PropSet matches all properties the Filter.
|
||||
func (m Match) ObjectContent(objects []types.ObjectContent) []types.ManagedObjectReference {
|
||||
var refs []types.ManagedObjectReference
|
||||
|
||||
for _, o := range objects {
|
||||
if m.List(o.PropSet) {
|
||||
refs = append(refs, o.Obj)
|
||||
}
|
||||
}
|
||||
|
||||
return refs
|
||||
}
|
||||
|
||||
// AnyList returns true if any given props match.
|
||||
func (m Match) AnyList(props []types.DynamicProperty) bool {
|
||||
for _, p := range props {
|
||||
if m.Property(p) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// AnyObjectContent returns a list of ObjectContent.Obj where the
|
||||
// ObjectContent.PropSet matches any property.
|
||||
func (m Match) AnyObjectContent(objects []types.ObjectContent) []types.ManagedObjectReference {
|
||||
var refs []types.ManagedObjectReference
|
||||
|
||||
for _, o := range objects {
|
||||
if m.AnyList(o.PropSet) {
|
||||
refs = append(refs, o.Obj)
|
||||
}
|
||||
}
|
||||
|
||||
return refs
|
||||
}
|
||||
143
vendor/github.com/vmware/govmomi/property/wait.go
generated
vendored
143
vendor/github.com/vmware/govmomi/property/wait.go
generated
vendored
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (c) 2015-2017 VMware, Inc. All Rights Reserved.
|
||||
Copyright (c) 2015-2024 VMware, Inc. All Rights Reserved.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
|
@ -18,18 +18,23 @@ package property
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/vmware/govmomi/vim25/methods"
|
||||
"github.com/vmware/govmomi/vim25/soap"
|
||||
"github.com/vmware/govmomi/vim25/types"
|
||||
)
|
||||
|
||||
// WaitOptions defines options for a property collector's WaitForUpdatesEx
|
||||
// method.
|
||||
type WaitOptions struct {
|
||||
Options *types.WaitOptions
|
||||
PropagateMissing bool
|
||||
Truncated bool
|
||||
}
|
||||
|
||||
// WaitFilter provides helpers to construct a types.CreateFilter for use with property.Wait
|
||||
type WaitFilter struct {
|
||||
types.CreateFilter
|
||||
Options *types.WaitOptions
|
||||
PropagateMissing bool
|
||||
Truncated bool
|
||||
WaitOptions
|
||||
}
|
||||
|
||||
// Add a new ObjectSpec and PropertySpec to the WaitFilter
|
||||
|
|
@ -70,8 +75,8 @@ func Wait(ctx context.Context, c *Collector, obj types.ManagedObjectReference, p
|
|||
})
|
||||
}
|
||||
|
||||
// WaitForUpdates waits for any of the specified properties of the specified managed
|
||||
// object to change. It calls the specified function for every update it
|
||||
// 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.
|
||||
|
|
@ -80,14 +85,24 @@ func Wait(ctx context.Context, c *Collector, obj types.ManagedObjectReference, p
|
|||
// 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).
|
||||
// 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.
|
||||
func WaitForUpdates(ctx context.Context, c *Collector, filter *WaitFilter, f func([]types.ObjectUpdate) bool) error {
|
||||
p, err := c.Create(ctx)
|
||||
// By default, ObjectUpdate.MissingSet faults are not propagated to the returned
|
||||
// error, set WaitFilter.PropagateMissing=true to enable MissingSet fault
|
||||
// propagation.
|
||||
//
|
||||
// Deprecated: Please consider using WaitForUpdatesEx instead, as it does not
|
||||
// create a new property collector, instead it destroys the property filter
|
||||
// after the expected update is received.
|
||||
func WaitForUpdates(
|
||||
ctx context.Context,
|
||||
c *Collector,
|
||||
filter *WaitFilter,
|
||||
onUpdatesFn func([]types.ObjectUpdate) bool) (result error) {
|
||||
|
||||
pc, err := c.Create(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -95,57 +110,65 @@ func WaitForUpdates(ctx context.Context, c *Collector, filter *WaitFilter, f fun
|
|||
// Attempt to destroy the collector using the background context, as the
|
||||
// specified context may have timed out or have been canceled.
|
||||
defer func() {
|
||||
_ = p.Destroy(context.Background())
|
||||
if err := pc.Destroy(context.Background()); err != nil {
|
||||
if result == nil {
|
||||
result = err
|
||||
} else {
|
||||
result = fmt.Errorf(
|
||||
"destroy property collector failed with %s after failing to wait for updates: %w",
|
||||
err,
|
||||
result)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
err = p.CreateFilter(ctx, filter.CreateFilter)
|
||||
// Create a property filter for the property collector.
|
||||
if _, err := pc.CreateFilter(ctx, filter.CreateFilter); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return pc.WaitForUpdatesEx(ctx, filter.WaitOptions, onUpdatesFn)
|
||||
}
|
||||
|
||||
// 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.
|
||||
//
|
||||
// If the Context is canceled, a call to CancelWaitForUpdates() is made and its
|
||||
// error value is returned.
|
||||
//
|
||||
// By default, ObjectUpdate.MissingSet faults are not propagated to the returned
|
||||
// error, set WaitFilter.PropagateMissing=true to enable MissingSet fault
|
||||
// propagation.
|
||||
func WaitForUpdatesEx(
|
||||
ctx context.Context,
|
||||
pc *Collector,
|
||||
filter *WaitFilter,
|
||||
onUpdatesFn func([]types.ObjectUpdate) bool) (result error) {
|
||||
|
||||
// Create a property filter for the property collector.
|
||||
pf, err := pc.CreateFilter(ctx, filter.CreateFilter)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req := types.WaitForUpdatesEx{
|
||||
This: p.Reference(),
|
||||
Options: filter.Options,
|
||||
}
|
||||
|
||||
for {
|
||||
res, err := methods.WaitForUpdatesEx(ctx, p.roundTripper, &req)
|
||||
if err != nil {
|
||||
if ctx.Err() == context.Canceled {
|
||||
werr := p.CancelWaitForUpdates(context.Background())
|
||||
return werr
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
set := res.Returnval
|
||||
if set == nil {
|
||||
if req.Options != nil && req.Options.MaxWaitSeconds != nil {
|
||||
return nil // WaitOptions.MaxWaitSeconds exceeded
|
||||
}
|
||||
// Retry if the result came back empty
|
||||
continue
|
||||
}
|
||||
|
||||
req.Version = set.Version
|
||||
filter.Truncated = false
|
||||
if set.Truncated != nil {
|
||||
filter.Truncated = *set.Truncated
|
||||
}
|
||||
|
||||
for _, fs := range set.FilterSet {
|
||||
if filter.PropagateMissing {
|
||||
for i := range fs.ObjectSet {
|
||||
for _, p := range fs.ObjectSet[i].MissingSet {
|
||||
// Same behavior as mo.ObjectContentToType()
|
||||
return soap.WrapVimFault(p.Fault.Fault)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if f(fs.ObjectSet) {
|
||||
return nil
|
||||
// Destroy the filter using the background context, as the specified context
|
||||
// may have timed out or have been canceled.
|
||||
defer func() {
|
||||
if err := pf.Destroy(context.Background()); err != nil {
|
||||
if result == nil {
|
||||
result = err
|
||||
} else {
|
||||
result = fmt.Errorf(
|
||||
"destroy property filter failed with %s after failing to wait for updates: %w",
|
||||
err,
|
||||
result)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}()
|
||||
|
||||
return pc.WaitForUpdatesEx(ctx, filter.WaitOptions, onUpdatesFn)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue