fix host IP for virtualbox
parent
46b5d4113f
commit
bf59d39587
|
@ -59,17 +59,18 @@ func HostIP(host *host.Host) (net.IP, error) {
|
|||
}
|
||||
return ip, nil
|
||||
case driver.VirtualBox:
|
||||
out, err := exec.Command(driver.VBoxManagePath(), "showvminfo", host.Name, "--machinereadable").Output()
|
||||
vBoxManageCmd := driver.VBoxManagePath()
|
||||
out, err := exec.Command(vBoxManageCmd, "showvminfo", host.Name, "--machinereadable").Output()
|
||||
if err != nil {
|
||||
return []byte{}, errors.Wrap(err, "vboxmanage")
|
||||
}
|
||||
re := regexp.MustCompile(`hostonlyadapter2="(.*?)"`)
|
||||
iface := re.FindStringSubmatch(string(out))[1]
|
||||
ipList, err := exec.Command(driver.VBoxManagePath(), "list", "hostonlyifs").Output()
|
||||
ipList, err := exec.Command(vBoxManageCmd, "list", "hostonlyifs").Output()
|
||||
if err != nil {
|
||||
return []byte{}, errors.Wrap(err, "Error getting VM/Host IP address")
|
||||
}
|
||||
re = regexp.MustCompile(`(?s)Name:\s*` + iface + `.+IPAddress:\s*(\S+)`)
|
||||
re = regexp.MustCompile(`(?sm)Name:\s*` + iface + `\s*$.+?IPAddress:\s*(\S+)`)
|
||||
ip := re.FindStringSubmatch(string(ipList))[1]
|
||||
return net.ParseIP(ip), nil
|
||||
case driver.Parallels:
|
||||
|
|
Loading…
Reference in New Issue