From 5436e314417e4822d105d1efdbea4e5442d6f42d Mon Sep 17 00:00:00 2001 From: Sujil02 Date: Mon, 20 Apr 2020 10:10:41 -0400 Subject: Adding system prune for podman v2 Register system prune route, handler to support system prune, Adds testcase to validate the system prune flow. Signed-off-by: Sujil02 --- pkg/bindings/system/system.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'pkg/bindings/system/system.go') diff --git a/pkg/bindings/system/system.go b/pkg/bindings/system/system.go index fce8bbb8e..aee9a7ffd 100644 --- a/pkg/bindings/system/system.go +++ b/pkg/bindings/system/system.go @@ -6,9 +6,11 @@ import ( "io" "net/http" "net/url" + "strconv" "github.com/containers/libpod/pkg/api/handlers" "github.com/containers/libpod/pkg/bindings" + "github.com/containers/libpod/pkg/domain/entities" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -59,3 +61,26 @@ func Events(ctx context.Context, eventChan chan (handlers.Event), cancelChan cha } return nil } + +// Prune removes all unused system data. +func Prune(ctx context.Context, all, volumes *bool) (*entities.SystemPruneReport, error) { + var ( + report entities.SystemPruneReport + ) + conn, err := bindings.GetClient(ctx) + if err != nil { + return nil, err + } + params := url.Values{} + if all != nil { + params.Set("All", strconv.FormatBool(*all)) + } + if volumes != nil { + params.Set("Volumes", strconv.FormatBool(*volumes)) + } + response, err := conn.DoRequest(nil, http.MethodPost, "/system/prune", params) + if err != nil { + return nil, err + } + return &report, response.Process(&report) +} -- cgit v1.2.3-54-g00ecf