Skip to content

Commit 57a2080

Browse files
committed
refactor(BaseDriver): make drivers implement the driver.Driver interface
Signed-off-by: Ansuman Sahoo <[email protected]>
1 parent c1a08a1 commit 57a2080

File tree

3 files changed

+130
-12
lines changed

3 files changed

+130
-12
lines changed

pkg/qemu/qemu_driver.go

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ type LimaQemuDriver struct {
4747
vhostCmds []*exec.Cmd
4848
}
4949

50-
func New(inst *store.Instance) *LimaQemuDriver {
50+
func New(inst *store.Instance, sshLocalPort int) *LimaQemuDriver {
5151
// virtserialport doesn't seem to work reliably: https://github.com/lima-vm/lima/issues/2064
5252
// but on Windows default Unix socket forwarding is not available
5353
var virtioPort string
@@ -56,9 +56,10 @@ func New(inst *store.Instance) *LimaQemuDriver {
5656
virtioPort = ""
5757
}
5858
return &LimaQemuDriver{
59-
Instance: inst,
60-
VSockPort: 0,
61-
VirtioPort: virtioPort,
59+
Instance: inst,
60+
VSockPort: 0,
61+
VirtioPort: virtioPort,
62+
SSHLocalPort: sshLocalPort,
6263
}
6364
}
6465

@@ -503,3 +504,32 @@ func (a *qArgTemplateApplier) applyTemplate(qArg string) (string, error) {
503504
}
504505
return b.String(), nil
505506
}
507+
508+
func (l *LimaQemuDriver) Name() string {
509+
return "qemu"
510+
}
511+
512+
func (l *LimaQemuDriver) Initialize(_ context.Context) error {
513+
return nil
514+
}
515+
516+
func (l *LimaQemuDriver) CanRunGUI() bool {
517+
return false
518+
}
519+
520+
func (l *LimaQemuDriver) RunGUI() error {
521+
return nil
522+
}
523+
524+
func (l *LimaQemuDriver) Register(_ context.Context) error {
525+
return nil
526+
}
527+
528+
func (l *LimaQemuDriver) Unregister(_ context.Context) error {
529+
return nil
530+
}
531+
532+
func (l *LimaQemuDriver) ForwardGuestAgent() bool {
533+
// if driver is not providing, use host agent
534+
return l.VSockPort == 0 && l.VirtioPort == ""
535+
}

pkg/vz/vz_driver_darwin.go

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,12 @@ type LimaVzDriver struct {
7777
machine *virtualMachineWrapper
7878
}
7979

80-
func New(inst *store.Instance) *LimaVzDriver {
80+
func New(inst *store.Instance, sshLocalPort int) *LimaVzDriver {
8181
return &LimaVzDriver{
82-
Instance: inst,
83-
VSockPort: 2222,
84-
VirtioPort: "",
82+
Instance: inst,
83+
VSockPort: 2222,
84+
VirtioPort: "",
85+
SSHLocalPort: sshLocalPort,
8586
}
8687
}
8788

@@ -248,3 +249,44 @@ func (l *LimaVzDriver) GuestAgentConn(_ context.Context) (net.Conn, error) {
248249
}
249250
return nil, errors.New("unable to connect to guest agent via vsock port 2222")
250251
}
252+
253+
func (l *LimaVzDriver) Name() string {
254+
return "vz"
255+
}
256+
257+
func (l *LimaVzDriver) Register(_ context.Context) error {
258+
return nil
259+
}
260+
261+
func (l *LimaVzDriver) Unregister(_ context.Context) error {
262+
return nil
263+
}
264+
265+
func (l *LimaVzDriver) ChangeDisplayPassword(_ context.Context, _ string) error {
266+
return nil
267+
}
268+
269+
func (l *LimaVzDriver) GetDisplayConnection(_ context.Context) (string, error) {
270+
return "", nil
271+
}
272+
273+
func (l *LimaVzDriver) CreateSnapshot(_ context.Context, _ string) error {
274+
return errors.New("unimplemented")
275+
}
276+
277+
func (l *LimaVzDriver) ApplySnapshot(_ context.Context, _ string) error {
278+
return errors.New("unimplemented")
279+
}
280+
281+
func (l *LimaVzDriver) DeleteSnapshot(_ context.Context, _ string) error {
282+
return errors.New("unimplemented")
283+
}
284+
285+
func (l *LimaVzDriver) ListSnapshots(_ context.Context) (string, error) {
286+
return "", errors.New("unimplemented")
287+
}
288+
289+
func (l *LimaVzDriver) ForwardGuestAgent() bool {
290+
// If driver is not providing, use host agent
291+
return l.VSockPort == 0 && l.VirtioPort == ""
292+
}

pkg/wsl2/wsl_driver_windows.go

Lines changed: 50 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,17 @@ type LimaWslDriver struct {
5353
VirtioPort string
5454
}
5555

56-
func New(inst *store.Instance) *LimaWslDriver {
56+
func New(inst *store.Instance, sshLocalPort int) *LimaWslDriver {
5757
port, err := freeport.VSock()
5858
if err != nil {
5959
logrus.WithError(err).Error("failed to get free VSock port")
6060
}
6161

6262
return &LimaWslDriver{
63-
Instance: inst,
64-
VSockPort: port,
65-
VirtioPort: "",
63+
Instance: inst,
64+
VSockPort: port,
65+
VirtioPort: "",
66+
SSHLocalPort: sshLocalPort,
6667
}
6768
}
6869

@@ -205,3 +206,48 @@ func (l *LimaWslDriver) GuestAgentConn(ctx context.Context) (net.Conn, error) {
205206
}
206207
return winio.Dial(ctx, sockAddr)
207208
}
209+
210+
func (l *LimaWslDriver) Name() string {
211+
return "wsl2"
212+
}
213+
214+
func (l *LimaWslDriver) Initialize(_ context.Context) error {
215+
return nil
216+
}
217+
218+
func (l *LimaWslDriver) CreateDisk(_ context.Context) error {
219+
return nil
220+
}
221+
222+
func (l *LimaWslDriver) Register(_ context.Context) error {
223+
return nil
224+
}
225+
226+
func (l *LimaWslDriver) ChangeDisplayPassword(_ context.Context, _ string) error {
227+
return nil
228+
}
229+
230+
func (l *LimaWslDriver) GetDisplayConnection(_ context.Context) (string, error) {
231+
return "", nil
232+
}
233+
234+
func (l *LimaWslDriver) CreateSnapshot(_ context.Context, _ string) error {
235+
return fmt.Errorf("unimplemented")
236+
}
237+
238+
func (l *LimaWslDriver) ApplySnapshot(_ context.Context, _ string) error {
239+
return fmt.Errorf("unimplemented")
240+
}
241+
242+
func (l *LimaWslDriver) DeleteSnapshot(_ context.Context, _ string) error {
243+
return fmt.Errorf("unimplemented")
244+
}
245+
246+
func (l *LimaWslDriver) ListSnapshots(_ context.Context) (string, error) {
247+
return "", fmt.Errorf("unimplemented")
248+
}
249+
250+
func (l *LimaWslDriver) ForwardGuestAgent() bool {
251+
// If driver is not providing, use host agent
252+
return l.VSockPort == 0 && l.VirtioPort == ""
253+
}

0 commit comments

Comments
 (0)