Skip to content

Commit 274d385

Browse files
committed
driver(internal): add blank imports and make changes to Lima for internal drivers
Signed-off-by: Ansuman Sahoo <[email protected]>
1 parent 97299fb commit 274d385

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

cmd/limactl/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"runtime"
1212
"strings"
1313

14+
_ "github.com/lima-vm/lima/pkg/builtins" // register built-in drivers
1415
"github.com/lima-vm/lima/pkg/debugutil"
1516
"github.com/lima-vm/lima/pkg/fsutil"
1617
"github.com/lima-vm/lima/pkg/osutil"

pkg/builtins/drivers.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 builtins
5+
6+
import (
7+
_ "github.com/lima-vm/lima/pkg/qemu"
8+
_ "github.com/lima-vm/lima/pkg/vz"
9+
_ "github.com/lima-vm/lima/pkg/wsl2"
10+
)

pkg/driver/driver.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type Plugin interface {
7777
Name() string
7878

7979
// NewDriver returns a new driver instance. Only to be used to embed internal drivers
80-
NewDriver(inst *store.Instance, sshLocalPort int) Driver
80+
SetConfig(inst *store.Instance, sshLocalPort int)
8181
}
8282

8383
// Driver interface is used by hostagent for managing vm.
@@ -88,4 +88,7 @@ type Driver interface {
8888
Registration
8989
GuestAgent
9090
Plugin
91+
92+
GetVSockPort() int
93+
GetVirtioPort() string
9194
}

pkg/driverutil/instance.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ func CreateTargetDriverInstance(inst *store.Instance, sshLocalPort int) (driver.
1919
return nil, fmt.Errorf("unknown or unsupported VM type: %s", *limaDriver)
2020
}
2121

22+
driver.SetConfig(inst, sshLocalPort)
23+
2224
if err := driver.Validate(); err != nil {
2325
return nil, fmt.Errorf("driver validation failed: %w", err)
2426
}
2527

26-
return driver.NewDriver(inst, sshLocalPort), nil
28+
return driver, nil
2729
}

pkg/hostagent/hostagent.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,8 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
136136
return nil, fmt.Errorf("failed to create driver instance: %w", err)
137137
}
138138

139-
var vSockPort int
140-
var virtioPort string
139+
vSockPort := limaDriver.GetVSockPort()
140+
virtioPort := limaDriver.GetVirtioPort()
141141

142142
if err := cidata.GenerateCloudConfig(inst.Dir, instName, inst.Config); err != nil {
143143
return nil, err

pkg/registry/registry.go

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"sync"
88

99
"github.com/lima-vm/lima/pkg/driver"
10-
"github.com/lima-vm/lima/pkg/store"
1110
)
1211

1312
type Registry struct {
@@ -21,18 +20,6 @@ func NewRegistry() *Registry {
2120
}
2221
}
2322

24-
func (r *Registry) Register(driver driver.Driver, inst *store.Instance, sshLocalPort int) {
25-
r.mu.Lock()
26-
defer r.mu.Unlock()
27-
28-
name := driver.Name()
29-
if _, exists := r.drivers[name]; exists {
30-
return
31-
}
32-
33-
r.drivers[name] = driver
34-
}
35-
3623
func (r *Registry) List() []string {
3724
r.mu.RLock()
3825
defer r.mu.RUnlock()
@@ -54,6 +41,10 @@ func (r *Registry) Get(name string) (driver.Driver, bool) {
5441

5542
var DefaultRegistry *Registry
5643

44+
func init() {
45+
DefaultRegistry = NewRegistry()
46+
}
47+
5748
func Register(driver driver.Driver) {
5849
if DefaultRegistry != nil {
5950
name := driver.Name()

0 commit comments

Comments
 (0)