Skip to content

Commit c01a36d

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

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

pkg/networks/usernet/client.go

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

1717
gvproxyclient "github.com/containers/gvisor-tap-vsock/pkg/client"
1818
"github.com/containers/gvisor-tap-vsock/pkg/types"
19-
20-
"github.com/lima-vm/lima/pkg/driver"
2119
"github.com/lima-vm/lima/pkg/httpclientutil"
2220
"github.com/lima-vm/lima/pkg/limayaml"
2321
"github.com/lima-vm/lima/pkg/networks/usernet/dnshosts"
22+
"github.com/lima-vm/lima/pkg/store"
2423
)
2524

2625
type Client struct {
@@ -32,18 +31,18 @@ type Client struct {
3231
subnet net.IP
3332
}
3433

35-
func (c *Client) ConfigureDriver(ctx context.Context, driver *driver.BaseDriver) error {
36-
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)
3736
ipAddress, err := c.ResolveIPAddress(ctx, macAddress)
3837
if err != nil {
3938
return err
4039
}
41-
err = c.ResolveAndForwardSSH(ipAddress, driver.SSHLocalPort)
40+
err = c.ResolveAndForwardSSH(ipAddress, sshLocalPort)
4241
if err != nil {
4342
return err
4443
}
45-
hosts := driver.Instance.Config.HostResolver.Hosts
46-
hosts[fmt.Sprintf("%s.internal", driver.Instance.Hostname)] = ipAddress
44+
hosts := inst.Config.HostResolver.Hosts
45+
hosts[fmt.Sprintf("%s.internal", inst.Hostname)] = ipAddress
4746
err = c.AddDNSHosts(hosts)
4847
return err
4948
}

pkg/qemu/qemu_driver.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import (
2626
"github.com/digitalocean/go-qemu/qmp/raw"
2727
"github.com/sirupsen/logrus"
2828

29-
"github.com/lima-vm/lima/pkg/driver"
3029
"github.com/lima-vm/lima/pkg/executil"
3130
"github.com/lima-vm/lima/pkg/limayaml"
3231
"github.com/lima-vm/lima/pkg/networks/usernet"
@@ -37,23 +36,29 @@ import (
3736
)
3837

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

4447
vhostCmds []*exec.Cmd
4548
}
4649

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

@@ -212,7 +217,7 @@ func (l *LimaQemuDriver) Start(ctx context.Context) (chan error, error) {
212217
go func() {
213218
if usernetIndex := limayaml.FirstUsernetIndex(l.Instance.Config); usernetIndex != -1 {
214219
client := usernet.NewClientByName(l.Instance.Config.Networks[usernetIndex].Lima)
215-
err := client.ConfigureDriver(ctx, l.BaseDriver)
220+
err := client.ConfigureDriver(ctx, l.Instance, l.SSHLocalPort)
216221
if err != nil {
217222
l.qWaitCh <- err
218223
}
@@ -260,11 +265,11 @@ func (l *LimaQemuDriver) checkBinarySignature() error {
260265
}
261266
// The codesign --xml option is only available on macOS Monterey and later
262267
if !macOSProductVersion.LessThan(*semver.New("12.0.0")) {
263-
qExe, _, err := Exe(l.BaseDriver.Instance.Arch)
268+
qExe, _, err := Exe(l.Instance.Arch)
264269
if err != nil {
265-
return fmt.Errorf("failed to find the QEMU binary for the architecture %q: %w", l.BaseDriver.Instance.Arch, err)
270+
return fmt.Errorf("failed to find the QEMU binary for the architecture %q: %w", l.Instance.Arch, err)
266271
}
267-
if accel := Accel(l.BaseDriver.Instance.Arch); accel == "hvf" {
272+
if accel := Accel(l.Instance.Arch); accel == "hvf" {
268273
entitlementutil.AskToSignIfNotSignedProperly(qExe)
269274
}
270275
}

0 commit comments

Comments
 (0)