Skip to content

Commit 0fa3176

Browse files
committed
driver(internal): divide the driver.Driver interface and define some plugin related functions
Signed-off-by: Ansuman Sahoo <[email protected]>
1 parent 7fbd83a commit 0fa3176

File tree

1 file changed

+48
-24
lines changed

1 file changed

+48
-24
lines changed

pkg/driver/driver.go

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ package driver
66
import (
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+
// 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,65 @@ type Driver interface {
2931
// The second argument may contain error occurred while starting driver
3032
Start(_ context.Context) (chan error, error)
3133

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 {
3241
// CanRunGUI returns bool to indicate if the hostagent need to run GUI synchronously
3342
CanRunGUI() bool
3443

3544
// RunGUI is for starting GUI synchronously by hostagent. This method should be wait and return only after vm terminates
3645
// It returns error if there are any failures
3746
RunGUI() error
3847

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+
}
5851

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+
}
6059

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+
}
6265

66+
// Guest agent operations
67+
type GuestAgent interface {
6368
// ForwardGuestAgent returns if the guest agent sock needs forwarding by host agent.
6469
ForwardGuestAgent() bool
6570

6671
// GuestAgentConn returns the guest agent connection, or nil (if forwarded by ssh).
6772
GuestAgentConn(_ context.Context) (net.Conn, error)
73+
}
6874

69-
// Returns the driver name.
75+
type Plugin interface {
76+
// Name returns the name of the driver
7077
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
7195
}

0 commit comments

Comments
 (0)