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

Use vmrun to find guest IP #1

Closed
wants to merge 1 commit into from
Closed
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)
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