Skip to content

Commit 30acfcb

Browse files
Dowideit, Sven (O&A, St. Lucia)Dowideit, Sven (O&A, St. Lucia)
authored andcommitted
[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>
1 parent 0cfc858 commit 30acfcb

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

drivers/hyperv/hyperv.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -255,21 +255,29 @@ func (d *Driver) Create() error {
255255
}
256256

257257
func (d *Driver) chooseVirtualSwitch() (string, error) {
258-
stdout, err := cmdOut("(Get-VMSwitch).Name")
259-
if err != nil {
260-
return "", err
261-
}
258+
if d.VSwitch == "" {
259+
// Default to the first external switche and in the process avoid DockerNAT
260+
stdout, err := cmdOut("(Get-VMSwitch -SwitchType External).Name")
261+
if err != nil {
262+
return "", err
263+
}
262264

263-
switches := parseLines(stdout)
265+
switches := parseLines(stdout)
264266

265-
if d.VSwitch == "" {
266267
if len(switches) < 1 {
267-
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/")
268+
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/")
268269
}
269270

270271
return switches[0], nil
271272
}
272273

274+
stdout, err := cmdOut("(Get-VMSwitch).Name")
275+
if err != nil {
276+
return "", err
277+
}
278+
279+
switches := parseLines(stdout)
280+
273281
found := false
274282
for _, name := range switches {
275283
if name == d.VSwitch {

0 commit comments

Comments
 (0)