Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make processing of mac addresses case insensitive #2510

Merged
merged 2 commits into from
Jul 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions govc/test/vm.bats
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,40 @@ load test_helper
assert_equal $ip $res
}

@test "vm.ip capital MAC" {
vcsim_env -autostart=false

id=/DC0/vm/DC0_H0_VM0

mac=00:50:56:83:3A:5D
run govc vm.customize -vm $id -mac $mac -ip 10.0.0.1 -netmask 255.255.0.0 -type Linux
assert_success

run govc vm.power -on $id
assert_success

run govc vm.ip -wait 5s $id
assert_success

run govc vm.ip -wait 5s -a -v4 $id
assert_success

run govc vm.ip -wait 5s -n $mac $id
assert_success

run govc vm.ip -wait 5s -n ethernet-0 $id
assert_success

ip=$(govc vm.ip -wait 5s $id)

# add a second nic
run govc vm.network.add -vm $id "VM Network"
assert_success

res=$(govc vm.ip -wait 5s -n ethernet-0 $id)
assert_equal $ip $res
}

@test "vm.ip -esxcli" {
esx_env

Expand Down
9 changes: 7 additions & 2 deletions object/virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"net"
"path"
"strings"

"github.com/vmware/govmomi/nfc"
"github.com/vmware/govmomi/property"
Expand Down Expand Up @@ -333,7 +334,9 @@ func (v VirtualMachine) WaitForNetIP(ctx context.Context, v4 bool, device ...str
devices := VirtualDeviceList(c.Val.(types.ArrayOfVirtualDevice).VirtualDevice)
for _, d := range devices {
if nic, ok := d.(types.BaseVirtualEthernetCard); ok {
mac := nic.GetVirtualEthernetCard().MacAddress
// Convert to lower so that e.g. 00:50:56:83:3A:5D is treated the
// same as 00:50:56:83:3a:5d
mac := strings.ToLower(nic.GetVirtualEthernetCard().MacAddress)
if mac == "" {
return false
}
Expand Down Expand Up @@ -369,7 +372,9 @@ func (v VirtualMachine) WaitForNetIP(ctx context.Context, v4 bool, device ...str

nics := c.Val.(types.ArrayOfGuestNicInfo).GuestNicInfo
for _, nic := range nics {
mac := nic.MacAddress
// Convert to lower so that e.g. 00:50:56:83:3A:5D is treated the
// same as 00:50:56:83:3a:5d
mac := strings.ToLower(nic.MacAddress)
if mac == "" || nic.IpConfig == nil {
continue
}
Expand Down