Skip to content

What is the fastest/cheapest way to obtain the number of VMs from the inventory? #3203

Closed Answered by dougm
atc0005 asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @atc0005 , view is much faster than finder in this case. You can specify the config.template property (or summary.config.template. Below is a modify example of ExampleContainerView_RetrieveWithFilter

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"

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
1 reply
@atc0005
Comment options

Answer selected by atc0005
Comment options

You must be logged in to vote
1 reply
@dougm
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants