summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbaude <bbaude@redhat.com>2019-01-10 14:39:39 -0600
committerMatthew Heon <matthew.heon@pm.me>2019-02-08 15:02:28 -0500
commit28f5d25e8dabb6647699c2ccab8621cefac37d3b (patch)
treefd6f995f885ad4709202a7c8f35397eb096e7c20
parent9dfefed334cda999b55820368507209f8c6721b0 (diff)
downloadpodman-28f5d25e8dabb6647699c2ccab8621cefac37d3b.tar.gz
podman-28f5d25e8dabb6647699c2ccab8621cefac37d3b.tar.bz2
podman-28f5d25e8dabb6647699c2ccab8621cefac37d3b.zip
Add varlink support for prune
Add the ability to prune unused images using the varlink API. Signed-off-by: baude <bbaude@redhat.com>
-rwxr-xr-xAPI.md8
-rw-r--r--cmd/podman/images_prune.go15
-rw-r--r--cmd/podman/shared/prune.go24
-rw-r--r--cmd/podman/varlink/io.podman.varlink4
-rw-r--r--pkg/varlinkapi/images.go18
5 files changed, 43 insertions, 26 deletions
diff --git a/API.md b/API.md
index 3722c2864..0cbdffea4 100755
--- a/API.md
+++ b/API.md
@@ -57,6 +57,8 @@ in the [API.md](https://github.com/containers/libpod/blob/master/API.md) file in
[func ImageExists(name: string) int](#ImageExists)
+[func ImagesPrune() []string](#ImagesPrune)
+
[func ImportImage(source: string, reference: string, message: string, changes: []string) string](#ImportImage)
[func InspectContainer(name: string) string](#InspectContainer)
@@ -543,6 +545,12 @@ $ varlink call -m unix:/run/podman/io.podman/io.podman.ImageExists '{"name": "im
"exists": 1
}
~~~
+### <a name="ImagesPrune"></a>func ImagesPrune
+<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
+
+method ImagesPrune() [[]string](#[]string)</div>
+ImagesPrune removes all unused images from the local store. Upon successful pruning,
+the IDs of the removed images are returned.
### <a name="ImportImage"></a>func ImportImage
<div style="background-color: #E8E8E8; padding: 15px; margin: 10px; border-radius: 10px;">
diff --git a/cmd/podman/images_prune.go b/cmd/podman/images_prune.go
index cb72a498f..06879e02d 100644
--- a/cmd/podman/images_prune.go
+++ b/cmd/podman/images_prune.go
@@ -1,8 +1,8 @@
package main
import (
+ "fmt"
"github.com/containers/libpod/cmd/podman/libpodruntime"
- "github.com/containers/libpod/cmd/podman/shared"
"github.com/pkg/errors"
"github.com/urfave/cli"
)
@@ -30,5 +30,16 @@ func pruneImagesCmd(c *cli.Context) error {
}
defer runtime.Shutdown(false)
- return shared.Prune(runtime.ImageRuntime())
+ pruneImages, err := runtime.ImageRuntime().GetPruneImages()
+ if err != nil {
+ return err
+ }
+
+ for _, i := range pruneImages {
+ if err := i.Remove(true); err != nil {
+ return errors.Wrapf(err, "failed to remove %s", i.ID())
+ }
+ fmt.Println(i.ID())
+ }
+ return nil
}
diff --git a/cmd/podman/shared/prune.go b/cmd/podman/shared/prune.go
deleted file mode 100644
index 90cfe4475..000000000
--- a/cmd/podman/shared/prune.go
+++ /dev/null
@@ -1,24 +0,0 @@
-package shared
-
-import (
- "fmt"
- "github.com/pkg/errors"
-
- "github.com/containers/libpod/libpod/image"
-)
-
-// Prune removes all unnamed and unused images from the local store
-func Prune(ir *image.Runtime) error {
- pruneImages, err := ir.GetPruneImages()
- if err != nil {
- return err
- }
-
- for _, i := range pruneImages {
- if err := i.Remove(true); err != nil {
- return errors.Wrapf(err, "failed to remove %s", i.ID())
- }
- fmt.Println(i.ID())
- }
- return nil
-}
diff --git a/cmd/podman/varlink/io.podman.varlink b/cmd/podman/varlink/io.podman.varlink
index 4e8b69faf..7cd6c16b2 100644
--- a/cmd/podman/varlink/io.podman.varlink
+++ b/cmd/podman/varlink/io.podman.varlink
@@ -1015,6 +1015,10 @@ method MountContainer(name: string) -> (path: string)
# ~~~
method UnmountContainer(name: string, force: bool) -> ()
+# ImagesPrune removes all unused images from the local store. Upon successful pruning,
+# the IDs of the removed images are returned.
+method ImagesPrune() -> (pruned: []string)
+
# This function is not implemented yet.
method ListContainerPorts(name: string) -> (notimplemented: NotImplemented)
diff --git a/pkg/varlinkapi/images.go b/pkg/varlinkapi/images.go
index 8f8934025..4a4f20031 100644
--- a/pkg/varlinkapi/images.go
+++ b/pkg/varlinkapi/images.go
@@ -620,3 +620,21 @@ func (i *LibpodAPI) ContainerRunlabel(call iopodman.VarlinkCall, input iopodman.
}
return call.ReplyContainerRunlabel()
}
+
+// ImagesPrune ....
+func (i *LibpodAPI) ImagesPrune(call iopodman.VarlinkCall) error {
+ var (
+ pruned []string
+ )
+ pruneImages, err := i.Runtime.ImageRuntime().GetPruneImages()
+ if err != nil {
+ return err
+ }
+ for _, i := range pruneImages {
+ if err := i.Remove(true); err != nil {
+ return call.ReplyErrorOccurred(err.Error())
+ }
+ pruned = append(pruned, i.ID())
+ }
+ return call.ReplyImagesPrune(pruned)
+}