Add HostIP implementation for parallels driver

pull/8259/head
Mikhail Zholobov 2020-05-23 18:49:50 +02:00
parent 49905d8fea
commit c22a92f9bf
No known key found for this signature in database
GPG Key ID: 467E2D8B15AE6DB3
1 changed files with 19 additions and 0 deletions

View File

@ -72,6 +72,25 @@ func HostIP(host *host.Host) (net.IP, error) {
re = regexp.MustCompile(`(?s)Name:\s*` + iface + `.+IPAddress:\s*(\S+)`)
ip := re.FindStringSubmatch(string(ipList))[1]
return net.ParseIP(ip), nil
case driver.Parallels:
cmd := "prlsrvctl"
var cmdPath string
if fullPath, err := exec.LookPath(cmd); err != nil {
cmdPath = fullPath
} else {
cmdPath = cmd
}
out, err := exec.Command(cmdPath, "net", "info", "Shared").Output()
if err != nil {
return []byte{}, errors.Wrap(err, "Error reading the info of Parallels Shared network interface")
}
re := regexp.MustCompile(`IPv4 address: (.*)`)
ipMatch := re.FindStringSubmatch(string(out))
if len(ipMatch) < 2 {
return []byte{}, errors.Wrap(err, "Error getting the IP address of Parallels Shared network interface")
}
ip := ipMatch[1]
return net.ParseIP(ip), nil
case driver.HyperKit:
return net.ParseIP("192.168.64.1"), nil
case driver.VMware: