diff options
author | Adrian Reber <areber@redhat.com> | 2018-10-16 12:07:32 +0000 |
---|---|---|
committer | Adrian Reber <adrian@lisas.de> | 2018-10-23 17:01:30 +0200 |
commit | e8d69030b621874159176eb67292ce06632ea2fd (patch) | |
tree | 17e725d1d6d2d3d94b85e9587d8282149b8a97bc /cmd/podman | |
parent | c10ac01395066ddeb321a83ab64bc02b2e765f9a (diff) | |
download | podman-e8d69030b621874159176eb67292ce06632ea2fd.tar.gz podman-e8d69030b621874159176eb67292ce06632ea2fd.tar.bz2 podman-e8d69030b621874159176eb67292ce06632ea2fd.zip |
Add --all and --latest to checkpoint/restore
This add the convenience options --all and --latest to the subcommands
checkpoint and restore.
Signed-off-by: Adrian Reber <areber@redhat.com>
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/checkpoint.go | 25 | ||||
-rw-r--r-- | cmd/podman/restore.go | 28 |
2 files changed, 27 insertions, 26 deletions
diff --git a/cmd/podman/checkpoint.go b/cmd/podman/checkpoint.go index 8582ce138..bf280920d 100644 --- a/cmd/podman/checkpoint.go +++ b/cmd/podman/checkpoint.go @@ -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" @@ -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", @@ -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) diff --git a/cmd/podman/restore.go b/cmd/podman/restore.go index 623c4936e..067a2b5d4 100644 --- a/cmd/podman/restore.go +++ b/cmd/podman/restore.go @@ -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" @@ -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", @@ -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) |