From f53de955d8dacb81cf69a0287397cc30a77b49fd Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Thu, 25 Apr 2024 17:02:05 -0700 Subject: [PATCH] vcsim: add HostVirtualNicManager --- govc/test/host.bats | 2 +- simulator/esx/host_vnic_manager.go | 46 ++++++++++++++++++++++++ simulator/host_system.go | 5 +-- simulator/host_vnic_manager.go | 58 ++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+), 3 deletions(-) create mode 100644 simulator/esx/host_vnic_manager.go create mode 100644 simulator/host_vnic_manager.go diff --git a/govc/test/host.bats b/govc/test/host.bats index 1aac47129..9364dc656 100755 --- a/govc/test/host.bats +++ b/govc/test/host.bats @@ -106,7 +106,7 @@ load test_helper } @test "host.vnic.info" { - esx_env + vcsim_env run govc host.vnic.info assert_success diff --git a/simulator/esx/host_vnic_manager.go b/simulator/esx/host_vnic_manager.go new file mode 100644 index 000000000..725b3bef5 --- /dev/null +++ b/simulator/esx/host_vnic_manager.go @@ -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 + +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"}, + }, +} diff --git a/simulator/host_system.go b/simulator/host_system.go index 6dcab0d9d..6c7705e59 100644 --- a/simulator/host_system.go +++ b/simulator/host_system.go @@ -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, @@ -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)}, diff --git a/simulator/host_vnic_manager.go b/simulator/host_vnic_manager.go new file mode 100644 index 000000000..a00bc9df5 --- /dev/null +++ b/simulator/host_vnic_manager.go @@ -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 + +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 +}