Skip to content

Commit

Permalink
Merge pull request vmware#3292 from dougm/vcsim-save
Browse files Browse the repository at this point in the history
vcsim: handle HostNotConnected when saving inventory
  • Loading branch information
dbhat-arkin authored Nov 22, 2023
2 parents 8d86612 + 04ccf69 commit 44d6f8d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
14 changes: 14 additions & 0 deletions govc/object/save.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/methods"
"github.com/vmware/govmomi/vim25/mo"
"github.com/vmware/govmomi/vim25/soap"
"github.com/vmware/govmomi/vim25/types"
"github.com/vmware/govmomi/vim25/xml"
)
Expand Down Expand Up @@ -153,6 +154,16 @@ var saveObjects = map[string]func(context.Context, *vim25.Client, types.ManagedO
"HostNetworkSystem": saveHostNetworkSystem,
}

func isNotConnected(err error) bool {
if soap.IsSoapFault(err) {
switch soap.ToSoapFault(err).VimFault().(type) {
case types.HostNotConnected:
return true
}
}
return false
}

func (cmd *save) save(content []types.ObjectContent) error {
for _, x := range content {
x.MissingSet = nil // drop any NoPermission faults
Expand All @@ -174,6 +185,9 @@ func (cmd *save) save(content []types.ObjectContent) error {
if method, ok := saveObjects[x.Obj.Type]; ok {
objs, err := method(context.Background(), c, x.Obj)
if err != nil {
if isNotConnected(err) {
continue
}
return err
}
dir := filepath.Join(cmd.dir, ref)
Expand Down
14 changes: 14 additions & 0 deletions govc/test/host.bats
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ load test_helper
govc host.vnic.info -json | jq .
}

@test "host.vnic.hint" {
vcsim_env

run govc host.vnic.hint -xml -host DC0_C0_H0
assert_success

run govc host.disconnect DC0_C0_H0
assert_success

run govc host.vnic.hint -xml -host DC0_C0_H0
assert_failure
assert_matches HostNotConnected "$output"
}

@test "host.vswitch.info" {
vcsim_env -esx

Expand Down
6 changes: 6 additions & 0 deletions simulator/host_network_system.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,12 @@ func (s *HostNetworkSystem) UpdateNetworkConfig(req *types.UpdateNetworkConfig)
}

func (s *HostNetworkSystem) QueryNetworkHint(req *types.QueryNetworkHint) soap.HasFault {
if s.Host.Runtime.ConnectionState != types.HostSystemConnectionStateConnected {
return &methods.QueryNetworkHintBody{
Fault_: Fault("", &types.HostNotConnected{}),
}
}

return &methods.QueryNetworkHintBody{
Res: &types.QueryNetworkHintResponse{
Returnval: s.QueryNetworkHintResponse.Returnval,
Expand Down

0 comments on commit 44d6f8d

Please sign in to comment.