diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2019-02-06 23:03:21 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-06 23:03:21 +0100 |
commit | c7350721bff99fb4455a0ddb51e7155e04a9283d (patch) | |
tree | 9c5dd9778e8cdd8fc9f0b5880c3fdb7f9a615d61 /cmd/podman/containers_prune.go | |
parent | 72fcfb7e8624a4f61761d10f3bd80d9c6da3e31e (diff) | |
parent | 0830bb9035a9ee35810e358a32b8011da2dc1be6 (diff) | |
download | podman-c7350721bff99fb4455a0ddb51e7155e04a9283d.tar.gz podman-c7350721bff99fb4455a0ddb51e7155e04a9283d.tar.bz2 podman-c7350721bff99fb4455a0ddb51e7155e04a9283d.zip |
Merge pull request #2252 from rhatdan/system
Add podman system prune and info commands
Diffstat (limited to 'cmd/podman/containers_prune.go')
-rw-r--r-- | cmd/podman/containers_prune.go | 37 |
1 files changed, 20 insertions, 17 deletions
diff --git a/cmd/podman/containers_prune.go b/cmd/podman/containers_prune.go index 92604e82f..09141e9a3 100644 --- a/cmd/podman/containers_prune.go +++ b/cmd/podman/containers_prune.go @@ -1,9 +1,11 @@ package main import ( - "github.com/containers/libpod/cmd/podman/libpodruntime" + "context" + "github.com/containers/libpod/cmd/podman/shared" "github.com/containers/libpod/libpod" + "github.com/containers/libpod/libpod/adapter" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/urfave/cli" @@ -25,20 +27,11 @@ var ( } ) -func pruneContainersCmd(c *cli.Context) error { - var ( - deleteFuncs []shared.ParallelWorkerInput - ) - - ctx := getContext() - runtime, err := libpodruntime.GetRuntime(c) - if err != nil { - return errors.Wrapf(err, "could not get runtime") - } - defer runtime.Shutdown(false) +func pruneContainers(runtime *adapter.LocalRuntime, ctx context.Context, maxWorkers int, force bool) error { + var deleteFuncs []shared.ParallelWorkerInput filter := func(c *libpod.Container) bool { - state, _ := c.State() + state, err := c.State() if state == libpod.ContainerStateStopped || (state == libpod.ContainerStateExited && err == nil && c.PodID() == "") { return true } @@ -54,7 +47,7 @@ func pruneContainersCmd(c *cli.Context) error { for _, container := range delContainers { con := container f := func() error { - return runtime.RemoveContainer(ctx, con, c.Bool("force")) + return runtime.RemoveContainer(ctx, con, force) } deleteFuncs = append(deleteFuncs, shared.ParallelWorkerInput{ @@ -62,13 +55,23 @@ func pruneContainersCmd(c *cli.Context) error { ParallelFunc: f, }) } + // Run the parallel funcs + deleteErrors, errCount := shared.ParallelExecuteWorkerPool(maxWorkers, deleteFuncs) + return printParallelOutput(deleteErrors, errCount) +} + +func pruneContainersCmd(c *cli.Context) error { + runtime, err := adapter.GetRuntime(c) + if err != nil { + return errors.Wrapf(err, "could not get runtime") + } + defer runtime.Shutdown(false) + maxWorkers := shared.Parallelize("rm") if c.GlobalIsSet("max-workers") { maxWorkers = c.GlobalInt("max-workers") } logrus.Debugf("Setting maximum workers to %d", maxWorkers) - // Run the parallel funcs - deleteErrors, errCount := shared.ParallelExecuteWorkerPool(maxWorkers, deleteFuncs) - return printParallelOutput(deleteErrors, errCount) + return pruneContainers(runtime, getContext(), maxWorkers, c.Bool("force")) } |