Skip to content

Commit b865895

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

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
@@ -864,6 +864,8 @@ func NewVMType(driver string) VMType {
864864
return QEMU
865865
case "wsl2":
866866
return WSL2
867+
case "ext":
868+
return EXT
867869
default:
868870
logrus.Warnf("Unknown driver: %s", driver)
869871
return driver

pkg/limayaml/limayaml.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ const (
6464
QEMU VMType = "qemu"
6565
VZ VMType = "vz"
6666
WSL2 VMType = "wsl2"
67+
EXT VMType = "ext"
6768
)
6869

6970
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
@@ -177,6 +177,14 @@ func inspectStatusWithPIDFiles(instDir string, inst *Instance, y *limayaml.LimaY
177177
inst.Status = StatusBroken
178178
inst.Errors = append(inst.Errors, err)
179179
}
180+
if *y.VMType == limayaml.EXT {
181+
if inst.HostAgentPID > 0 {
182+
inst.Status = StatusRunning
183+
} else if inst.HostAgentPID == 0 {
184+
inst.Status = StatusStopped
185+
}
186+
return
187+
}
180188

181189
if inst.Status == StatusUnknown {
182190
if inst.HostAgentPID > 0 && inst.DriverPID > 0 {

0 commit comments

Comments
 (0)