Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Use vmrun to find guest IP #4847

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions drivers/vmwarefusion/fusion_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this works in VMWare headless mode - there appears to be a bug that requires passing the -wait option to getGuestIPAddress otherwise it returns Error: The VMware Tools are not running in the virtual machine.

Also see machine-drivers/docker-machine-driver-vmware#31 (comment)

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
Expand Down