Skip to content

Commit

Permalink
Merge pull request vmware#3428 from dougm/vcsim-vnic-manager
Browse files Browse the repository at this point in the history
vcsim: add HostVirtualNicManager
  • Loading branch information
dougm authored May 13, 2024
2 parents 3a7ad6a + 542398a commit 077b0b0
Show file tree
Hide file tree
Showing 4 changed files with 110 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
47 changes: 47 additions & 0 deletions simulator/esx/host_vnic_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
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

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
59 changes: 59 additions & 0 deletions simulator/host_vnic_manager.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
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

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 077b0b0

Please sign in to comment.