[hyperv] if no vswitch is specified, only pick the first external one
Signed-off-by: Dowideit, Sven (O&A, St. Lucia) <Sven.Dowideit@csiro.au>
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user