Skip to content

Commit df5e35a

Browse files
committed
Revert "Use loopback for SSH connection in WSL2"
This reverts commit ebaa100. Signed-off-by: Anders F Björklund <[email protected]>
1 parent 8a4811d commit df5e35a

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

pkg/store/instance_windows.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package store
55

66
import (
77
"fmt"
8+
"os/exec"
89
"regexp"
910
"strings"
1011

@@ -115,6 +116,18 @@ func GetWslStatus(instName string) (string, error) {
115116
return instState, nil
116117
}
117118

118-
func GetSSHAddress(_ string) (string, error) {
119-
return "127.0.0.1", nil
119+
// GetSSHAddress runs a hostname command to get the IP from inside of a wsl2 VM.
120+
//
121+
// Expected output (whitespace preserved, [] for optional):
122+
// PS > wsl -d <distroName> bash -c hostname -I | cut -d' ' -f1
123+
// 168.1.1.1 [10.0.0.1]
124+
func GetSSHAddress(instName string) (string, error) {
125+
distroName := "lima-" + instName
126+
cmd := exec.Command("wsl.exe", "-d", distroName, "bash", "-c", `hostname -I | cut -d ' ' -f1`)
127+
out, err := cmd.CombinedOutput()
128+
if err != nil {
129+
return "", fmt.Errorf("failed to get hostname for instance %q, err: %w (out=%q)", instName, err, string(out))
130+
}
131+
132+
return strings.TrimSpace(string(out)), nil
120133
}

0 commit comments

Comments
 (0)