From 30acfcbedcdac8a8191a8508fc23ceec3024938e Mon Sep 17 00:00:00 2001 From: "Dowideit, Sven (O&A, St. Lucia)" Date: Tue, 30 Jan 2018 16:11:39 +1000 Subject: [PATCH] [hyperv] if no vswitch is specified, only pick the first external one Signed-off-by: Dowideit, Sven (O&A, St. Lucia) --- drivers/hyperv/hyperv.go | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/hyperv/hyperv.go b/drivers/hyperv/hyperv.go index 6a46ab6d..690256b8 100644 --- a/drivers/hyperv/hyperv.go +++ b/drivers/hyperv/hyperv.go @@ -255,6 +255,22 @@ func (d *Driver) Create() error { } func (d *Driver) chooseVirtualSwitch() (string, error) { + if d.VSwitch == "" { + // Default to the first external switche and in the process avoid DockerNAT + stdout, err := cmdOut("(Get-VMSwitch -SwitchType External).Name") + if err != nil { + return "", err + } + + switches := parseLines(stdout) + + if len(switches) < 1 { + return "", fmt.Errorf("no External vswitch found. A valid vswitch must be available for this command to run. Check https://docs.docker.com/machine/drivers/hyper-v/") + } + + return switches[0], nil + } + stdout, err := cmdOut("(Get-VMSwitch).Name") if err != nil { return "", err @@ -262,14 +278,6 @@ func (d *Driver) chooseVirtualSwitch() (string, error) { switches := parseLines(stdout) - if d.VSwitch == "" { - if len(switches) < 1 { - return "", fmt.Errorf("no vswitch found. A valid vswitch must be available for this command to run. Check https://docs.docker.com/machine/drivers/hyper-v/") - } - - return switches[0], nil - } - found := false for _, name := range switches { if name == d.VSwitch {