Skip to content

Commit 4e814fb

Browse files
committed
resolve vmtype by using internal drivers
Signed-off-by: Ansuman Sahoo <[email protected]>
1 parent 2bfc04a commit 4e814fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+851
-782
lines changed

cmd/limactl/copy.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/spf13/cobra"
1818

1919
"github.com/lima-vm/lima/v2/pkg/ioutilx"
20+
"github.com/lima-vm/lima/v2/pkg/limatype"
2021
"github.com/lima-vm/lima/v2/pkg/sshutil"
2122
"github.com/lima-vm/lima/v2/pkg/store"
2223
)
@@ -62,7 +63,7 @@ func copyAction(cmd *cobra.Command, args []string) error {
6263
if err != nil {
6364
return err
6465
}
65-
instances := make(map[string]*store.Instance)
66+
instances := make(map[string]*limatype.Instance)
6667
scpFlags := []string{}
6768
scpArgs := []string{}
6869
debug, err := cmd.Flags().GetBool("debug")
@@ -109,7 +110,7 @@ func copyAction(cmd *cobra.Command, args []string) error {
109110
}
110111
return err
111112
}
112-
if inst.Status == store.StatusStopped {
113+
if inst.Status == limatype.StatusStopped {
113114
return fmt.Errorf("instance %q is stopped, run `limactl start %s` to start the instance", instName, instName)
114115
}
115116
if legacySSH {

cmd/limactl/disk.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/spf13/cobra"
2020

2121
"github.com/lima-vm/lima/v2/pkg/imgutil/proxyimgutil"
22+
"github.com/lima-vm/lima/v2/pkg/limatype"
2223
"github.com/lima-vm/lima/v2/pkg/store"
2324
"github.com/lima-vm/lima/v2/pkg/store/filenames"
2425
)
@@ -241,7 +242,7 @@ func diskDeleteAction(cmd *cobra.Command, args []string) error {
241242
if err != nil {
242243
return err
243244
}
244-
var instances []*store.Instance
245+
var instances []*limatype.Instance
245246
for _, instName := range instNames {
246247
inst, err := store.Inspect(instName)
247248
if err != nil {
@@ -341,7 +342,7 @@ func diskUnlockAction(_ *cobra.Command, args []string) error {
341342
diskName, disk.Instance, inst.Errors)
342343
continue
343344
}
344-
if inst.Status == store.StatusRunning {
345+
if inst.Status == limatype.StatusRunning {
345346
logrus.Warnf("Cannot unlock disk %q used by running instance %q", diskName, disk.Instance)
346347
continue
347348
}
@@ -398,7 +399,7 @@ func diskResizeAction(cmd *cobra.Command, args []string) error {
398399
if disk.Instance != "" {
399400
inst, err := store.Inspect(disk.Instance)
400401
if err == nil {
401-
if inst.Status == store.StatusRunning {
402+
if inst.Status == limatype.StatusRunning {
402403
return fmt.Errorf("cannot resize disk %q used by running instance %q. Please stop the VM instance", diskName, disk.Instance)
403404
}
404405
}

cmd/limactl/edit.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/lima-vm/lima/v2/cmd/limactl/editflags"
1717
"github.com/lima-vm/lima/v2/pkg/editutil"
1818
"github.com/lima-vm/lima/v2/pkg/instance"
19+
"github.com/lima-vm/lima/v2/pkg/limatype"
1920
"github.com/lima-vm/lima/v2/pkg/limayaml"
2021
networks "github.com/lima-vm/lima/v2/pkg/networks/reconcile"
2122
"github.com/lima-vm/lima/v2/pkg/store"
@@ -45,7 +46,7 @@ func editAction(cmd *cobra.Command, args []string) error {
4546

4647
var filePath string
4748
var err error
48-
var inst *store.Instance
49+
var inst *limatype.Instance
4950

5051
if arg == "" {
5152
arg = DefaultInstanceName
@@ -58,7 +59,7 @@ func editAction(cmd *cobra.Command, args []string) error {
5859
}
5960
return err
6061
}
61-
if inst.Status == store.StatusRunning {
62+
if inst.Status == limatype.StatusRunning {
6263
return errors.New("cannot edit a running instance")
6364
}
6465
filePath = filepath.Join(inst.Dir, filenames.LimaYAML)

cmd/limactl/genschema.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
orderedmap "github.com/wk8/go-ordered-map/v2"
1616

1717
"github.com/lima-vm/lima/v2/pkg/jsonschemautil"
18-
"github.com/lima-vm/lima/v2/pkg/limayaml"
18+
"github.com/lima-vm/lima/v2/pkg/limatype"
1919
)
2020

2121
func newGenSchemaCommand() *cobra.Command {
@@ -52,7 +52,7 @@ func genschemaAction(cmd *cobra.Command, args []string) error {
5252
return err
5353
}
5454

55-
schema := jsonschema.Reflect(&limayaml.LimaYAML{})
55+
schema := jsonschema.Reflect(&limatype.LimaYAML{})
5656
// allow Disk to be either string (name) or object (struct)
5757
schema.Definitions["Disk"].Type = "" // was: "object"
5858
schema.Definitions["Disk"].OneOf = []*jsonschema.Schema{
@@ -72,10 +72,10 @@ func genschemaAction(cmd *cobra.Command, args []string) error {
7272
{Type: "object"},
7373
}
7474
properties := schema.Definitions["LimaYAML"].Properties
75-
getProp(properties, "os").Enum = toAny(limayaml.OSTypes)
76-
getProp(properties, "arch").Enum = toAny(limayaml.ArchTypes)
77-
getProp(properties, "mountType").Enum = toAny(limayaml.MountTypes)
78-
getProp(properties, "vmType").Enum = toAny(limayaml.VMTypes)
75+
getProp(properties, "os").Enum = toAny(limatype.OSTypes)
76+
getProp(properties, "arch").Enum = toAny(limatype.ArchTypes)
77+
getProp(properties, "mountType").Enum = toAny(limatype.MountTypes)
78+
getProp(properties, "vmType").Enum = toAny(limatype.VMTypes)
7979
j, err := json.MarshalIndent(schema, "", " ")
8080
if err != nil {
8181
return err

cmd/limactl/list.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/sirupsen/logrus"
1717
"github.com/spf13/cobra"
1818

19+
"github.com/lima-vm/lima/v2/pkg/limatype"
1920
"github.com/lima-vm/lima/v2/pkg/store"
2021
)
2122

@@ -171,7 +172,7 @@ func listAction(cmd *cobra.Command, args []string) error {
171172
}
172173

173174
// get the state and config for all the requested instances
174-
var instances []*store.Instance
175+
var instances []*limatype.Instance
175176
for _, instanceName := range instanceNames {
176177
instance, err := store.Inspect(instanceName)
177178
if err != nil {

cmd/limactl/prune.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"github.com/spf13/cobra"
1212

1313
"github.com/lima-vm/lima/v2/pkg/downloader"
14+
"github.com/lima-vm/lima/v2/pkg/limatype"
1415
"github.com/lima-vm/lima/v2/pkg/limayaml"
1516
"github.com/lima-vm/lima/v2/pkg/store"
1617
"github.com/lima-vm/lima/v2/pkg/templatestore"
@@ -62,8 +63,8 @@ func pruneAction(cmd *cobra.Command, _ []string) error {
6263
return nil
6364
}
6465

65-
func knownLocations() (map[string]limayaml.File, error) {
66-
locations := make(map[string]limayaml.File)
66+
func knownLocations() (map[string]limatype.File, error) {
67+
locations := make(map[string]limatype.File)
6768

6869
// Collect locations from instances
6970
instances, err := store.Instances()
@@ -97,8 +98,8 @@ func knownLocations() (map[string]limayaml.File, error) {
9798
return locations, nil
9899
}
99100

100-
func locationsFromLimaYAML(y *limayaml.LimaYAML) map[string]limayaml.File {
101-
locations := make(map[string]limayaml.File)
101+
func locationsFromLimaYAML(y *limatype.LimaYAML) map[string]limatype.File {
102+
locations := make(map[string]limatype.File)
102103
for _, f := range y.Images {
103104
locations[downloader.CacheKey(f.Location)] = f.File
104105
if f.Kernel != nil {

cmd/limactl/shell.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121

2222
"github.com/lima-vm/lima/v2/pkg/instance"
2323
"github.com/lima-vm/lima/v2/pkg/ioutilx"
24-
"github.com/lima-vm/lima/v2/pkg/limayaml"
24+
"github.com/lima-vm/lima/v2/pkg/limatype"
2525
networks "github.com/lima-vm/lima/v2/pkg/networks/reconcile"
2626
"github.com/lima-vm/lima/v2/pkg/sshutil"
2727
"github.com/lima-vm/lima/v2/pkg/store"
@@ -82,7 +82,7 @@ func shellAction(cmd *cobra.Command, args []string) error {
8282
}
8383
return err
8484
}
85-
if inst.Status == store.StatusStopped {
85+
if inst.Status == limatype.StatusStopped {
8686
startNow, err := askWhetherToStart()
8787
if err != nil {
8888
return err
@@ -140,7 +140,7 @@ func shellAction(cmd *cobra.Command, args []string) error {
140140
if workDir != "" {
141141
changeDirCmd = fmt.Sprintf("cd %s || exit 1", shellescape.Quote(workDir))
142142
// FIXME: check whether y.Mounts contains the home, not just len > 0
143-
} else if len(inst.Config.Mounts) > 0 || inst.VMType == limayaml.WSL2 {
143+
} else if len(inst.Config.Mounts) > 0 || inst.VMType == limatype.WSL2 {
144144
hostCurrentDir, err := os.Getwd()
145145
if err == nil && runtime.GOOS == "windows" {
146146
hostCurrentDir, err = mountDirFromWindowsDir(inst, hostCurrentDir)
@@ -245,8 +245,8 @@ func shellAction(cmd *cobra.Command, args []string) error {
245245
return sshCmd.Run()
246246
}
247247

248-
func mountDirFromWindowsDir(inst *store.Instance, dir string) (string, error) {
249-
if inst.VMType == limayaml.WSL2 {
248+
func mountDirFromWindowsDir(inst *limatype.Instance, dir string) (string, error) {
249+
if inst.VMType == limatype.WSL2 {
250250
distroName := "lima-" + inst.Name
251251
return ioutilx.WindowsSubsystemPathForLinux(dir, distroName)
252252
}

cmd/limactl/start.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/lima-vm/lima/v2/pkg/editutil"
2020
"github.com/lima-vm/lima/v2/pkg/instance"
2121
"github.com/lima-vm/lima/v2/pkg/limatmpl"
22+
"github.com/lima-vm/lima/v2/pkg/limatype"
2223
"github.com/lima-vm/lima/v2/pkg/limayaml"
2324
networks "github.com/lima-vm/lima/v2/pkg/networks/reconcile"
2425
"github.com/lima-vm/lima/v2/pkg/registry"
@@ -102,7 +103,7 @@ See the examples in 'limactl create --help'.
102103
return startCommand
103104
}
104105

105-
func loadOrCreateInstance(cmd *cobra.Command, args []string, createOnly bool) (*store.Instance, error) {
106+
func loadOrCreateInstance(cmd *cobra.Command, args []string, createOnly bool) (*limatype.Instance, error) {
106107
var arg string // can be empty
107108
if len(args) > 0 {
108109
arg = args[0]
@@ -240,7 +241,7 @@ func loadOrCreateInstance(cmd *cobra.Command, args []string, createOnly bool) (*
240241
return instance.Create(cmd.Context(), tmpl.Name, tmpl.Bytes, saveBrokenYAML)
241242
}
242243

243-
func applyYQExpressionToExistingInstance(inst *store.Instance, yq string) (*store.Instance, error) {
244+
func applyYQExpressionToExistingInstance(inst *limatype.Instance, yq string) (*limatype.Instance, error) {
244245
if strings.TrimSpace(yq) == "" {
245246
return inst, nil
246247
}
@@ -461,15 +462,15 @@ func startAction(cmd *cobra.Command, args []string) error {
461462
return fmt.Errorf("errors inspecting instance: %+v", inst.Errors)
462463
}
463464
switch inst.Status {
464-
case store.StatusRunning:
465+
case limatype.StatusRunning:
465466
logrus.Infof("The instance %q is already running. Run `%s` to open the shell.",
466467
inst.Name, instance.LimactlShellCmd(inst.Name))
467468
// Not an error
468469
return nil
469-
case store.StatusStopped:
470+
case limatype.StatusStopped:
470471
// NOP
471472
default:
472-
logrus.Warnf("expected status %q, got %q", store.StatusStopped, inst.Status)
473+
logrus.Warnf("expected status %q, got %q", limatype.StatusStopped, inst.Status)
473474
}
474475
ctx := cmd.Context()
475476
err = networks.Reconcile(ctx, inst.Name)

cmd/limactl/tunnel.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/spf13/cobra"
1616

1717
"github.com/lima-vm/lima/v2/pkg/freeport"
18+
"github.com/lima-vm/lima/v2/pkg/limatype"
1819
"github.com/lima-vm/lima/v2/pkg/sshutil"
1920
"github.com/lima-vm/lima/v2/pkg/store"
2021
)
@@ -71,7 +72,7 @@ func tunnelAction(cmd *cobra.Command, args []string) error {
7172
}
7273
return err
7374
}
74-
if inst.Status == store.StatusStopped {
75+
if inst.Status == limatype.StatusStopped {
7576
return fmt.Errorf("instance %q is stopped, run `limactl start %s` to start the instance", instName, instName)
7677
}
7778

0 commit comments

Comments
 (0)