Skip to content

Commit 33beaf8

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

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
@@ -930,6 +930,8 @@ func NewVMType(driver string) VMType {
930930
return QEMU
931931
case "wsl2":
932932
return WSL2
933+
case "ext":
934+
return EXT
933935
default:
934936
logrus.Warnf("Unknown driver: %s", driver)
935937
return driver

pkg/limayaml/limayaml.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const (
7070
QEMU VMType = "qemu"
7171
VZ VMType = "vz"
7272
WSL2 VMType = "wsl2"
73+
EXT VMType = "ext"
7374
)
7475

7576
type Rosetta struct {

pkg/limayaml/validate.go

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

69-
if len(y.Images) == 0 {
71+
if len(y.Images) == 0 && *y.VMType != EXT {
7072
return errors.New("field `images` must be set")
7173
}
7274
for i, f := range y.Images {
@@ -154,6 +156,9 @@ func Validate(y *LimaYAML, warn bool) error {
154156
}
155157
}
156158

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

pkg/store/instance.go

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

196204
if inst.Status == StatusUnknown {
197205
switch {

0 commit comments

Comments
 (0)