@@ -6,10 +6,12 @@ package driver
6
6
import (
7
7
"context"
8
8
"net"
9
+
10
+ "github.com/lima-vm/lima/pkg/store"
9
11
)
10
12
11
- // Driver interface is used by hostagent for managing vm.
12
- type Driver interface {
13
+ // Basic lifecycle operations
14
+ type Lifecycle interface {
13
15
// Validate returns error if the current driver isn't support for given config
14
16
Validate () error
15
17
@@ -29,43 +31,65 @@ type Driver interface {
29
31
// The second argument may contain error occurred while starting driver
30
32
Start (_ context.Context ) (chan error , error )
31
33
34
+ // Stop will terminate the running vm instance.
35
+ // It returns error if there are any errors during Stop
36
+ Stop (_ context.Context ) error
37
+ }
38
+
39
+ // GUI-related operations
40
+ type GUI interface {
32
41
// CanRunGUI returns bool to indicate if the hostagent need to run GUI synchronously
33
42
CanRunGUI () bool
34
43
35
44
// RunGUI is for starting GUI synchronously by hostagent. This method should be wait and return only after vm terminates
36
45
// It returns error if there are any failures
37
46
RunGUI () error
38
47
39
- // Stop will terminate the running vm instance.
40
- // It returns error if there are any errors during Stop
41
- Stop (_ context.Context ) error
42
-
43
- // Register will add an instance to a registry.
44
- // It returns error if there are any errors during Register
45
- Register (_ context.Context ) error
46
-
47
- // Unregister will perform any cleanup related to the vm instance.
48
- // It returns error if there are any errors during Unregister
49
- Unregister (_ context.Context ) error
50
-
51
- ChangeDisplayPassword (_ context.Context , password string ) error
52
-
53
- GetDisplayConnection (_ context.Context ) (string , error )
54
-
55
- CreateSnapshot (_ context.Context , tag string ) error
56
-
57
- ApplySnapshot (_ context.Context , tag string ) error
48
+ ChangeDisplayPassword (ctx context.Context , password string ) error
49
+ GetDisplayConnection (ctx context.Context ) (string , error )
50
+ }
58
51
59
- DeleteSnapshot (_ context.Context , tag string ) error
52
+ // Snapshot operations
53
+ type Snapshot interface {
54
+ CreateSnapshot (ctx context.Context , tag string ) error
55
+ ApplySnapshot (ctx context.Context , tag string ) error
56
+ DeleteSnapshot (ctx context.Context , tag string ) error
57
+ ListSnapshots (ctx context.Context ) (string , error )
58
+ }
60
59
61
- ListSnapshots (_ context.Context ) (string , error )
60
+ // Registration operations
61
+ type Registration interface {
62
+ Register (ctx context.Context ) error
63
+ Unregister (ctx context.Context ) error
64
+ }
62
65
66
+ // Guest agent operations
67
+ type GuestAgent interface {
63
68
// ForwardGuestAgent returns if the guest agent sock needs forwarding by host agent.
64
69
ForwardGuestAgent () bool
65
70
66
71
// GuestAgentConn returns the guest agent connection, or nil (if forwarded by ssh).
67
72
GuestAgentConn (_ context.Context ) (net.Conn , error )
73
+ }
68
74
69
- // Returns the driver name.
75
+ type Plugin interface {
76
+ // Name returns the name of the driver
70
77
Name () string
78
+
79
+ // Enabled returns whether this driver is available on the current platform.
80
+ // Also checks whether this driver can handle the given config
81
+ Enabled () bool
82
+
83
+ // NewDriver returns a new driver instance. Only to be used to embed internal drivers
84
+ NewDriver (ctx context.Context , inst * store.Instance , sshLocalPort int ) Driver
85
+ }
86
+
87
+ // Driver interface is used by hostagent for managing vm.
88
+ type Driver interface {
89
+ Lifecycle
90
+ GUI
91
+ Snapshot
92
+ Registration
93
+ GuestAgent
94
+ Plugin
71
95
}
0 commit comments