@@ -25,44 +25,45 @@ import (
25
25
// FindMachineByPort finds a running machine that matches the given connection port.
26
26
// It returns the machine configuration and provider, or an error if not found.
27
27
func FindMachineByPort (connectionURI string , parsedConnection * url.URL ) (* vmconfigs.MachineConfig , vmconfigs.VMProvider , error ) {
28
- machineProvider , err := provider .Get ()
29
- if err != nil {
30
- return nil , nil , fmt .Errorf ("getting machine provider: %w" , err )
31
- }
32
-
33
- dirs , err := env .GetMachineDirs (machineProvider .VMType ())
34
- if err != nil {
35
- return nil , nil , err
36
- }
37
-
38
- machineList , err := vmconfigs .LoadMachinesInDir (dirs )
39
- if err != nil {
40
- return nil , nil , fmt .Errorf ("listing machines: %w" , err )
41
- }
42
-
43
- // Now we know that the connection points to a machine and we
44
- // can find the machine by looking for the one with the
45
- // matching port.
46
- connectionPort , err := strconv .Atoi (parsedConnection .Port ())
47
- if err != nil {
48
- return nil , nil , fmt .Errorf ("parsing connection port: %w" , err )
49
- }
50
-
51
- for _ , mc := range machineList {
52
- if connectionPort != mc .SSH .Port {
28
+ for _ , machineProvider := range provider .GetAll () {
29
+ logrus .Debugf ("Checking provider: %s" , machineProvider .VMType ())
30
+ dirs , err := env .GetMachineDirs (machineProvider .VMType ())
31
+ if err != nil {
32
+ logrus .Debugf ("Failed to get machine dirs for provider %s: %v" , machineProvider .VMType (), err )
53
33
continue
54
34
}
55
35
56
- state , err := machineProvider . State ( mc , false )
36
+ machineList , err := vmconfigs . LoadMachinesInDir ( dirs )
57
37
if err != nil {
58
- return nil , nil , err
38
+ logrus .Debugf ("Failed to list machines: %v" , err )
39
+ continue
59
40
}
60
41
61
- if state != define .Running {
62
- return nil , nil , fmt .Errorf ("machine %s is not running but in state %s" , mc .Name , state )
42
+ // Now we know that the connection points to a machine and we
43
+ // can find the machine by looking for the one with the
44
+ // matching port.
45
+ connectionPort , err := strconv .Atoi (parsedConnection .Port ())
46
+ if err != nil {
47
+ logrus .Debugf ("Failed to parse connection port: %v" , err )
48
+ continue
63
49
}
64
50
65
- return mc , machineProvider , nil
51
+ for _ , mc := range machineList {
52
+ if connectionPort != mc .SSH .Port {
53
+ continue
54
+ }
55
+
56
+ state , err := machineProvider .State (mc , false )
57
+ if err != nil {
58
+ return nil , nil , err
59
+ }
60
+
61
+ if state != define .Running {
62
+ return nil , nil , fmt .Errorf ("machine %s is not running but in state %s" , mc .Name , state )
63
+ }
64
+
65
+ return mc , machineProvider , nil
66
+ }
66
67
}
67
68
68
69
return nil , nil , fmt .Errorf ("could not find a matching machine for connection %q" , connectionURI )
@@ -203,7 +204,7 @@ func IsHyperVProvider(ctx context.Context) (bool, error) {
203
204
204
205
_ , vmType , err := getMachineMountsAndVMType (conn .URI .String (), conn .URI )
205
206
if err != nil {
206
- logrus .Debugf ("Failed to get machine mounts : %v" , err )
207
+ logrus .Debugf ("Failed to get machine hypervisor type : %v" , err )
207
208
return false , err
208
209
}
209
210
0 commit comments