@@ -26,44 +26,46 @@ import (
26
26
// FindMachineByPort finds a running machine that matches the given connection port.
27
27
// It returns the machine configuration and provider, or an error if not found.
28
28
func FindMachineByPort (connectionURI string , parsedConnection * url.URL ) (* vmconfigs.MachineConfig , vmconfigs.VMProvider , error ) {
29
- machineProvider , err := provider .Get ()
30
- if err != nil {
31
- return nil , nil , fmt .Errorf ("getting machine provider: %w" , err )
32
- }
33
-
34
- dirs , err := env .GetMachineDirs (machineProvider .VMType ())
35
- if err != nil {
36
- return nil , nil , err
37
- }
38
-
39
- machineList , err := vmconfigs .LoadMachinesInDir (dirs )
40
- if err != nil {
41
- return nil , nil , fmt .Errorf ("listing machines: %w" , err )
42
- }
43
-
44
- // Now we know that the connection points to a machine and we
45
- // can find the machine by looking for the one with the
46
- // matching port.
47
- connectionPort , err := strconv .Atoi (parsedConnection .Port ())
48
- if err != nil {
49
- return nil , nil , fmt .Errorf ("parsing connection port: %w" , err )
50
- }
51
-
52
- for _ , mc := range machineList {
53
- if connectionPort != mc .SSH .Port {
29
+ for _ , machineProvider := range provider .GetAll () {
30
+ logrus .Debugf ("Checking provider: %s" , machineProvider .VMType ())
31
+ dirs , err := env .GetMachineDirs (machineProvider .VMType ())
32
+ if err != nil {
33
+ logrus .Debugf ("Failed to get machine dirs for provider %s: %v" , machineProvider .VMType (), err )
54
34
continue
55
35
}
56
36
57
- state , err := machineProvider . State ( mc , false )
37
+ machineList , err := vmconfigs . LoadMachinesInDir ( dirs )
58
38
if err != nil {
59
- return nil , nil , err
39
+ logrus .Debugf ("Failed to list machines: %v" , err )
40
+ continue
60
41
}
61
42
62
- if state != define .Running {
63
- return nil , nil , fmt .Errorf ("machine %s is not running but in state %s" , mc .Name , state )
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
+ logrus .Debugf ("Failed to parse connection port: %v" , err )
49
+ continue
64
50
}
65
51
66
- return mc , machineProvider , nil
52
+ for _ , mc := range machineList {
53
+ if connectionPort != mc .SSH .Port {
54
+ continue
55
+ }
56
+
57
+ state , err := machineProvider .State (mc , false )
58
+ if err != nil {
59
+ logrus .Debugf ("Failed to get machine state for %s: %v" , mc .Name , err )
60
+ continue
61
+ }
62
+
63
+ if state != define .Running {
64
+ return nil , nil , fmt .Errorf ("machine %s is not running but in state %s" , mc .Name , state )
65
+ }
66
+
67
+ return mc , machineProvider , nil
68
+ }
67
69
}
68
70
69
71
return nil , nil , fmt .Errorf ("could not find a matching machine for connection %q" , connectionURI )
@@ -244,13 +246,13 @@ func IsHyperVProvider(ctx context.Context) (bool, error) {
244
246
return false , err
245
247
}
246
248
247
- _ , vmType , err := getMachineMountsAndVMType (conn .URI .String (), conn .URI )
249
+ _ , vmProvider , err := FindMachineByPort (conn .URI .String (), conn .URI )
248
250
if err != nil {
249
- logrus .Debugf ("Failed to get machine mounts : %v" , err )
251
+ logrus .Debugf ("Failed to get machine hypervisor type : %v" , err )
250
252
return false , err
251
253
}
252
254
253
- return vmType == define .HyperVVirt , nil
255
+ return vmProvider . VMType () == define .HyperVVirt , nil
254
256
}
255
257
256
258
// ValidatePathForLocalAPI checks if the provided path satisfies requirements for local API usage.
0 commit comments