Skip to content

Commit ef9c43c

Browse files
committed
refactor(BaseDriver): remove driver.BaseDriver from driver(qemu) level
Signed-off-by: Ansuman Sahoo <[email protected]>
1 parent 30cc8bc commit ef9c43c

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

pkg/networks/usernet/client.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ import (
1616

1717
gvproxyclient "github.com/containers/gvisor-tap-vsock/pkg/client"
1818
"github.com/containers/gvisor-tap-vsock/pkg/types"
19-
"github.com/lima-vm/lima/pkg/driver"
2019
"github.com/lima-vm/lima/pkg/httpclientutil"
2120
"github.com/lima-vm/lima/pkg/limayaml"
2221
"github.com/lima-vm/lima/pkg/networks/usernet/dnshosts"
22+
"github.com/lima-vm/lima/pkg/store"
2323
)
2424

2525
type Client struct {
@@ -31,18 +31,18 @@ type Client struct {
3131
subnet net.IP
3232
}
3333

34-
func (c *Client) ConfigureDriver(ctx context.Context, driver *driver.BaseDriver) error {
35-
macAddress := limayaml.MACAddress(driver.Instance.Dir)
34+
func (c *Client) ConfigureDriver(ctx context.Context, inst *store.Instance, sshLocalPort int) error {
35+
macAddress := limayaml.MACAddress(inst.Dir)
3636
ipAddress, err := c.ResolveIPAddress(ctx, macAddress)
3737
if err != nil {
3838
return err
3939
}
40-
err = c.ResolveAndForwardSSH(ipAddress, driver.SSHLocalPort)
40+
err = c.ResolveAndForwardSSH(ipAddress, sshLocalPort)
4141
if err != nil {
4242
return err
4343
}
44-
hosts := driver.Instance.Config.HostResolver.Hosts
45-
hosts[fmt.Sprintf("%s.internal", driver.Instance.Hostname)] = ipAddress
44+
hosts := inst.Config.HostResolver.Hosts
45+
hosts[fmt.Sprintf("%s.internal", inst.Hostname)] = ipAddress
4646
err = c.AddDNSHosts(hosts)
4747
return err
4848
}

pkg/qemu/qemu_driver.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ 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"
2827
"github.com/lima-vm/lima/pkg/executil"
2928
"github.com/lima-vm/lima/pkg/limayaml"
3029
"github.com/lima-vm/lima/pkg/networks/usernet"
@@ -36,23 +35,29 @@ import (
3635
)
3736

3837
type LimaQemuDriver struct {
39-
*driver.BaseDriver
38+
Instance *store.Instance
39+
SSHLocalPort int
40+
VSockPort int
41+
VirtioPort string
42+
4043
qCmd *exec.Cmd
4144
qWaitCh chan error
4245

4346
vhostCmds []*exec.Cmd
4447
}
4548

46-
func New(driver *driver.BaseDriver) *LimaQemuDriver {
47-
driver.VSockPort = 0
48-
driver.VirtioPort = filenames.VirtioPort
49+
func New(inst *store.Instance) *LimaQemuDriver {
4950
// virtserialport doesn't seem to work reliably: https://github.com/lima-vm/lima/issues/2064
5051
// but on Windows default Unix socket forwarding is not available
52+
var virtioPort string
53+
virtioPort = filenames.VirtioPort
5154
if runtime.GOOS != "windows" {
52-
driver.VirtioPort = ""
55+
virtioPort = ""
5356
}
5457
return &LimaQemuDriver{
55-
BaseDriver: driver,
58+
Instance: inst,
59+
VSockPort: 0,
60+
VirtioPort: virtioPort,
5661
}
5762
}
5863

@@ -211,7 +216,7 @@ func (l *LimaQemuDriver) Start(ctx context.Context) (chan error, error) {
211216
go func() {
212217
if usernetIndex := limayaml.FirstUsernetIndex(l.Instance.Config); usernetIndex != -1 {
213218
client := usernet.NewClientByName(l.Instance.Config.Networks[usernetIndex].Lima)
214-
err := client.ConfigureDriver(ctx, l.BaseDriver)
219+
err := client.ConfigureDriver(ctx, l.Instance, l.SSHLocalPort)
215220
if err != nil {
216221
l.qWaitCh <- err
217222
}
@@ -259,11 +264,11 @@ func (l *LimaQemuDriver) checkBinarySignature() error {
259264
}
260265
// The codesign --xml option is only available on macOS Monterey and later
261266
if !macOSProductVersion.LessThan(*semver.New("12.0.0")) {
262-
qExe, _, err := Exe(l.BaseDriver.Instance.Arch)
267+
qExe, _, err := Exe(l.Instance.Arch)
263268
if err != nil {
264-
return fmt.Errorf("failed to find the QEMU binary for the architecture %q: %w", l.BaseDriver.Instance.Arch, err)
269+
return fmt.Errorf("failed to find the QEMU binary for the architecture %q: %w", l.Instance.Arch, err)
265270
}
266-
if accel := Accel(l.BaseDriver.Instance.Arch); accel == "hvf" {
271+
if accel := Accel(l.Instance.Arch); accel == "hvf" {
267272
entitlementutil.AskToSignIfNotSignedProperly(qExe)
268273
}
269274
}

0 commit comments

Comments
 (0)