@@ -6,10 +6,12 @@ package driver
66import (
77 "context"
88 "net"
9+
10+ "github.com/lima-vm/lima/pkg/store"
911)
1012
11- // Driver interface is used by hostagent for managing vm .
12- type Driver interface {
13+ // Lifecycle defines basic lifecycle operations .
14+ type Lifecycle interface {
1315 // Validate returns error if the current driver isn't support for given config
1416 Validate () error
1517
@@ -29,43 +31,66 @@ type Driver interface {
2931 // The second argument may contain error occurred while starting driver
3032 Start (_ context.Context ) (chan error , error )
3133
32- // CanRunGUI returns bool to indicate if the hostagent need to run GUI synchronously
33- CanRunGUI () bool
34-
35- // RunGUI is for starting GUI synchronously by hostagent. This method should be wait and return only after vm terminates
36- // It returns error if there are any failures
37- RunGUI () error
38-
3934 // Stop will terminate the running vm instance.
4035 // It returns error if there are any errors during Stop
4136 Stop (_ context.Context ) error
37+ }
4238
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
39+ // GUI defines GUI-related operations.
40+ type GUI interface {
41+ // RunGUI is for starting GUI synchronously by hostagent. This method should be wait and return only after vm terminates
42+ // It returns error if there are any failures
43+ RunGUI () error
4644
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
45+ ChangeDisplayPassword ( ctx context. Context , password string ) error
46+ DisplayConnection ( ctx context. Context ) ( string , error )
47+ }
5048
51- ChangeDisplayPassword (_ context.Context , password string ) error
49+ // SnapshotManager defines operations for managing snapshots.
50+ type SnapshotManager interface {
51+ CreateSnapshot (ctx context.Context , tag string ) error
52+ ApplySnapshot (ctx context.Context , tag string ) error
53+ DeleteSnapshot (ctx context.Context , tag string ) error
54+ ListSnapshots (ctx context.Context ) (string , error )
55+ }
5256
53- GetDisplayConnection (_ context.Context ) (string , error )
57+ // Registration defines operations for registering and unregistering the driver instance.
58+ type Registration interface {
59+ Register (ctx context.Context ) error
60+ Unregister (ctx context.Context ) error
61+ }
5462
55- CreateSnapshot (_ context.Context , tag string ) error
63+ // GuestAgent defines operations for the guest agent.
64+ type GuestAgent interface {
65+ // ForwardGuestAgent returns if the guest agent sock needs forwarding by host agent.
66+ ForwardGuestAgent () bool
5667
57- ApplySnapshot (_ context.Context , tag string ) error
68+ // GuestAgentConn returns the guest agent connection, or nil (if forwarded by ssh).
69+ GuestAgentConn (_ context.Context ) (net.Conn , string , error )
70+ }
5871
59- DeleteSnapshot (_ context.Context , tag string ) error
72+ // Driver interface is used by hostagent for managing vm.
73+ type Driver interface {
74+ Lifecycle
75+ GUI
76+ SnapshotManager
77+ Registration
78+ GuestAgent
6079
61- ListSnapshots ( _ context. Context ) ( string , error )
80+ Info () Info
6281
63- // ForwardGuestAgent returns if the guest agent sock needs forwarding by host agent.
64- ForwardGuestAgent () bool
82+ // SetConfig sets the configuration for the instance.
83+ Configure (inst * store.Instance , sshLocalPort int ) * ConfiguredDriver
84+ }
6585
66- // GuestAgentConn returns the guest agent connection, or nil (if forwarded by ssh).
67- GuestAgentConn (_ context.Context ) (net.Conn , error )
86+ type ConfiguredDriver struct {
87+ Driver
88+ }
6889
69- VSockPort () int
70- VirtioPort () string
90+ type Info struct {
91+ DriverName string `json:"driverName"`
92+ CanRunGUI bool `json:"canRunGui,omitempty"`
93+ VsockPort int `json:"vsockPort"`
94+ VirtioPort string `json:"virtioPort"`
95+ InstanceDir string `json:"instanceDir,omitempty"`
7196}
0 commit comments