Skip to content

Commit

Permalink
api: use RetrievePropertiesEx in mo package functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dougm committed Apr 11, 2024
1 parent 4348bd9 commit f5080d3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 24 deletions.
24 changes: 2 additions & 22 deletions property/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,35 +155,15 @@ func (p *Collector) RetrieveProperties(
opts.MaxObjects = maxObjectsArgs[0]
}

req.This = p.Reference()
rx, err := methods.RetrievePropertiesEx(ctx, p.roundTripper, &types.RetrievePropertiesEx{
This: req.This,
objects, err := mo.RetrievePropertiesEx(ctx, p.roundTripper, types.RetrievePropertiesEx{
This: p.Reference(),
SpecSet: req.SpecSet,
Options: opts,
})
if err != nil {
return nil, err
}

if rx.Returnval == nil {
return &types.RetrievePropertiesResponse{}, nil
}

objects := rx.Returnval.Objects
token := rx.Returnval.Token

for token != "" {
cx, err := methods.ContinueRetrievePropertiesEx(ctx, p.roundTripper, &types.ContinueRetrievePropertiesEx{
This: req.This,
Token: token,
})
if err != nil {
return nil, err
}
token = cx.Returnval.Token
objects = append(objects, cx.Returnval.Objects...)
}

return &types.RetrievePropertiesResponse{Returnval: objects}, nil
}

Expand Down
37 changes: 35 additions & 2 deletions vim25/mo/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,49 @@ func LoadObjectContent(content []types.ObjectContent, dst interface{}) error {
return nil
}

// RetrievePropertiesEx wraps RetrievePropertiesEx and ContinueRetrievePropertiesEx to collect properties in batches.
func RetrievePropertiesEx(ctx context.Context, r soap.RoundTripper, req types.RetrievePropertiesEx) ([]types.ObjectContent, error) {
rx, err := methods.RetrievePropertiesEx(ctx, r, &req)
if err != nil {
return nil, err
}

if rx.Returnval == nil {
return nil, nil
}

objects := rx.Returnval.Objects
token := rx.Returnval.Token

for token != "" {
cx, err := methods.ContinueRetrievePropertiesEx(ctx, r, &types.ContinueRetrievePropertiesEx{
This: req.This,
Token: token,
})
if err != nil {
return nil, err
}

token = cx.Returnval.Token
objects = append(objects, cx.Returnval.Objects...)
}

return objects, nil
}

// RetrievePropertiesForRequest calls the RetrieveProperties method with the
// specified request and decodes the response struct into the value pointed to
// by dst.
func RetrievePropertiesForRequest(ctx context.Context, r soap.RoundTripper, req types.RetrieveProperties, dst interface{}) error {
res, err := methods.RetrieveProperties(ctx, r, &req)
objects, err := RetrievePropertiesEx(ctx, r, types.RetrievePropertiesEx{
This: req.This,
SpecSet: req.SpecSet,
})
if err != nil {
return err
}

return LoadObjectContent(res.Returnval, dst)
return LoadObjectContent(objects, dst)
}

// RetrieveProperties retrieves the properties of the managed object specified
Expand Down

0 comments on commit f5080d3

Please sign in to comment.