Skip to content

Commit 5980d9d

Browse files
authored
Use vmrun to find guest IP
Since there is no more vmnet devices on Big Sur, there's no DHCP lease update either. Find ip using vmrun's own feature first, falling back to the legacy ones next. Fixes docker-archive-public#4846
1 parent b170508 commit 5980d9d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

drivers/vmwarefusion/fusion_darwin.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,11 @@ func (d *Driver) GetIP() (string, error) {
194194
return "", err
195195
}
196196

197+
// attempt to find the address from vmrun
198+
if ip, err := d.getIPfromVmrun(); err == nil {
199+
return ip, err
200+
}
201+
197202
// attempt to find the address in the vmnet configuration
198203
if ip, err := d.getIPfromVmnetConfiguration(macaddr); err == nil {
199204
return ip, err
@@ -535,6 +540,18 @@ func (d *Driver) getIPfromVmnetConfiguration(macaddr string) (string, error) {
535540
return "", fmt.Errorf("IP not found for MAC %s in vmnet configuration files", macaddr)
536541
}
537542

543+
func (d *Driver) getIPfromVmrun() (string, error) {
544+
vmx := d.vmxPath()
545+
546+
ip := regexp.MustCompile(`(\d+\.\d+\.\d+\.\d+)`)
547+
stdout, _, _ := vmrun("getGuestIPAddress", vmx)
548+
if matches := ip.FindStringSubmatch(stdout); matches != nil {
549+
return matches[1], nil
550+
}
551+
552+
return "", fmt.Errorf("could not get IP from vmrun")
553+
}
554+
538555
func (d *Driver) getIPfromVmnetConfigurationFile(conffile, macaddr string) (string, error) {
539556
var conffh *os.File
540557
var confcontent []byte

0 commit comments

Comments
 (0)