Skip to content

Commit

Permalink
make processing of mac addresses case insensitive (vmware#2510)
Browse files Browse the repository at this point in the history
Closes: vmware#2509
  • Loading branch information
rconde01 authored and protochron committed Aug 31, 2021
1 parent c98380c commit e12f51d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
34 changes: 34 additions & 0 deletions govc/test/vm.bats
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
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

0 comments on commit e12f51d

Please sign in to comment.