fix host IP for virtualbox

pull/8475/head
jjanik 2020-06-14 14:52:07 +02:00
parent 46b5d4113f
commit bf59d39587
1 changed files with 4 additions and 3 deletions

View File

@ -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: