Skip to content

Commit 0f4bf50

Browse files
committed
refactor(BaseDriver): remove driver.BaseDriver from Lima level
Signed-off-by: Ansuman Sahoo <[email protected]>
1 parent ff8a943 commit 0f4bf50

File tree

7 files changed

+12
-122
lines changed

7 files changed

+12
-122
lines changed

pkg/driver/driver.go

Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,10 @@ package driver
55

66
import (
77
"context"
8-
"errors"
98
"net"
10-
11-
"github.com/lima-vm/lima/pkg/store"
129
)
1310

1411
// Driver interface is used by hostagent for managing vm.
15-
//
16-
// This interface is extended by BaseDriver which provides default implementation.
17-
// All other driver definition must extend BaseDriver.
1812
type Driver interface {
1913
// Validate returns error if the current driver isn't support for given config
2014
Validate() error
@@ -75,87 +69,3 @@ type Driver interface {
7569
// Returns the driver name.
7670
Name() string
7771
}
78-
79-
type BaseDriver struct {
80-
Instance *store.Instance
81-
82-
SSHLocalPort int
83-
VSockPort int
84-
VirtioPort string
85-
}
86-
87-
var _ Driver = (*BaseDriver)(nil)
88-
89-
func (d *BaseDriver) Validate() error {
90-
return nil
91-
}
92-
93-
func (d *BaseDriver) Initialize(_ context.Context) error {
94-
return nil
95-
}
96-
97-
func (d *BaseDriver) CreateDisk(_ context.Context) error {
98-
return nil
99-
}
100-
101-
func (d *BaseDriver) Start(_ context.Context) (chan error, error) {
102-
return nil, nil
103-
}
104-
105-
func (d *BaseDriver) CanRunGUI() bool {
106-
return false
107-
}
108-
109-
func (d *BaseDriver) RunGUI() error {
110-
return nil
111-
}
112-
113-
func (d *BaseDriver) Stop(_ context.Context) error {
114-
return nil
115-
}
116-
117-
func (d *BaseDriver) Register(_ context.Context) error {
118-
return nil
119-
}
120-
121-
func (d *BaseDriver) Unregister(_ context.Context) error {
122-
return nil
123-
}
124-
125-
func (d *BaseDriver) ChangeDisplayPassword(_ context.Context, _ string) error {
126-
return nil
127-
}
128-
129-
func (d *BaseDriver) GetDisplayConnection(_ context.Context) (string, error) {
130-
return "", nil
131-
}
132-
133-
func (d *BaseDriver) CreateSnapshot(_ context.Context, _ string) error {
134-
return errors.New("unimplemented")
135-
}
136-
137-
func (d *BaseDriver) ApplySnapshot(_ context.Context, _ string) error {
138-
return errors.New("unimplemented")
139-
}
140-
141-
func (d *BaseDriver) DeleteSnapshot(_ context.Context, _ string) error {
142-
return errors.New("unimplemented")
143-
}
144-
145-
func (d *BaseDriver) ListSnapshots(_ context.Context) (string, error) {
146-
return "", errors.New("unimplemented")
147-
}
148-
149-
func (d *BaseDriver) ForwardGuestAgent() bool {
150-
// if driver is not providing, use host agent
151-
return d.VSockPort == 0 && d.VirtioPort == ""
152-
}
153-
154-
func (d *BaseDriver) GuestAgentConn(_ context.Context) (net.Conn, error) {
155-
// use the unix socket forwarded by host agent
156-
return nil, nil
157-
}
158-
159-
func (d *BaseDriver) Name() string {
160-
return ""
161-
}

pkg/driverutil/instance.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77
"github.com/lima-vm/lima/pkg/driver"
88
"github.com/lima-vm/lima/pkg/limayaml"
99
"github.com/lima-vm/lima/pkg/qemu"
10+
"github.com/lima-vm/lima/pkg/store"
1011
"github.com/lima-vm/lima/pkg/vz"
1112
"github.com/lima-vm/lima/pkg/wsl2"
1213
)
1314

