Skip to content

Commit ebaa100

Browse files
committed
Use loopback for SSH connection in WSL2
Signed-off-by: Arthur Sengileyev <[email protected]>
1 parent bfac818 commit ebaa100

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

Diff for: pkg/store/instance_windows.go

+2-19
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ package store
55

66
import (
77
"fmt"
8-
"os/exec"
98
"regexp"
109
"strings"
1110

@@ -26,7 +25,7 @@ func inspectStatus(instDir string, inst *Instance, y *limayaml.LimaYAML) {
2625
inst.SSHLocalPort = 22
2726

2827
if inst.Status == StatusRunning {
29-
sshAddr, err := getWslSSHAddress(inst.Name)
28+
sshAddr, err := GetSSHAddress(inst.Name)
3029
if err == nil {
3130
inst.SSHAddress = sshAddr
3231
} else {
@@ -118,21 +117,5 @@ func GetWslStatus(instName string) (string, error) {
118117
}
119118

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

0 commit comments

Comments
 (0)