Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/limactl/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/spf13/cobra"

"github.com/lima-vm/lima/v2/cmd/limactl/editflags"
"github.com/lima-vm/lima/v2/pkg/driverutil"
"github.com/lima-vm/lima/v2/pkg/instance"
"github.com/lima-vm/lima/v2/pkg/limatype/filenames"
"github.com/lima-vm/lima/v2/pkg/limayaml"
Expand Down Expand Up @@ -79,6 +80,9 @@ func cloneAction(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
if err := driverutil.ResolveVMType(y, filePath); err != nil {
return fmt.Errorf("failed to accept config for %q: %w", filePath, err)
}
if err := limayaml.Validate(y, true); err != nil {
return saveRejectedYAML(yBytes, err)
}
Expand Down
4 changes: 4 additions & 0 deletions cmd/limactl/edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/spf13/cobra"

"github.com/lima-vm/lima/v2/cmd/limactl/editflags"
"github.com/lima-vm/lima/v2/pkg/driverutil"
"github.com/lima-vm/lima/v2/pkg/editutil"
"github.com/lima-vm/lima/v2/pkg/instance"
"github.com/lima-vm/lima/v2/pkg/limatype"
Expand Down Expand Up @@ -120,6 +121,9 @@ func editAction(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
if err := driverutil.ResolveVMType(y, filePath); err != nil {
return fmt.Errorf("failed to accept config for %q: %w", filePath, err)
}
if err := limayaml.Validate(y, true); err != nil {
return saveRejectedYAML(yBytes, err)
}
Expand Down
18 changes: 12 additions & 6 deletions cmd/limactl/editflags/editflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"

"github.com/lima-vm/lima/v2/pkg/registry"
)

// RegisterEdit registers flags related to in-place YAML modification, for `limactl edit`.
Expand Down Expand Up @@ -75,6 +77,15 @@ func RegisterEdit(cmd *cobra.Command, commentPrefix string) {
_ = cmd.RegisterFlagCompletionFunc("disk", func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
return []string{"10", "30", "50", "100", "200"}, cobra.ShellCompDirectiveNoFileComp
})

flags.String("vm-type", "", commentPrefix+"Virtual machine type")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--vm-type is not guaranteed to work as an edit flag.

e.g., this will probably not work

limactl create --vm-type qemu
limactl edit --vm-type vz

Probably we need a warning when --vm-type is specified as an edit flag for an existing instance, but it can be worked out later.

_ = cmd.RegisterFlagCompletionFunc("vm-type", func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
var drivers []string
for k := range registry.List() {
drivers = append(drivers, k)
}
return drivers, cobra.ShellCompDirectiveNoFileComp
})
}

// RegisterCreate registers flags related to in-place YAML modification, for `limactl create`.
Expand All @@ -92,11 +103,6 @@ func RegisterCreate(cmd *cobra.Command, commentPrefix string) {
return []string{"user", "system", "user+system", "none"}, cobra.ShellCompDirectiveNoFileComp
})

flags.String("vm-type", "", commentPrefix+"Virtual machine type (qemu, vz)") // colima-compatible
_ = cmd.RegisterFlagCompletionFunc("vm-type", func(*cobra.Command, []string, string) ([]string, cobra.ShellCompDirective) {
return []string{"qemu", "vz"}, cobra.ShellCompDirectiveNoFileComp
})

flags.Bool("plain", false, commentPrefix+"Plain mode. Disables mounts, port forwarding, containerd, etc.")
}

Expand Down Expand Up @@ -177,6 +183,7 @@ func YQExpressions(flags *flag.FlagSet, newInstance bool) ([]string, error) {
false,
},
{"mount-type", d(".mountType = %q"), false, false},
{"vm-type", d(".vmType = %q"), false, false},
{"mount-inotify", d(".mountInotify = %s"), false, true},
{"mount-writable", d(".mounts[].writable = %s"), false, false},
{
Expand Down Expand Up @@ -262,7 +269,6 @@ func YQExpressions(flags *flag.FlagSet, newInstance bool) ([]string, error) {
false,
},
{"disk", d(".disk= \"%sGiB\""), false, false},
{"vm-type", d(".vmType = %q"), true, false},
{"plain", d(".plain = %s"), true, false},
}
var exprs []string
Expand Down
1 change: 1 addition & 0 deletions cmd/limactl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func main() {
}
rootCmd := newApp()
if err := executeWithPluginSupport(rootCmd, os.Args[1:]); err != nil {
server.StopAllExternalDrivers()
handleExitCoder(err)
logrus.Fatal(err)
}
Expand Down
5 changes: 5 additions & 0 deletions cmd/limactl/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ package main

