Skip to content

Commit 0199d54

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

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
@@ -46,7 +46,7 @@ type LimaQemuDriver struct {
4646
vhostCmds []*exec.Cmd
4747
}
4848

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

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

pkg/vz/vz_driver_darwin.go

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

81-
func New(inst *store.Instance) *LimaVzDriver {
81+
func New(inst *store.Instance, sshLocalPort int) *LimaVzDriver {
8282
return &LimaVzDriver{
83-
Instance: inst,
84-
VSockPort: 2222,
85-
VirtioPort: "",
83+
Instance: inst,
84+
VSockPort: 2222,
85+
VirtioPort: "",
86+
SSHLocalPort: sshLocalPort,
8687
}
8788
}
8889

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

pkg/wsl2/wsl_driver_windows.go

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

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

6161
return &LimaWslDriver{
62-
Instance: inst,
63-
VSockPort: port,
64-
VirtioPort: "",
62+
Instance: inst,
63+
VSockPort: port,
64+
VirtioPort: "",
65+
SSHLocalPort: sshLocalPort,
6566
}
6667
}
6768

@@ -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)