github.com/vmware/govmomi@v0.51.0/cli/vm/option/info.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 option 6 7 import ( 8 "context" 9 "flag" 10 "fmt" 11 "io" 12 "text/tabwriter" 13 14 "github.com/vmware/govmomi/cli" 15 "github.com/vmware/govmomi/cli/flags" 16 "github.com/vmware/govmomi/vim25/types" 17 ) 18 19 type info struct { 20 flags.EnvBrowser 21 22 key string 23 } 24 25 func init() { 26 cli.Register("vm.option.info", &info{}) 27 } 28 29 func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) { 30 cmd.EnvBrowser.Register(ctx, f) 31 32 f.StringVar(&cmd.key, "id", "", "Option descriptor key") 33 } 34 35 func (cmd *info) Usage() string { 36 return "[GUEST_ID]..." 37 } 38 39 func (cmd *info) Description() string { 40 return `VM config options for CLUSTER. 41 42 The config option data contains information about the execution environment for a VM 43 in the given CLUSTER, and optionally for a specific HOST. 44 45 By default, supported guest OS IDs and full name are listed. 46 47 Examples: 48 govc vm.option.info -cluster C0 49 govc vm.option.info -cluster C0 -dump ubuntu64Guest 50 govc vm.option.info -cluster C0 -json | jq .guestOSDescriptor[].id 51 govc vm.option.info -host my_hostname 52 govc vm.option.info -vm my_vm` 53 } 54 55 func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error { 56 b, err := cmd.Browser(ctx) 57 if err != nil { 58 return err 59 } 60 61 host, err := cmd.HostSystemIfSpecified() 62 if err != nil { 63 return err 64 } 65 66 var req *types.EnvironmentBrowserConfigOptionQuerySpec 67 68 spec := func() *types.EnvironmentBrowserConfigOptionQuerySpec { 69 if req == nil { 70 req = new(types.EnvironmentBrowserConfigOptionQuerySpec) 71 } 72 return req 73 } 74 75 if f.NArg() != 0 { 76 spec().GuestId = f.Args() 77 } 78 79 if host != nil { 80 spec().Host = types.NewReference(host.Reference()) 81 } 82 83 if cmd.key != "" { 84 spec().Key = cmd.key 85 } 86 87 opt, err := b.QueryConfigOption(ctx, req) 88 if err != nil { 89 return err 90 } 91 92 return cmd.VirtualMachineFlag.WriteResult(&infoResult{opt}) 93 } 94 95 type infoResult struct { 96 *types.VirtualMachineConfigOption 97 } 98 99 func (r *infoResult) Write(w io.Writer) error { 100 tw := tabwriter.NewWriter(w, 2, 0, 2, ' ', 0) 101 102 for _, d := range r.GuestOSDescriptor { 103 _, _ = fmt.Fprintf(tw, "%s\t%s\n", d.Id, d.FullName) 104 } 105 106 return tw.Flush() 107 } 108 109 func (r *infoResult) Dump() any { 110 return r.VirtualMachineConfigOption 111 }