未验证 提交 64173240 编写于 作者: M Medya Ghazizadeh 提交者: GitHub

Merge pull request #8103 from sharifelgamal/vswitch

retrieve virtual switch name from driver object directly
......@@ -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))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册