Skip to content

Commit

Permalink
FIX docker#512 Check the virtual switch in PreCreateCheck()
Browse files Browse the repository at this point in the history
Signed-off-by: David Gageot <david@gageot.net>
  • Loading branch information
dgageot committed Dec 23, 2015
1 parent aa3a4e4 commit d5e11fb
Showing 1 changed file with 27 additions and 8 deletions.
35 changes: 27 additions & 8 deletions drivers/hyperv/hyperv.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,12 @@ func (d *Driver) PreCreateCheck() error {
return err
}

// Check that there is a virtual switch already configured
_, err := d.chooseVirtualSwitch()
if err != nil {
return err
}

// Downloading boot2docker to cache should be done here to make sure
// that a download failure will not leave a machine half created.
b2dutils := mcnutils.NewB2dUtils(d.StorePath)
Expand Down Expand Up @@ -155,6 +161,8 @@ func (d *Driver) Create() error {
return err
}

log.Infof("Using switch %q", virtualSwitch)

err = d.generateDiskImage()
if err != nil {
return err
Expand All @@ -181,23 +189,34 @@ func (d *Driver) Create() error {
}

func (d *Driver) chooseVirtualSwitch() (string, error) {
if d.vSwitch != "" {
return d.vSwitch, nil
}

stdout, err := cmdOut("@(Get-VMSwitch).Name")
if err != nil {
return "", err
}

switches := parseLines(stdout)
if len(switches) < 1 {
return "", fmt.Errorf("no vswitch found")

if d.vSwitch == "" {
if len(switches) < 1 {
return "", fmt.Errorf("no vswitch found")
}

return switches[0], nil
}

log.Infof("Using switch %s", switches[0])
found := false
for _, name := range switches {
if name == d.vSwitch {
found = true
break
}
}

if !found {
return "", fmt.Errorf("vswitch %q not found", d.vSwitch)
}

return switches[0], nil
return d.vSwitch, nil
}

func (d *Driver) wait() error {
Expand Down

0 comments on commit d5e11fb

Please sign in to comment.