Skip to content

Commit b1ed5fc

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

File tree

7 files changed

+42
-3
lines changed

7 files changed

+42
-3
lines changed

pkg/driverutil/driverutil.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ func Drivers() []string {
1818
if wsl2.Enabled {
1919
drivers = append(drivers, limayaml.WSL2)
2020
}
21+
drivers = append(drivers, limayaml.EXT)
2122
return drivers
2223
}

pkg/driverutil/instance.go

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

66
import (
77
"github.com/lima-vm/lima/pkg/driver"
8+
"github.com/lima-vm/lima/pkg/ext"
89
"github.com/lima-vm/lima/pkg/limayaml"
910
"github.com/lima-vm/lima/pkg/qemu"
1011
"github.com/lima-vm/lima/pkg/vz"
@@ -19,5 +20,8 @@ func CreateTargetDriverInstance(base *driver.BaseDriver) driver.Driver {
1920
if *limaDriver == limayaml.WSL2 {
2021
return wsl2.New(base)
2122
}
23+
if *limaDriver == limayaml.EXT {
24+
return ext.New(base)
25+
}
2226
return qemu.New(base)
2327
}

pkg/ext/ext_driver.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// SPDX-FileCopyrightText: Copyright The Lima Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package ext
5+
6+
import (
7+
"github.com/lima-vm/lima/pkg/driver"
8+
)
9+
10+
type LimaExtDriver struct {
11+
*driver.BaseDriver
12+
}
13+
14+
func New(driver *driver.BaseDriver) *LimaExtDriver {
15+
return &LimaExtDriver{
16+
BaseDriver: driver,
17+
}
18+
}

pkg/limayaml/defaults.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1109,6 +1109,8 @@ func NewVMType(driver string) VMType {
11091109
return QEMU
11101110
case "wsl2":
11111111
return WSL2
1112+
case "ext":
1113+
return EXT
11121114
default:
11131115
logrus.Warnf("Unknown driver: %s", driver)
11141116
return driver

pkg/limayaml/limayaml.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,14 @@ const (
8787
QEMU VMType = "qemu"
8888
VZ VMType = "vz"
8989
WSL2 VMType = "wsl2"
90+
EXT VMType = "ext"
9091
)
9192

9293
var (
9394
OSTypes = []OS{LINUX}
9495
ArchTypes = []Arch{X8664, AARCH64, ARMV7L, RISCV64, S390X}
9596
MountTypes = []MountType{REVSSHFS, NINEP, VIRTIOFS, WSLMount}
96-
VMTypes = []VMType{QEMU, VZ, WSL2}
97+
VMTypes = []VMType{QEMU, VZ, WSL2, EXT}
9798
)
9899

99100
type User struct {

pkg/limayaml/validate.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,13 @@ func Validate(y *LimaYAML, warn bool) error {
9292
if !IsNativeArch(*y.Arch) {
9393
return fmt.Errorf("field `arch` must be %q for VZ; got %q", NewArch(runtime.GOARCH), *y.Arch)
9494
}
95+
case EXT:
96+
// NOP
9597
default:
96-
return fmt.Errorf("field `vmType` must be %q, %q, %q; got %q", QEMU, VZ, WSL2, *y.VMType)
98+
return fmt.Errorf("field `vmType` must be %q, %q, %q, %q; got %q", QEMU, VZ, WSL2, EXT, *y.VMType)
9799
}
98100

99-
if len(y.Images) == 0 {
101+
if len(y.Images) == 0 && *y.VMType != EXT {
100102
return errors.New("field `images` must be set")
101103
}
102104
for i, f := range y.Images {
@@ -187,6 +189,9 @@ func Validate(y *LimaYAML, warn bool) error {
187189
}
188190
}
189191

192+
if *y.SSH.Address == "127.0.0.1" && *y.VMType == EXT {
193+
return errors.New("field `ssh.address` must be set, for ext")
194+
}
190195
if y.SSH.Address != nil {
191196
if err := validateHost("ssh.address", *y.SSH.Address); err != nil {
192197
return err

pkg/store/instance.go

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

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

0 commit comments

Comments
 (0)