github.com/vmware/govmomi@v0.51.0/cli/esx/example_test.go (about)

     1  // © Broadcom. All Rights Reserved.
     2  // The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
     3  // SPDX-License-Identifier: Apache-2.0
     4  
     5  package esx_test
     6  
     7  import (
     8  	"context"
     9  	"fmt"
    10  
    11  	"github.com/vmware/govmomi/cli/esx"
    12  	"github.com/vmware/govmomi/find"
    13  	"github.com/vmware/govmomi/simulator"
    14  	"github.com/vmware/govmomi/vim25"
    15  )
    16  
    17  func ExampleExecutor_Run() {
    18  	simulator.Run(func(ctx context.Context, c *vim25.Client) error {
    19  		host, err := find.NewFinder(c).HostSystem(ctx, "DC0_H0")
    20  		if err != nil {
    21  			return err
    22  		}
    23  
    24  		x, err := esx.NewExecutor(ctx, c, host)
    25  		if err != nil {
    26  			return err
    27  		}
    28  
    29  		res, err := x.Run(ctx, []string{"software", "vib", "list"})
    30  		if err != nil {
    31  			return err
    32  		}
    33  
    34  		for _, vib := range res.Values {
    35  			fmt.Println(vib.Value("Name"))
    36  		}
    37  
    38  		return nil
    39  	})
    40  	// Output:
    41  	// esx-ui
    42  	// intelgpio
    43  }