summaryrefslogtreecommitdiff
path: root/cmd/podman/volume_prune.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-02-06 23:03:21 +0100
committerGitHub <noreply@github.com>2019-02-06 23:03:21 +0100
commitc7350721bff99fb4455a0ddb51e7155e04a9283d (patch)
tree9c5dd9778e8cdd8fc9f0b5880c3fdb7f9a615d61 /cmd/podman/volume_prune.go
parent72fcfb7e8624a4f61761d10f3bd80d9c6da3e31e (diff)
parent0830bb9035a9ee35810e358a32b8011da2dc1be6 (diff)
downloadpodman-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/volume_prune.go')
-rw-r--r--cmd/podman/volume_prune.go48
1 files changed, 26 insertions, 22 deletions
diff --git a/cmd/podman/volume_prune.go b/cmd/podman/volume_prune.go
index 652c50f42..41d95f9c7 100644
--- a/cmd/podman/volume_prune.go
+++ b/cmd/podman/volume_prune.go
@@ -2,12 +2,13 @@ package main
import (
"bufio"
+ "context"
"fmt"
"os"
"strings"
- "github.com/containers/libpod/cmd/podman/libpodruntime"
"github.com/containers/libpod/libpod"
+ "github.com/containers/libpod/libpod/adapter"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
@@ -37,21 +38,40 @@ var volumePruneCommand = cli.Command{
UseShortOptionHandling: true,
}
-func volumePruneCmd(c *cli.Context) error {
+func volumePrune(runtime *adapter.LocalRuntime, ctx context.Context) error {
var lastError error
+ volumes, err := runtime.GetAllVolumes()
+ if err != nil {
+ return err
+ }
+
+ for _, vol := range volumes {
+ err = runtime.RemoveVolume(ctx, vol, false, true)
+ if err == nil {
+ fmt.Println(vol.Name())
+ } else if err != libpod.ErrVolumeBeingUsed {
+ if lastError != nil {
+ logrus.Errorf("%q", lastError)
+ }
+ lastError = errors.Wrapf(err, "failed to remove volume %q", vol.Name())
+ }
+ }
+ return lastError
+}
+
+func volumePruneCmd(c *cli.Context) error {
+
if err := validateFlags(c, volumePruneFlags); err != nil {
return err
}
- runtime, err := libpodruntime.GetRuntime(c)
+ runtime, err := adapter.GetRuntime(c)
if err != nil {
return errors.Wrapf(err, "error creating libpod runtime")
}
defer runtime.Shutdown(false)
- ctx := getContext()
-
// Prompt for confirmation if --force is not set
if !c.Bool("force") {
reader := bufio.NewReader(os.Stdin)
@@ -66,21 +86,5 @@ func volumePruneCmd(c *cli.Context) error {
}
}
- volumes, err := runtime.GetAllVolumes()
- if err != nil {
- return err
- }
-
- for _, vol := range volumes {
- err = runtime.RemoveVolume(ctx, vol, false, true)
- if err == nil {
- fmt.Println(vol.Name())
- } else if err != libpod.ErrVolumeBeingUsed {
- if lastError != nil {
- logrus.Errorf("%q", lastError)
- }
- lastError = errors.Wrapf(err, "failed to remove volume %q", vol.Name())
- }
- }
- return lastError
+ return volumePrune(runtime, getContext())
}