Skip to content

Commit

Permalink
Merge pull request vmware#2941 from smahadikarkin/sm.cdp_lldp_support…
Browse files Browse the repository at this point in the history
…_govc_vcsim

Adding support for LLDP and CDP details for GOVC and VCSIM
  • Loading branch information
dougm committed Nov 3, 2022
2 parents aedcf47 + 8f4da55 commit 1f8aadb
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 10 deletions.
15 changes: 15 additions & 0 deletions govc/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ but appear via `govc $cmd -h`:
- [host.storage.mark](#hoststoragemark)
- [host.storage.partition](#hoststoragepartition)
- [host.vnic.change](#hostvnicchange)
- [host.vnic.hint](#hostvnichint)
- [host.vnic.info](#hostvnicinfo)
- [host.vnic.service](#hostvnicservice)
- [host.vswitch.add](#hostvswitchadd)
Expand Down Expand Up @@ -3006,6 +3007,20 @@ Options:
-mtu=0 vmk MTU
```

## host.vnic.hint

```
Usage: govc host.vnic.hint [OPTIONS] [DEVICE]...
Query virtual nic DEVICE hints.
Examples:
govc host.vnic.hint -host hostname
govc host.vnic.hint -host hostname vmnic1
Options:
-host= Host system [GOVC_HOST]
```

## host.vnic.info

```
Expand Down
75 changes: 75 additions & 0 deletions govc/host/vnic/hint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
Copyright (c) 2022-2022 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package vnic

import (
"context"
"errors"
"flag"
"io"

"github.com/vmware/govmomi/govc/cli"
"github.com/vmware/govmomi/govc/flags"
"github.com/vmware/govmomi/vim25/types"
)

type hint struct {
*flags.HostSystemFlag
}

func init() {
cli.Register("host.vnic.hint", &hint{})
}

func (cmd *hint) Register(ctx context.Context, f *flag.FlagSet) {
cmd.HostSystemFlag, ctx = flags.NewHostSystemFlag(ctx)
cmd.HostSystemFlag.Register(ctx, f)
}

func (cmd *hint) Usage() string {
return "[DEVICE]..."
}

func (cmd *hint) Description() string {
return `Query virtual nic DEVICE hints.
Examples:
govc host.vnic.hint -host hostname
govc host.vnic.hint -host hostname vmnic1`
}

type hintResult struct {
Hint []types.PhysicalNicHintInfo
}

func (i *hintResult) Write(w io.Writer) error {
// TODO: human friendly output
return errors.New("-xml, -json or -dump flag required")
}

func (cmd *hint) Run(ctx context.Context, f *flag.FlagSet) error {
ns, err := cmd.HostNetworkSystem()
if err != nil {
return err
}

hints, err := ns.QueryNetworkHint(ctx, f.Args())
if err != nil {
return err
}

return cmd.WriteResult(&hintResult{Hint: hints})
}
9 changes: 9 additions & 0 deletions govc/object/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,19 @@ func saveEnvironmentBrowser(ctx context.Context, c *vim25.Client, ref types.Mana
return []saveMethod{{"QueryConfigOption", res}}, nil
}

func saveHostNetworkSystem(ctx context.Context, c *vim25.Client, ref types.ManagedObjectReference) ([]saveMethod, error) {
res, err := methods.QueryNetworkHint(ctx, c, &types.QueryNetworkHint{This: ref})
if err != nil {
return nil, err
}
return []saveMethod{{"QueryNetworkHint", res}}, nil
}

// saveObjects maps object types to functions that can save data that isn't available via the PropertyCollector
var saveObjects = map[string]func(context.Context, *vim25.Client, types.ManagedObjectReference) ([]saveMethod, error){
"VmwareDistributedVirtualSwitch": saveDVS,
"EnvironmentBrowser": saveEnvironmentBrowser,
"HostNetworkSystem": saveHostNetworkSystem,
}

func (cmd *save) save(content []types.ObjectContent) error {
Expand Down
12 changes: 3 additions & 9 deletions simulator/host_network_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type HostNetworkSystem struct {
mo.HostNetworkSystem

Host *mo.HostSystem

types.QueryNetworkHintResponse
}

func NewHostNetworkSystem(host *mo.HostSystem) *HostNetworkSystem {
Expand Down Expand Up @@ -196,17 +198,9 @@ func (s *HostNetworkSystem) UpdateNetworkConfig(req *types.UpdateNetworkConfig)
}

func (s *HostNetworkSystem) QueryNetworkHint(req *types.QueryNetworkHint) soap.HasFault {
var info []types.PhysicalNicHintInfo

for _, nic := range s.Host.Config.Network.Pnic {
info = append(info, types.PhysicalNicHintInfo{
Device: nic.Device,
})
}

return &methods.QueryNetworkHintBody{
Res: &types.QueryNetworkHintResponse{
Returnval: info,
Returnval: s.QueryNetworkHintResponse.Returnval,
},
}
}
2 changes: 1 addition & 1 deletion simulator/host_network_system_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestHostNetworkSystem(t *testing.T) {
t.Fatal(err)
}

if len(info) != len(esx.HostConfigInfo.Network.Pnic) {
if len(info) != 0 { // TODO: data is only returned when Model.Load is used
t.Errorf("len=%d", len(info))
}
}

0 comments on commit 1f8aadb

Please sign in to comment.