Skip to content

Commit 7fbd83a

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

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

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

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

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

0 commit comments

Comments
 (0)