allow for prefix interace names for hyperv
parent
46a4377498
commit
f92015df9b
|
@ -22,6 +22,7 @@ import (
|
|||
"os/exec"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/machine/libmachine"
|
||||
"github.com/docker/machine/libmachine/host"
|
||||
|
@ -134,7 +135,23 @@ func DriverIP(api libmachine.API, machineName string) (net.IP, error) {
|
|||
|
||||
// Based on code from http://stackoverflow.com/questions/23529663/how-to-get-all-addresses-and-masks-from-local-interfaces-in-go
|
||||
func getIPForInterface(name string) (net.IP, error) {
|
||||
i, _ := net.InterfaceByName(name)
|
||||
ints, err := net.Interfaces()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var i net.Interface
|
||||
for _, in := range ints {
|
||||
if strings.HasPrefix(in.Name, name) {
|
||||
i = in
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if i.Name == "" {
|
||||
return nil, errors.Errorf("Could not find interface %s", name)
|
||||
}
|
||||
|
||||
addrs, _ := i.Addrs()
|
||||
for _, a := range addrs {
|
||||
if ipnet, ok := a.(*net.IPNet); ok {
|
||||
|
|
Loading…
Reference in New Issue