diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-04-28 18:11:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-28 18:11:39 +0200 |
commit | 4ed125f7b5228b3e5898e23fbb91d6db8b9a6c18 (patch) | |
tree | 03d2c90b648219f3481653f9cd7a84b78b2d4eba /pkg/api/handlers/compat/containers_prune.go | |
parent | 5077aece7e7c7531f002116ffce33c0cf0d03ec3 (diff) | |
parent | 5436e314417e4822d105d1efdbea4e5442d6f42d (diff) | |
download | podman-4ed125f7b5228b3e5898e23fbb91d6db8b9a6c18.tar.gz podman-4ed125f7b5228b3e5898e23fbb91d6db8b9a6c18.tar.bz2 podman-4ed125f7b5228b3e5898e23fbb91d6db8b9a6c18.zip |
Merge pull request #5907 from sujil02/systemprune-v2
Adding system prune for podman v2
Diffstat (limited to 'pkg/api/handlers/compat/containers_prune.go')
-rw-r--r-- | pkg/api/handlers/compat/containers_prune.go | 35 |
1 files changed, 27 insertions, 8 deletions
diff --git a/pkg/api/handlers/compat/containers_prune.go b/pkg/api/handlers/compat/containers_prune.go index b4e98ac1f..9d77f612b 100644 --- a/pkg/api/handlers/compat/containers_prune.go +++ b/pkg/api/handlers/compat/containers_prune.go @@ -38,21 +38,24 @@ func PruneContainers(w http.ResponseWriter, r *http.Request) { filterFuncs = append(filterFuncs, generatedFunc) } } - prunedContainers, pruneErrors, err := runtime.PruneContainers(filterFuncs) - if err != nil { - utils.InternalServerError(w, err) - return - } // Libpod response differs if utils.IsLibpodRequest(r) { - report := &entities.ContainerPruneReport{ - Err: pruneErrors, - ID: prunedContainers, + report, err := PruneContainersHelper(w, r, filterFuncs) + if err != nil { + utils.InternalServerError(w, err) + return } + utils.WriteResponse(w, http.StatusOK, report) return } + + prunedContainers, pruneErrors, err := runtime.PruneContainers(filterFuncs) + if err != nil { + utils.InternalServerError(w, err) + return + } for ctrID, size := range prunedContainers { if pruneErrors[ctrID] == nil { space += size @@ -65,3 +68,19 @@ func PruneContainers(w http.ResponseWriter, r *http.Request) { } utils.WriteResponse(w, http.StatusOK, report) } + +func PruneContainersHelper(w http.ResponseWriter, r *http.Request, filterFuncs []libpod.ContainerFilter) ( + *entities.ContainerPruneReport, error) { + runtime := r.Context().Value("runtime").(*libpod.Runtime) + prunedContainers, pruneErrors, err := runtime.PruneContainers(filterFuncs) + if err != nil { + utils.InternalServerError(w, err) + return nil, err + } + + report := &entities.ContainerPruneReport{ + Err: pruneErrors, + ID: prunedContainers, + } + return report, nil +} |