github.com/vmware/govmomi@v0.43.0/govc/host/vnic/hint.go (about) 1 /* 2 Copyright (c) 2022-2023 VMware, Inc. All Rights Reserved. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package vnic 18 19 import ( 20 "context" 21 "errors" 22 "flag" 23 "io" 24 25 "github.com/vmware/govmomi/govc/cli" 26 "github.com/vmware/govmomi/govc/flags" 27 "github.com/vmware/govmomi/vim25/types" 28 ) 29 30 type hint struct { 31 *flags.HostSystemFlag 32 } 33 34 func init() { 35 cli.Register("host.vnic.hint", &hint{}) 36 } 37 38 func (cmd *hint) Register(ctx context.Context, f *flag.FlagSet) { 39 cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx) 40 cmd.HostSystemFlag.Register(ctx, f) 41 } 42 43 func (cmd *hint) Usage() string { 44 return "[DEVICE]..." 45 } 46 47 func (cmd *hint) Description() string { 48 return `Query virtual nic DEVICE hints. 49 Examples: 50 govc host.vnic.hint -host hostname 51 govc host.vnic.hint -host hostname vmnic1` 52 } 53 54 type hintResult struct { 55 Hint []types.PhysicalNicHintInfo `json:"hint"` 56 } 57 58 func (i *hintResult) Write(w io.Writer) error { 59 // TODO: human friendly output 60 return errors.New("-xml, -json or -dump flag required") 61 } 62 63 func (cmd *hint) Run(ctx context.Context, f *flag.FlagSet) error { 64 ns, err := cmd.HostNetworkSystem() 65 if err != nil { 66 return err 67 } 68 69 hints, err := ns.QueryNetworkHint(ctx, f.Args()) 70 if err != nil { 71 return err 72 } 73 74 return cmd.WriteResult(&hintResult{Hint: hints}) 75 }