Skip to content

vz: implement auto save/restore #2900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions cmd/limactl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ func newApp() *cobra.Command {
newProtectCommand(),
newUnprotectCommand(),
newTunnelCommand(),
newSaveCommand(),
)
if runtime.GOOS == "darwin" || runtime.GOOS == "linux" {
rootCmd.AddCommand(startAtLoginCommand())
Expand Down
44 changes: 44 additions & 0 deletions cmd/limactl/save.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"github.com/lima-vm/lima/pkg/instance"
networks "github.com/lima-vm/lima/pkg/networks/reconcile"
"github.com/lima-vm/lima/pkg/store"
"github.com/spf13/cobra"
)

func newSaveCommand() *cobra.Command {
saveCmd := &cobra.Command{
Use: "save INSTANCE",
Short: "Save an instance",
Copy link
Member

Choose a reason for hiding this comment

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

This also stop the instance but the name or the help do not explain this. I think this is confusing user interface even if we improve the help text, and it is better to have:

limactl stop --save

Using --save and --force should be an error.

This also more consistent with saveOnStop instance config. You either enable save on stop for the instance, or for specific stop of the instance.

Args: WrapArgsError(cobra.MaximumNArgs(1)),
RunE: saveAction,
ValidArgsFunction: saveBashComplete,
GroupID: basicCommand,
}

return saveCmd
}

func saveAction(cmd *cobra.Command, args []string) error {
instName := DefaultInstanceName
if len(args) > 0 {
instName = args[0]
}

inst, err := store.Inspect(instName)
if err != nil {
return err
}

err = instance.StopGracefully(inst, true)
// TODO: should we also reconcile networks if graceful save returned an error?
if err == nil {
err = networks.Reconcile(cmd.Context(), "")
}
return err
}

func saveBashComplete(cmd *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return bashCompleteInstanceNames(cmd)
}