Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #4378 from SvenDowideit/default-to-external-switch
Browse files Browse the repository at this point in the history
[hyperv] if no vswitch is specified, only pick the first external one
  • Loading branch information
dgageot authored Feb 1, 2018
2 parents 86f9487 + 30acfcb commit d9615a5
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions drivers/hyperv/hyperv.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,21 +255,29 @@ func (d *Driver) Create() error {
}

func (d *Driver) chooseVirtualSwitch() (string, error) {
stdout, err := cmdOut("(Get-VMSwitch).Name")
if err != nil {
return "", err
}
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)
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 "", 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
}

switches := parseLines(stdout)

found := false
for _, name := range switches {
if name == d.VSwitch {
Expand Down

0 comments on commit d9615a5

Please sign in to comment.