From 5980d9d0b3317e99ef22fddc00f45e909c9d8221 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Fri, 13 Nov 2020 11:54:20 +0100 Subject: [PATCH] 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/machine#4846 --- drivers/vmwarefusion/fusion_darwin.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/vmwarefusion/fusion_darwin.go b/drivers/vmwarefusion/fusion_darwin.go index fb22c96ab5..b1dcff5ed0 100644 --- a/drivers/vmwarefusion/fusion_darwin.go +++ b/drivers/vmwarefusion/fusion_darwin.go @@ -194,6 +194,11 @@ func (d *Driver) GetIP() (string, error) { return "", err } + // attempt to find the address from vmrun + if ip, err := d.getIPfromVmrun(); err == nil { + return ip, err + } + // attempt to find the address in the vmnet configuration if ip, err := d.getIPfromVmnetConfiguration(macaddr); err == nil { return ip, err @@ -535,6 +540,18 @@ func (d *Driver) getIPfromVmnetConfiguration(macaddr string) (string, error) { return "", fmt.Errorf("IP not found for MAC %s in vmnet configuration files", macaddr) } +func (d *Driver) getIPfromVmrun() (string, error) { + vmx := d.vmxPath() + + ip := regexp.MustCompile(`(\d+\.\d+\.\d+\.\d+)`) + stdout, _, _ := vmrun("getGuestIPAddress", vmx) + if matches := ip.FindStringSubmatch(stdout); matches != nil { + return matches[1], nil + } + + return "", fmt.Errorf("could not get IP from vmrun") +} + func (d *Driver) getIPfromVmnetConfigurationFile(conffile, macaddr string) (string, error) { var conffh *os.File var confcontent []byte