14-
func CreateTargetDriverInstance(base *driver.BaseDriver) driver.Driver {
15+
func CreateTargetDriverInstance(inst *store.Instance, SSHLocalPort int) driver.Driver {
1516
limaDriver := base.Instance.Config.VMType
1617
if *limaDriver == limayaml.VZ {
1718
return vz.New(base)

pkg/hostagent/hostagent.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,9 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
131131
}
132132
}
133133

134-
baseDriver := driver.BaseDriver{
135-
Instance: inst,
136-
SSHLocalPort: sshLocalPort,
137-
}
138-
limaDriver := driverutil.CreateTargetDriverInstance(&baseDriver)
139-
vSockPort := baseDriver.VSockPort
140-
virtioPort := baseDriver.VirtioPort
134+
limaDriver := driverutil.CreateTargetDriverInstance(inst, sshLocalPort)
135+
var vSockPort int
136+
var virtioPort string
141137

142138
if err := cidata.GenerateCloudConfig(inst.Dir, instName, inst.Config); err != nil {
143139
return nil, err

pkg/instance/create.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"path/filepath"
1212

1313
"github.com/lima-vm/lima/pkg/cidata"
14-
"github.com/lima-vm/lima/pkg/driver"
1514
"github.com/lima-vm/lima/pkg/driverutil"
1615
"github.com/lima-vm/lima/pkg/limayaml"
1716
"github.com/lima-vm/lima/pkg/osutil"
@@ -76,9 +75,7 @@ func Create(ctx context.Context, instName string, instConfig []byte, saveBrokenY
7675
return nil, err
7776
}
7877

79-
limaDriver := driverutil.CreateTargetDriverInstance(&driver.BaseDriver{
80-
Instance: inst,
81-
})
78+
limaDriver := driverutil.CreateTargetDriverInstance(inst, 0)
8279

8380
if err := limaDriver.Register(ctx); err != nil {
8481
return nil, err

pkg/instance/delete.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"fmt"
1010
"os"
1111

12-
"github.com/lima-vm/lima/pkg/driver"
1312
"github.com/lima-vm/lima/pkg/driverutil"
1413
"github.com/lima-vm/lima/pkg/store"
1514
)
@@ -37,9 +36,7 @@ func Delete(ctx context.Context, inst *store.Instance, force bool) error {
3736
}
3837

3938
func unregister(ctx context.Context, inst *store.Instance) error {
40-
limaDriver := driverutil.CreateTargetDriverInstance(&driver.BaseDriver{
41-
Instance: inst,
42-
})
39+
limaDriver := driverutil.CreateTargetDriverInstance(inst, 0)
4340

4441
return limaDriver.Unregister(ctx)
4542
}

pkg/instance/start.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,7 @@ func Prepare(ctx context.Context, inst *store.Instance) (*Prepared, error) {
9191
return nil, err
9292
}
9393
}
94-
limaDriver := driverutil.CreateTargetDriverInstance(&driver.BaseDriver{
95-
Instance: inst,
96-
})
94+
limaDriver := driverutil.CreateTargetDriverInstance(inst, 0)
9795

9896
if err := limaDriver.Validate(); err != nil {
9997
return nil, err

pkg/snapshot/snapshot.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,26 @@ package snapshot
66
import (
77
"context"
88

9-
"github.com/lima-vm/lima/pkg/driver"
109
"github.com/lima-vm/lima/pkg/driverutil"
1110
"github.com/lima-vm/lima/pkg/store"
1211
)
1312

1413
func Del(ctx context.Context, inst *store.Instance, tag string) error {
15-
limaDriver := driverutil.CreateTargetDriverInstance(&driver.BaseDriver{
16-
Instance: inst,
17-
})
14+
limaDriver := driverutil.CreateTargetDriverInstance(inst, 0)
1815
return limaDriver.DeleteSnapshot(ctx, tag)
1916
}
2017

2118
func Save(ctx context.Context, inst *store.Instance, tag string) error {
22-
limaDriver := driverutil.CreateTargetDriverInstance(&driver.BaseDriver{
23-
Instance: inst,
24-
})
19+
limaDriver := driverutil.CreateTargetDriverInstance(inst, 0)
2520
return limaDriver.CreateSnapshot(ctx, tag)
2621
}
2722

2823
func Load(ctx context.Context, inst *store.Instance, tag string) error {
29-
limaDriver := driverutil.CreateTargetDriverInstance(&driver.BaseDriver{
30-
Instance: inst,
31-
})
24+
limaDriver := driverutil.CreateTargetDriverInstance(inst, 0)
3225
return limaDriver.ApplySnapshot(ctx, tag)
3326
}
3427

3528
func List(ctx context.Context, inst *store.Instance) (string, error) {
36-
limaDriver := driverutil.CreateTargetDriverInstance(&driver.BaseDriver{
37-
Instance: inst,
38-
})
29+
limaDriver := driverutil.CreateTargetDriverInstance(inst, 0)
3930
return limaDriver.ListSnapshots(ctx)
4031
}

0 commit comments

Comments
 (0)