Skip to content

Commit

Permalink
Add --all and --latest to checkpoint/restore
Browse files Browse the repository at this point in the history
This add the convenience options --all and --latest to the subcommands
checkpoint and restore.

Signed-off-by: Adrian Reber <[email protected]>
  • Loading branch information
adrianreber committed Oct 23, 2018
1 parent c10ac01 commit e8d6903
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 26 deletions.
25 changes: 12 additions & 13 deletions cmd/podman/checkpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/rootless"
"github.com/pkg/errors"
"github.com/urfave/cli"
Expand All @@ -22,6 +23,11 @@ var (
Name: "keep, k",
Usage: "keep all temporary checkpoint files",
},
cli.BoolFlag{
Name: "all, a",
Usage: "checkpoint all running containers",
},
LatestFlag,
}
checkpointCommand = cli.Command{
Name: "checkpoint",
Expand All @@ -45,21 +51,14 @@ func checkpointCmd(c *cli.Context) error {
defer runtime.Shutdown(false)

keep := c.Bool("keep")
args := c.Args()
if len(args) < 1 {
return errors.Errorf("you must provide at least one container name or id")

if err := checkAllAndLatest(c); err != nil {
return err
}

var lastError error
for _, arg := range args {
ctr, err := runtime.LookupContainer(arg)
if err != nil {
if lastError != nil {
fmt.Fprintln(os.Stderr, lastError)
}
lastError = errors.Wrapf(err, "error looking up container %q", arg)
continue
}
containers, lastError := getAllOrLatestContainers(c, runtime, libpod.ContainerStateRunning, "running")

for _, ctr := range containers {
if err = ctr.Checkpoint(context.TODO(), keep); err != nil {
if lastError != nil {
fmt.Fprintln(os.Stderr, lastError)
Expand Down
28 changes: 15 additions & 13 deletions cmd/podman/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"

"github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod"
"github.com/containers/libpod/pkg/rootless"
"github.com/pkg/errors"
"github.com/urfave/cli"
Expand All @@ -22,6 +23,14 @@ var (
Name: "keep, k",
Usage: "keep all temporary checkpoint files",
},
// restore --all would make more sense if there would be
// dedicated state for container which are checkpointed.
// TODO: add ContainerStateCheckpointed
cli.BoolFlag{
Name: "all, a",
Usage: "restore all checkpointed containers",
},
LatestFlag,
}
restoreCommand = cli.Command{
Name: "restore",
Expand All @@ -45,21 +54,14 @@ func restoreCmd(c *cli.Context) error {
defer runtime.Shutdown(false)

keep := c.Bool("keep")
args := c.Args()
if len(args) < 1 {
return errors.Errorf("you must provide at least one container name or id")

if err := checkAllAndLatest(c); err != nil {
return err
}

var lastError error
for _, arg := range args {
ctr, err := runtime.LookupContainer(arg)
if err != nil {
if lastError != nil {
fmt.Fprintln(os.Stderr, lastError)
}
lastError = errors.Wrapf(err, "error looking up container %q", arg)
continue
}
containers, lastError := getAllOrLatestContainers(c, runtime, libpod.ContainerStateRunning, "checkpointed")

for _, ctr := range containers {
if err = ctr.Restore(context.TODO(), keep); err != nil {
if lastError != nil {
fmt.Fprintln(os.Stderr, lastError)
Expand Down

0 comments on commit e8d6903

Please sign in to comment.