Skip to content

Commit 8997faa

Browse files
committed
driver(internal): add register files and make drivers compatible for internal plugins
Signed-off-by: Ansuman Sahoo <[email protected]>
1 parent 274d385 commit 8997faa

File tree

8 files changed

+323
-15
lines changed

8 files changed

+323
-15
lines changed

pkg/qemu/qemu_driver.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"github.com/coreos/go-semver/semver"
2525
"github.com/digitalocean/go-qemu/qmp"
2626
"github.com/digitalocean/go-qemu/qmp/raw"
27+
"github.com/lima-vm/lima/pkg/driver"
2728
"github.com/lima-vm/lima/pkg/executil"
2829
"github.com/lima-vm/lima/pkg/limayaml"
2930
"github.com/lima-vm/lima/pkg/networks/usernet"
@@ -46,7 +47,9 @@ type LimaQemuDriver struct {
4647
vhostCmds []*exec.Cmd
4748
}
4849

49-
func New(inst *store.Instance, sshLocalPort int) *LimaQemuDriver {
50+
var _ driver.Driver = (*LimaQemuDriver)(nil)
51+
52+
func New() *LimaQemuDriver {
5053
// virtserialport doesn't seem to work reliably: https://github.com/lima-vm/lima/issues/2064
5154
// but on Windows default Unix socket forwarding is not available
5255
var virtioPort string
@@ -55,13 +58,24 @@ func New(inst *store.Instance, sshLocalPort int) *LimaQemuDriver {
5558
virtioPort = ""
5659
}
5760
return &LimaQemuDriver{
58-
Instance: inst,
59-
VSockPort: 0,
60-
VirtioPort: virtioPort,
61-
SSHLocalPort: sshLocalPort,
61+
VSockPort: 0,
62+
VirtioPort: virtioPort,
6263
}
6364
}
6465

66+
func (l *LimaQemuDriver) SetConfig(inst *store.Instance, sshLocalPort int) {
67+
l.Instance = inst
68+
l.SSHLocalPort = sshLocalPort
69+
}
70+
71+
func (l *LimaQemuDriver) GetVirtioPort() string {
72+
return l.VirtioPort
73+
}
74+
75+
func (l *LimaQemuDriver) GetVSockPort() int {
76+
return l.VSockPort
77+
}
78+
6579
func (l *LimaQemuDriver) Validate() error {
6680
if runtime.GOOS == "darwin" {
6781
if err := l.checkBinarySignature(); err != nil {

pkg/qemu/register.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-FileCopyrightText: Copyright The Lima Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package qemu
5+
6+
import "github.com/lima-vm/lima/pkg/registry"
7+
8+
func init() {
9+
registry.Register(New())
10+
}

pkg/vz/register.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-FileCopyrightText: Copyright The Lima Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package vz
5+
6+
import "github.com/lima-vm/lima/pkg/registry"
7+
8+
func init() {
9+
registry.Register(New())
10+
}

pkg/vz/vz_driver_darwin.go

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
"github.com/sirupsen/logrus"
2121

22+
"github.com/lima-vm/lima/pkg/driver"
2223
"github.com/lima-vm/lima/pkg/limayaml"
2324
"github.com/lima-vm/lima/pkg/osutil"
2425
"github.com/lima-vm/lima/pkg/reflectutil"
@@ -78,15 +79,28 @@ type LimaVzDriver struct {
7879
machine *virtualMachineWrapper
7980
}
8081

81-
func New(inst *store.Instance, sshLocalPort int) *LimaVzDriver {
82+
var _ driver.Driver = (*LimaVzDriver)(nil)
83+
84+
func New() *LimaVzDriver {
8285
return &LimaVzDriver{
83-
Instance: inst,
84-
VSockPort: 2222,
85-
VirtioPort: "",
86-
SSHLocalPort: sshLocalPort,
86+
VSockPort: 2222,
87+
VirtioPort: "",
8788
}
8889
}
8990

91+
func (l *LimaVzDriver) SetConfig(inst *store.Instance, sshLocalPort int) {
92+
l.Instance = inst
93+
l.SSHLocalPort = sshLocalPort
94+
}
95+
96+
func (l *LimaVzDriver) GetVirtioPort() string {
97+
return l.VirtioPort
98+
}
99+
100+
func (l *LimaVzDriver) GetVSockPort() int {
101+
return l.VSockPort
102+
}
103+
90104
func (l *LimaVzDriver) Validate() error {
91105
macOSProductVersion, err := osutil.ProductVersion()
92106
if err != nil {

pkg/vz/vz_driver_others.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
//go:build !darwin || no_vz
2+
3+
// SPDX-FileCopyrightText: Copyright The Lima Authors
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
package vz
7+
8+
import (
9+
"context"
10+
"errors"
11+
"net"
12+
13+
"github.com/lima-vm/lima/pkg/driver"
14+
"github.com/lima-vm/lima/pkg/store"
15+
)
16+
17+
var ErrUnsupported = errors.New("vm driver 'vz' needs macOS 13 or later (Hint: try recompiling Lima if you are seeing this error on macOS 13)")
18+
19+
const Enabled = false
20+
21+
type LimaVzDriver struct {
22+
Instance *store.Instance
23+
24+
SSHLocalPort int
25+
VSockPort int
26+
VirtioPort string
27+
}
28+
29+
var _ driver.Driver = (*LimaVzDriver)(nil)
30+
31+
func New() *LimaVzDriver {
32+
return &LimaVzDriver{}
33+
}
34+
35+
func (l *LimaVzDriver) GetVirtioPort() string {
36+
return l.VirtioPort
37+
}
38+
39+
func (l *LimaVzDriver) GetVSockPort() int {
40+
return l.VSockPort
41+
}
42+
43+
func (l *LimaVzDriver) Validate() error {
44+
return ErrUnsupported
45+
}
46+
47+
func (l *LimaVzDriver) Initialize(_ context.Context) error {
48+
return ErrUnsupported
49+
}
50+
51+
func (l *LimaVzDriver) CreateDisk(_ context.Context) error {
52+
return ErrUnsupported
53+
}
54+
55+
func (l *LimaVzDriver) Start(_ context.Context) (chan error, error) {
56+
return nil, ErrUnsupported
57+
}
58+
59+
func (l *LimaVzDriver) Stop(_ context.Context) error {
60+
return ErrUnsupported
61+
}
62+
63+
func (l *LimaVzDriver) CanRunGUI() bool {
64+
return false
65+
}
66+
67+
func (l *LimaVzDriver) RunGUI() error {
68+
return ErrUnsupported
69+
}
70+
71+
func (l *LimaVzDriver) ChangeDisplayPassword(_ context.Context, _ string) error {
72+
return ErrUnsupported
73+
}
74+
75+
func (l *LimaVzDriver) GetDisplayConnection(_ context.Context) (string, error) {
76+
return "", ErrUnsupported
77+
}
78+
79+
func (l *LimaVzDriver) CreateSnapshot(_ context.Context, _ string) error {
80+
return ErrUnsupported
81+
}
82+
83+
func (l *LimaVzDriver) ApplySnapshot(_ context.Context, _ string) error {
84+
return ErrUnsupported
85+
}
86+
87+
func (l *LimaVzDriver) DeleteSnapshot(_ context.Context, _ string) error {
88+
return ErrUnsupported
89+
}
90+
91+
func (l *LimaVzDriver) ListSnapshots(_ context.Context) (string, error) {
92+
return "", ErrUnsupported
93+
}
94+
95+
func (l *LimaVzDriver) Register(_ context.Context) error {
96+
return ErrUnsupported
97+
}
98+
99+
func (l *LimaVzDriver) Unregister(_ context.Context) error {
100+
return ErrUnsupported
101+
}
102+
103+
func (l *LimaVzDriver) ForwardGuestAgent() bool {
104+
return false
105+
}
106+
107+
func (l *LimaVzDriver) GuestAgentConn(_ context.Context) (net.Conn, error) {
108+
return nil, ErrUnsupported
109+
}
110+
111+
func (l *LimaVzDriver) Name() string {
112+
return "vz"
113+
}
114+
115+
func (l *LimaVzDriver) SetConfig(inst *store.Instance, sshLocalPort int) {
116+
l.Instance = inst
117+
l.SSHLocalPort = sshLocalPort
118+
}

pkg/wsl2/register.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-FileCopyrightText: Copyright The Lima Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package wsl2
5+
6+
import "github.com/lima-vm/lima/pkg/registry"
7+
8+
func init() {
9+
registry.Register(New())
10+
}

pkg/wsl2/wsl_driver_others.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
//go:build !windows || no_wsl
2+
3+
// SPDX-FileCopyrightText: Copyright The Lima Authors
4+
// SPDX-License-Identifier: Apache-2.0
5+
6+
package wsl2
7+
8+
import (
9+
"context"
10+
"errors"
11+
"net"
12+
13+
"github.com/lima-vm/lima/pkg/driver"
14+
"github.com/lima-vm/lima/pkg/store"
15+
)
16+
17+
var ErrUnsupported = errors.New("vm driver 'wsl2' requires Windows 10 build 19041 or later (Hint: try recompiling Lima if you are seeing this error on Windows 10+)")
18+
19+
const Enabled = false
20+
21+
type LimaWslDriver struct {
22+
Instance *store.Instance
23+
24+
SSHLocalPort int
25+
VSockPort int
26+
VirtioPort string
27+
}
28+
29+
var _ driver.Driver = (*LimaWslDriver)(nil)
30+
31+
func New() *LimaWslDriver {
32+
return &LimaWslDriver{}
33+
}
34+
35+
func (l *LimaWslDriver) GetVirtioPort() string {
36+
return l.VirtioPort
37+
}
38+
39+
func (l *LimaWslDriver) GetVSockPort() int {
40+
return l.VSockPort
41+
}
42+
43+
func (l *LimaWslDriver) Validate() error {
44+
return ErrUnsupported
45+
}
46+
47+
func (l *LimaWslDriver) Initialize(_ context.Context) error {
48+
return ErrUnsupported
49+
}
50+
51+
func (l *LimaWslDriver) CreateDisk(_ context.Context) error {
52+
return ErrUnsupported
53+
}
54+
55+
func (l *LimaWslDriver) Start(_ context.Context) (chan error, error) {
56+
return nil, ErrUnsupported
57+
}
58+
59+
func (l *LimaWslDriver) Stop(_ context.Context) error {
60+
return ErrUnsupported
61+
}
62+
63+
func (l *LimaWslDriver) CanRunGUI() bool {
64+
return false
65+
}
66+
67+
func (l *LimaWslDriver) RunGUI() error {
68+
return ErrUnsupported
69+
}
70+
71+
func (l *LimaWslDriver) ChangeDisplayPassword(_ context.Context, _ string) error {
72+
return ErrUnsupported
73+
}
74+
75+
func (l *LimaWslDriver) GetDisplayConnection(_ context.Context) (string, error) {
76+
return "", ErrUnsupported
77+
}
78+
79+
func (l *LimaWslDriver) CreateSnapshot(_ context.Context, _ string) error {
80+
return ErrUnsupported
81+
}
82+
83+
func (l *LimaWslDriver) ApplySnapshot(_ context.Context, _ string) error {
84+
return ErrUnsupported
85+
}
86+
87+
func (l *LimaWslDriver) DeleteSnapshot(_ context.Context, _ string) error {
88+
return ErrUnsupported
89+
}
90+
91+
func (l *LimaWslDriver) ListSnapshots(_ context.Context) (string, error) {
92+
return "", ErrUnsupported
93+
}
94+
95+
func (l *LimaWslDriver) Register(_ context.Context) error {
96+
return ErrUnsupported
97+
}
98+
99+
func (l *LimaWslDriver) Unregister(_ context.Context) error {
100+
return ErrUnsupported
101+
}
102+
103+
func (l *LimaWslDriver) ForwardGuestAgent() bool {
104+
return false
105+
}
106+
107+
func (l *LimaWslDriver) GuestAgentConn(_ context.Context) (net.Conn, error) {
108+
return nil, ErrUnsupported
109+
}
110+
111+
func (l *LimaWslDriver) Name() string {
112+
return "vz"
113+
}
114+
115+
func (l *LimaWslDriver) SetConfig(inst *store.Instance, sshLocalPort int) {
116+
l.Instance = inst
117+
l.SSHLocalPort = sshLocalPort
118+
}

0 commit comments

Comments
 (0)