Skip to content

Commit 1a6169b

Browse files
committed
Add ext driver for external VM machines
Signed-off-by: Anders F Björklund <[email protected]>
1 parent a2c3792 commit 1a6169b

File tree

7 files changed

+43
-2
lines changed

7 files changed

+43
-2
lines changed

pkg/driverutil/driverutil.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package driverutil
22

33
import (
4+
"github.com/lima-vm/lima/pkg/ext"
45
"github.com/lima-vm/lima/pkg/limayaml"
56
"github.com/lima-vm/lima/pkg/vz"
67
"github.com/lima-vm/lima/pkg/wsl2"
@@ -15,5 +16,8 @@ func Drivers() []string {
1516
if wsl2.Enabled {
1617
drivers = append(drivers, limayaml.WSL2)
1718
}
19+
if ext.Enabled {
20+
drivers = append(drivers, limayaml.EXT)
21+
}
1822
return drivers
1923
}

pkg/driverutil/instance.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package driverutil
22

33
import (
44
"github.com/lima-vm/lima/pkg/driver"
5+
"github.com/lima-vm/lima/pkg/ext"
56
"github.com/lima-vm/lima/pkg/limayaml"
67
"github.com/lima-vm/lima/pkg/qemu"
78
"github.com/lima-vm/lima/pkg/vz"
@@ -16,5 +17,8 @@ func CreateTargetDriverInstance(base *driver.BaseDriver) driver.Driver {
1617
if *limaDriver == limayaml.WSL2 {
1718
return wsl2.New(base)
1819
}
20+
if *limaDriver == limayaml.EXT {
21+
return ext.New(base)
22+
}
1923
return qemu.New(base)
2024
}

pkg/ext/ext_driver.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package ext
2+
3+
import (
4+
"github.com/lima-vm/lima/pkg/driver"
5+
)
6+
7+
const Enabled = true
8+
9+
type LimaExtDriver struct {
10+
*driver.BaseDriver
11+
}
12+
13+
func New(driver *driver.BaseDriver) *LimaExtDriver {
14+
return &LimaExtDriver{
15+
BaseDriver: driver,
16+
}
17+
}

pkg/limayaml/defaults.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -920,6 +920,8 @@ func NewVMType(driver string) VMType {
920920
return QEMU
921921
case "wsl2":
922922
return WSL2
923+
case "ext":
924+
return EXT
923925
default:
924926
logrus.Warnf("Unknown driver: %s", driver)
925927
return driver

pkg/limayaml/limayaml.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ const (
6666
QEMU VMType = "qemu"
6767
VZ VMType = "vz"
6868
WSL2 VMType = "wsl2"
69+
EXT VMType = "ext"
6970
)
7071

7172
type Rosetta struct {

pkg/limayaml/validate.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ func Validate(y LimaYAML, warn bool) error {
6161
if !IsNativeArch(*y.Arch) {
6262
return fmt.Errorf("field `arch` must be %q for VZ; got %q", NewArch(runtime.GOARCH), *y.Arch)
6363
}
64+
case EXT:
65+
// NOP
6466
default:
65-
return fmt.Errorf("field `vmType` must be %q, %q, %q; got %q", QEMU, VZ, WSL2, *y.VMType)
67+
return fmt.Errorf("field `vmType` must be %q, %q, %q, %q; got %q", QEMU, VZ, WSL2, EXT, *y.VMType)
6668
}
6769

68-
if len(y.Images) == 0 {
70+
if len(y.Images) == 0 && *y.VMType != EXT {
6971
return errors.New("field `images` must be set")
7072
}
7173
for i, f := range y.Images {
@@ -153,6 +155,9 @@ func Validate(y LimaYAML, warn bool) error {
153155
}
154156
}
155157

158+
if *y.SSH.Address == "127.0.0.1" && *y.VMType == EXT {
159+
return errors.New("field `ssh.address` must be set, for ext")
160+
}
156161
if y.SSH.Address != nil {
157162
if err := validateHost("ssh.address", *y.SSH.Address); err != nil {
158163
return err

pkg/store/instance.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ func inspectStatusWithPIDFiles(instDir string, inst *Instance, y *limayaml.LimaY
190190
inst.Status = StatusBroken
191191
inst.Errors = append(inst.Errors, err)
192192
}
193+
if *y.VMType == limayaml.EXT {
194+
if inst.HostAgentPID > 0 {
195+
inst.Status = StatusRunning
196+
} else if inst.HostAgentPID == 0 {
197+
inst.Status = StatusStopped
198+
}
199+
return
200+
}
193201

194202
if inst.Status == StatusUnknown {
195203
if inst.HostAgentPID > 0 && inst.DriverPID > 0 {

0 commit comments

Comments
 (0)