refactor spec and snapshot restore into opts

Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
Evan Hazlett
2018-09-17 09:47:04 -04:00
parent 45c700a955
commit 2d3db08daf
4 changed files with 51 additions and 35 deletions

View File

@@ -288,7 +288,7 @@ var infoCommand = cli.Command{
var checkpointCommand = cli.Command{
Name: "checkpoint",
Usage: "checkpoint a container",
ArgsUsage: "CONTAINER REF [flags]",
ArgsUsage: "CONTAINER REF",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "rw",
@@ -342,7 +342,7 @@ var checkpointCommand = cli.Command{
var restoreCommand = cli.Command{
Name: "restore",
Usage: "restore a container from checkpoint",
ArgsUsage: "CONTAINER REF [flags]",
ArgsUsage: "CONTAINER REF",
Flags: []cli.Flag{
cli.BoolFlag{
Name: "live",
@@ -358,18 +358,20 @@ var restoreCommand = cli.Command{
if ref == "" {
return errors.New("ref must be provided")
}
opts := []containerd.RestoreOpts{
containerd.WithRestoreSpec,
containerd.WithRestoreRuntime,
}
if context.Bool("live") {
opts = append(opts, containerd.WithRestoreLive)
}
client, ctx, cancel, err := commands.NewClient(context)
if err != nil {
return err
}
defer cancel()
opts := []containerd.RestoreOpts{
containerd.WithRestoreSpec,
containerd.WithRestoreSnapshot,
containerd.WithRestoreRuntime,
}
if context.Bool("live") {
opts = append(opts, containerd.WithRestoreLive)
}
if err := client.Restore(ctx, id, ref, opts...); err != nil {
return err
}