import (
"context"
"fmt"
"maps"
"os"

"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/lima-vm/lima/v2/pkg/downloader"
"github.com/lima-vm/lima/v2/pkg/driverutil"
"github.com/lima-vm/lima/v2/pkg/limatype"
"github.com/lima-vm/lima/v2/pkg/limayaml"
"github.com/lima-vm/lima/v2/pkg/store"
Expand Down Expand Up @@ -95,6 +97,9 @@ func knownLocations(ctx context.Context) (map[string]limatype.File, error) {
if err != nil {
return nil, err
}
if err := driverutil.ResolveVMType(y, t.Name); err != nil {
return nil, fmt.Errorf("failed to accept config for %q: %w", t.Name, err)
}
maps.Copy(locations, locationsFromLimaYAML(y))
}
return locations, nil
Expand Down
4 changes: 4 additions & 0 deletions cmd/limactl/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/spf13/pflag"

"github.com/lima-vm/lima/v2/cmd/limactl/editflags"
"github.com/lima-vm/lima/v2/pkg/driverutil"
"github.com/lima-vm/lima/v2/pkg/editutil"
"github.com/lima-vm/lima/v2/pkg/instance"
"github.com/lima-vm/lima/v2/pkg/limatmpl"
Expand Down Expand Up @@ -362,6 +363,9 @@ func applyYQExpressionToExistingInstance(ctx context.Context, inst *limatype.Ins
if err != nil {
return nil, err
}
if err := driverutil.ResolveVMType(y, filePath); err != nil {
return nil, fmt.Errorf("failed to accept config for %q: %w", filePath, err)
}
if err := limayaml.Validate(y, true); err != nil {
rejectedYAML := "lima.REJECTED.yaml"
if writeErr := os.WriteFile(rejectedYAML, yBytes, 0o644); writeErr != nil {
Expand Down
9 changes: 9 additions & 0 deletions cmd/limactl/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/lima-vm/lima/v2/pkg/driverutil"
"github.com/lima-vm/lima/v2/pkg/limatmpl"
"github.com/lima-vm/lima/v2/pkg/limatype/dirnames"
"github.com/lima-vm/lima/v2/pkg/limayaml"
Expand Down Expand Up @@ -87,6 +88,10 @@ func fillDefaults(ctx context.Context, tmpl *limatmpl.Template) error {
if err == nil {
tmpl.Bytes, err = limayaml.Marshal(tmpl.Config, false)
}
if err := driverutil.ResolveVMType(tmpl.Config, filePath); err != nil {
logrus.Warnf("failed to resolve VM type for %q: %v", filePath, err)
return nil
}
return err
}

Expand Down Expand Up @@ -246,6 +251,10 @@ func templateValidateAction(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
if err := driverutil.ResolveVMType(y, filePath); err != nil {
logrus.Warnf("failed to resolve VM type for %q: %v", filePath, err)
return nil
}
if err := limayaml.Validate(y, false); err != nil {
return fmt.Errorf("failed to validate YAML file %q: %w", arg, err)
}
Expand Down
5 changes: 4 additions & 1 deletion hack/test-upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,11 @@ INFO "==========================================================================
INFO "Installing the new Lima ${NEWVER}"
install_lima "${NEWVER}"

INFO "Editing the instance to specify vm-type as qemu explicitly"
limactl edit --vm-type=qemu "${LIMA_INSTANCE}"

INFO "Restarting the instance"
limactl start --tty=false "${LIMA_INSTANCE}" || show_lima_log
limactl start --tty=false --vm-type=qemu "${LIMA_INSTANCE}" || show_lima_log
lima nerdctl info

INFO "Confirming that the host filesystem is still mounted"
Expand Down
36 changes: 27 additions & 9 deletions pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/sirupsen/logrus"

"github.com/lima-vm/lima/v2/pkg/debugutil"
"github.com/lima-vm/lima/v2/pkg/driver"
"github.com/lima-vm/lima/v2/pkg/instance/hostname"
"github.com/lima-vm/lima/v2/pkg/iso9660util"
"github.com/lima-vm/lima/v2/pkg/limatype"
Expand Down Expand Up @@ -137,14 +138,19 @@ func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, i
Containerd: Containerd{System: *instConfig.Containerd.System, User: *instConfig.Containerd.User, Archive: archive},
SlirpNICName: networks.SlirpNICName,

RosettaEnabled: *instConfig.Rosetta.Enabled,
RosettaBinFmt: *instConfig.Rosetta.BinFmt,
VMType: *instConfig.VMType,
VSockPort: vsockPort,
VirtioPort: virtioPort,
Plain: *instConfig.Plain,
TimeZone: *instConfig.TimeZone,
Param: instConfig.Param,
VMType: *instConfig.VMType,
VSockPort: vsockPort,
VirtioPort: virtioPort,
Plain: *instConfig.Plain,
TimeZone: *instConfig.TimeZone,
Param: instConfig.Param,
}

if instConfig.VMOpts.VZ.Rosetta.Enabled != nil {
args.RosettaEnabled = *instConfig.VMOpts.VZ.Rosetta.Enabled
}
if instConfig.VMOpts.VZ.Rosetta.BinFmt != nil {
args.RosettaEnabled = *instConfig.VMOpts.VZ.Rosetta.BinFmt
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- args.RosettaEnabled = *instConfig.VMOpts.VZ.Rosetta.BinFmt
+ args.RosettaBinFmt = *instConfig.VMOpts.VZ.Rosetta.BinFmt

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opened #3921

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

}

firstUsernetIndex := limayaml.FirstUsernetIndex(instConfig)
Expand Down Expand Up @@ -357,7 +363,7 @@ func GenerateCloudConfig(ctx context.Context, instDir, name string, instConfig *
return os.WriteFile(filepath.Join(instDir, filenames.CloudConfig), config, 0o444)
}

func GenerateISO9660(ctx context.Context, instDir, name string, instConfig *limatype.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort int, guestAgentBinary, nerdctlArchive string, vsockPort int, virtioPort string) error {
func GenerateISO9660(ctx context.Context, drv driver.Driver, instDir, name string, instConfig *limatype.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort int, guestAgentBinary, nerdctlArchive string, vsockPort int, virtioPort string) error {
args, err := templateArgs(ctx, true, instDir, name, instConfig, udpDNSLocalPort, tcpDNSLocalPort, vsockPort, virtioPort)
if err != nil {
return err
Expand All @@ -372,6 +378,18 @@ func GenerateISO9660(ctx context.Context, instDir, name string, instConfig *lima
return err
}

driverScripts, err := drv.BootScripts()
if err != nil {
return fmt.Errorf("failed to get boot scripts: %w", err)
}

for filename, content := range driverScripts {
layout = append(layout, iso9660util.Entry{
Path: fmt.Sprintf("boot/%s", filename),
Reader: strings.NewReader(string(content)),
})
}

for i, f := range instConfig.Provision {
switch f.Mode {
case limatype.ProvisionModeSystem, limatype.ProvisionModeUser, limatype.ProvisionModeDependency:
Expand Down
44 changes: 27 additions & 17 deletions pkg/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ type Lifecycle interface {
// Validate returns error if the current driver isn't support for given config
Validate(_ context.Context) error

// Initialize is called on creating the instance for initialization.
// Create is called on creating the instance for the first time.
// (e.g., creating "vz-identifier" file)
//
// Initialize MUST return nil when it is called against an existing instance.
// Create MUST return nil when it is called against an existing instance.
//
// Initialize does not create the disks.
Initialize(_ context.Context) error
// Create does not create the disks.
Create(_ context.Context) error

// CreateDisk returns error if the current driver fails in creating disk
CreateDisk(_ context.Context) error
Expand All @@ -34,6 +34,12 @@ type Lifecycle interface {
// Stop will terminate the running vm instance.
// It returns error if there are any errors during Stop
Stop(_ context.Context) error

Delete(_ context.Context) error

InspectStatus(_ context.Context, inst *limatype.Instance) string

BootScripts() (map[string][]byte, error)
}

// GUI defines GUI-related operations.
Expand All @@ -54,12 +60,6 @@ type SnapshotManager interface {
ListSnapshots(ctx context.Context) (string, error)
}

// Registration defines operations for registering and unregistering the driver instance.
type Registration interface {
Register(ctx context.Context) error
Unregister(ctx context.Context) error
}

// GuestAgent defines operations for the guest agent.
type GuestAgent interface {
// ForwardGuestAgent returns if the guest agent sock needs forwarding by host agent.
Expand All @@ -74,23 +74,33 @@ type Driver interface {
Lifecycle
GUI
SnapshotManager
Registration
GuestAgent

Info() Info

// SetConfig sets the configuration for the instance.
// Configure sets the configuration for the instance.
Configure(inst *limatype.Instance) *ConfiguredDriver

AcceptConfig(cfg *limatype.LimaYAML, filePath string) error
FillConfig(cfg *limatype.LimaYAML, filePath string) error

SSHAddress(ctx context.Context) (string, error)
}

type ConfiguredDriver struct {
Driver
}

type Info struct {
DriverName string `json:"driverName"`
CanRunGUI bool `json:"canRunGui,omitempty"`
VsockPort int `json:"vsockPort"`
VirtioPort string `json:"virtioPort"`
InstanceDir string `json:"instanceDir,omitempty"`
DriverName string `json:"driverName"`
CanRunGUI bool `json:"canRunGui,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be in a "DriverFeatures" ?

Can be fixed later

VsockPort int `json:"vsockPort"`
VirtioPort string `json:"virtioPort"`
InstanceDir string `json:"instanceDir,omitempty"`
Features DriverFeatures `json:"features"`
}

type DriverFeatures struct {
DynamicSSHAddress bool `json:"dynamicSSHAddress"`
SkipSocketForwarding bool `json:"skipSocketForwarding"`
}
Loading