From 997d9ddc757adb8a6e322133df11b190eaaf11a3 Mon Sep 17 00:00:00 2001 From: Doug MacEachern Date: Fri, 20 Jan 2023 12:16:16 -0800 Subject: [PATCH] vcsim: add guest.net.ipConfig This is needed to support the VirtualMachine.WaitForNetIP helper against vcsim --- govc/test/vcsim.bats | 9 +++++++++ simulator/container.go | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/govc/test/vcsim.bats b/govc/test/vcsim.bats index 6b9f44d1d..7dba6c967 100755 --- a/govc/test/vcsim.bats +++ b/govc/test/vcsim.bats @@ -267,6 +267,15 @@ EOF netip=$(govc object.collect -json -s vm/$vm guest.net | jq -r .[].Val.GuestNicInfo[].IpAddress[0]) [ "$netip" = "$ip" ] + run govc vm.ip $vm # covers VirtualMachine.WaitForIP + assert_success "$ip" + + run govc vm.ip -a $vm # covers VirtualMachine.WaitForNetIP + assert_success "$ip" + + run govc vm.ip -n ethernet-0 $vm # covers VirtualMachine.WaitForNetIP + assert_success "$ip" + run govc vm.power -s $vm assert_success diff --git a/simulator/container.go b/simulator/container.go index 08f8f7ed1..96f4fd10c 100644 --- a/simulator/container.go +++ b/simulator/container.go @@ -114,6 +114,20 @@ func (c *container) inspect(vm *VirtualMachine) error { net := &vm.Guest.Net[0] net.IpAddress = []string{s.IPAddress} net.MacAddress = s.MacAddress + net.IpConfig = &types.NetIpConfigInfo{ + IpAddress: []types.NetIpConfigInfoIpAddress{{ + IpAddress: s.IPAddress, + PrefixLength: int32(s.IPPrefixLen), + State: string(types.NetIpConfigInfoIpAddressStatusPreferred), + }}, + } + } + + for _, d := range vm.Config.Hardware.Device { + if eth, ok := d.(types.BaseVirtualEthernetCard); ok { + eth.GetVirtualEthernetCard().MacAddress = s.MacAddress + break + } } }