summaryrefslogtreecommitdiff
path: root/cmd/podman/containers_prune.go
diff options
context:
space:
mode:
authorDaniel J Walsh <dwalsh@redhat.com>2019-02-05 10:41:55 -0800
committerDaniel J Walsh <dwalsh@redhat.com>2019-02-05 10:41:55 -0800
commit74d984e0560b2cb421287395b025687e3aabe118 (patch)
tree97de4a88cb4c201b3a69b15767aa79c55c3a9b6e /cmd/podman/containers_prune.go
parent650e242aa90fcb3f161da6e97921c606d3083215 (diff)
downloadpodman-74d984e0560b2cb421287395b025687e3aabe118.tar.gz
podman-74d984e0560b2cb421287395b025687e3aabe118.tar.bz2
podman-74d984e0560b2cb421287395b025687e3aabe118.zip
Add podman system prune and info commands
We are missing the equivalence of the docker system commands This patch set adds `podman system prune` and `podman system info` Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
Diffstat (limited to 'cmd/podman/containers_prune.go')
-rw-r--r--cmd/podman/containers_prune.go37
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"))
}