未验证 提交 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 ( ...@@ -20,6 +20,7 @@ import (
"fmt" "fmt"
"net" "net"
"os/exec" "os/exec"
"reflect"
"regexp" "regexp"
"github.com/docker/machine/libmachine" "github.com/docker/machine/libmachine"
...@@ -40,9 +41,18 @@ func HostIP(host *host.Host) (net.IP, error) { ...@@ -40,9 +41,18 @@ func HostIP(host *host.Host) (net.IP, error) {
case driver.KVM2: case driver.KVM2:
return net.ParseIP("192.168.39.1"), nil return net.ParseIP("192.168.39.1"), nil
case driver.HyperV: case driver.HyperV:
re := regexp.MustCompile(`"VSwitch": "(.*?)",`) v := reflect.ValueOf(host.Driver).Elem()
// TODO(aprindle) Change this to deserialize the driver instead var hypervVirtualSwitch string
hypervVirtualSwitch := re.FindStringSubmatch(string(host.RawDriver))[1] // 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)) ip, err := getIPForInterface(fmt.Sprintf("vEthernet (%s)", hypervVirtualSwitch))
if err != nil { if err != nil {
return []byte{}, errors.Wrap(err, fmt.Sprintf("ip for interface (%s)", hypervVirtualSwitch)) 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.
先完成此消息的编辑!
想要评论请 注册