Skip to content

Commit

Permalink
vcsim: add HostVirtualNicManager
Browse files Browse the repository at this point in the history
  • Loading branch information
dougm committed Apr 26, 2024
1 parent 2892d60 commit f53de95
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 3 deletions.
2 changes: 1 addition & 1 deletion govc/test/host.bats
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ load test_helper
}

@test "host.vnic.info" {
esx_env
vcsim_env

run govc host.vnic.info
assert_success
Expand Down
46 changes: 46 additions & 0 deletions simulator/esx/host_vnic_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright (c) 2024-2024 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 esx

Check failure on line 16 in simulator/esx/host_vnic_manager.go

View workflow job for this annotation

GitHub Actions / Boilerplate Check (go)

[Go headers] reported by reviewdog 🐶 found mismatched boilerplate lines: Raw Output: simulator/esx/host_vnic_manager.go:16: found mismatched boilerplate lines: {[]string}[0]: -: "" +: "package esx"

import "github.com/vmware/govmomi/vim25/types"

var VirtualNicManagerNetConfig = []types.VirtualNicManagerNetConfig{
{
NicType: "management",
MultiSelectAllowed: true,
CandidateVnic: []types.HostVirtualNic{
{
Device: "vmk0",
Key: "management.key-vim.host.VirtualNic-vmk0",
Portgroup: "Management Network",
Spec: types.HostVirtualNicSpec{
Ip: &types.HostIpConfig{
Dhcp: true,
IpAddress: "127.0.0.1",
SubnetMask: "255.0.0.0",
},
Mac: "00:0c:29:81:d8:a0",
Portgroup: "Management Network",
Mtu: 1500,
TsoEnabled: types.NewBool(true),
NetStackInstanceKey: "defaultTcpipStack",
SystemOwned: types.NewBool(false),
},
},
},
SelectedVnic: []string{"management.key-vim.host.VirtualNic-vmk0"},
},
}
5 changes: 3 additions & 2 deletions simulator/host_system.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
Copyright (c) 2017 VMware, Inc. All Rights Reserved.
Copyright (c) 2017-2024 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
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,
Expand Down Expand Up @@ -96,6 +96,7 @@ func NewHostSystem(host mo.HostSystem) *HostSystem {
}{
{&hs.ConfigManager.DatastoreSystem, &HostDatastoreSystem{Host: &hs.HostSystem}},
{&hs.ConfigManager.NetworkSystem, NewHostNetworkSystem(&hs.HostSystem)},
{&hs.ConfigManager.VirtualNicManager, NewHostVirtualNicManager(&hs.HostSystem)},
{&hs.ConfigManager.AdvancedOption, NewOptionManager(nil, nil, &hs.Config.Option)},
{&hs.ConfigManager.FirewallSystem, NewHostFirewallSystem(&hs.HostSystem)},
{&hs.ConfigManager.StorageSystem, NewHostStorageSystem(&hs.HostSystem)},
Expand Down
58 changes: 58 additions & 0 deletions simulator/host_vnic_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
Copyright (c) 2024-2024 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 simulator

Check failure on line 16 in simulator/host_vnic_manager.go

View workflow job for this annotation

GitHub Actions / Boilerplate Check (go)

[Go headers] reported by reviewdog 🐶 found mismatched boilerplate lines: Raw Output: simulator/host_vnic_manager.go:16: found mismatched boilerplate lines: {[]string}[0]: -: "" +: "package simulator"

import (
"github.com/vmware/govmomi/simulator/esx"
"github.com/vmware/govmomi/vim25/methods"
"github.com/vmware/govmomi/vim25/mo"
"github.com/vmware/govmomi/vim25/soap"
"github.com/vmware/govmomi/vim25/types"
)

type HostVirtualNicManager struct {
mo.HostVirtualNicManager

Host *mo.HostSystem
}

func NewHostVirtualNicManager(host *mo.HostSystem) *HostVirtualNicManager {
return &HostVirtualNicManager{
Host: host,
HostVirtualNicManager: mo.HostVirtualNicManager{
Info: types.HostVirtualNicManagerInfo{
NetConfig: esx.VirtualNicManagerNetConfig,
},
},
}
}

func (m *HostVirtualNicManager) QueryNetConfig(req *types.QueryNetConfig) soap.HasFault {
body := new(methods.QueryNetConfigBody)

for _, c := range m.Info.NetConfig {
if c.NicType == req.NicType {
body.Res = &types.QueryNetConfigResponse{
Returnval: &c,
}
return body
}
}

body.Fault_ = Fault("", &types.InvalidArgument{InvalidProperty: req.NicType})

return body
}

0 comments on commit f53de95

Please sign in to comment.