-
I'd like to obtain the total count of non-template VMs in the inventory. In my use case I do not need names or other properties. In the environment I'm currently testing in there are:
I've tested using a finder and using a view. Regardless of what settings I try the finder approach is the slowest. Using a view the fastest approach looks to be specifying just the If I retrieve the Is there another approach which is faster? Tips/suggestions are welcome. Thanks in advance! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Hey @atc0005 , view is much faster than finder in this case. You can specify the func ExampleContainerView_vmCount() {
simulator.Run(func(ctx context.Context, c *vim25.Client) error {
// quick version of MarkAsTemplate()
simulator.Map.Any("VirtualMachine").(*simulator.VirtualMachine).Config.Template = true
m := view.NewManager(c)
kind := []string{"VirtualMachine"}
v, err := m.CreateContainerView(ctx, c.ServiceContent.RootFolder, kind, true)
if err != nil {
log.Fatal(err)
}
var vms []types.ObjectContent
filter := property.Filter{"config.template": true}
err = v.Retrieve(ctx, kind, filter.Keys(), &vms)
if err != nil {
return err
}
templates := filter.MatchObjectContent(vms)
fmt.Printf("%d vms, %d templates\n", len(vms), len(templates))
return v.Destroy(ctx)
})
// Output: 4 vms, 1 templates
} |
Beta Was this translation helpful? Give feedback.
-
@dougm This is great, thank you! Thank you also for linking to those examples, I completely overlooked them. For a managed object like resource pools, would the name property generally be the least expensive or is there a better option (same goal of gathering just the count) ? |
Beta Was this translation helpful? Give feedback.
Hey @atc0005 , view is much faster than finder in this case. You can specify the
config.template
property (orsummary.config.template
. Below is a modify example of ExampleContainerView_RetrieveWithFilter