retrieve virtual switch name from driver object directly
parent
5b7f8096ab
commit
e65486a017
|
|
@ -20,6 +20,7 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
"os/exec"
|
||||
"reflect"
|
||||
"regexp"
|
||||
|
||||
"github.com/docker/machine/libmachine"
|
||||
|
|
@ -40,9 +41,18 @@ func HostIP(host *host.Host) (net.IP, error) {
|
|||
case driver.KVM2:
|
||||
return net.ParseIP("192.168.39.1"), nil
|
||||
case driver.HyperV:
|
||||
re := regexp.MustCompile(`"VSwitch": "(.*?)",`)
|
||||
// TODO(aprindle) Change this to deserialize the driver instead
|
||||
hypervVirtualSwitch := re.FindStringSubmatch(string(host.RawDriver))[1]
|
||||
v := reflect.ValueOf(host.Driver).Elem()
|
||||
var hypervVirtualSwitch string
|
||||
// We don't have direct access to hyperv.Driver so use reflection to retrieve the virtual switch name
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
if v.Type().Field(i).Name == "VSwitch" {
|
||||
hypervVirtualSwitch = v.Field(i).Interface().(string)
|
||||
break
|
||||
}
|
||||
}
|
||||
if hypervVirtualSwitch == "" {
|
||||
return nil, errors.New("No virtual switch found")
|
||||
}
|
||||
ip, err := getIPForInterface(fmt.Sprintf("vEthernet (%s)", hypervVirtualSwitch))
|
||||
if err != nil {
|
||||
return []byte{}, errors.Wrap(err, fmt.Sprintf("ip for interface (%s)", hypervVirtualSwitch))
|
||||
|
|
|
|||
Loading…
Reference in New Issue