diff options
author | Brent Baude <bbaude@redhat.com> | 2020-01-24 08:59:20 -0600 |
---|---|---|
committer | Brent Baude <bbaude@redhat.com> | 2020-01-25 15:09:09 -0600 |
commit | 5da70b04dd95263a536cc148288d2e20cd9dea30 (patch) | |
tree | 3d28c000a7941d9f8ea4aef906d29a44c2e80484 /libpod/runtime_pod.go | |
parent | 81e59a742b46d41848c8c213e155fbc9ecc4e5f8 (diff) | |
download | podman-5da70b04dd95263a536cc148288d2e20cd9dea30.tar.gz podman-5da70b04dd95263a536cc148288d2e20cd9dea30.tar.bz2 podman-5da70b04dd95263a536cc148288d2e20cd9dea30.zip |
APIv2 review corrections #3
The third pass of corrections for the APIv2.
Signed-off-by: Brent Baude <bbaude@redhat.com>
Diffstat (limited to 'libpod/runtime_pod.go')
-rw-r--r-- | libpod/runtime_pod.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/libpod/runtime_pod.go b/libpod/runtime_pod.go index 66f9b10c9..e1dc31391 100644 --- a/libpod/runtime_pod.go +++ b/libpod/runtime_pod.go @@ -182,3 +182,31 @@ func (r *Runtime) GetRunningPods() ([]*Pod, error) { } return runningPods, nil } + +// PrunePods removes unused pods and their containers from local storage. +// If force is given, then running pods are also included in the pruning. +func (r *Runtime) PrunePods() (map[string]error, error) { + response := make(map[string]error) + states := []string{define.PodStateStopped, define.PodStateExited} + filterFunc := func(p *Pod) bool { + state, _ := p.GetPodStatus() + for _, status := range states { + if state == status { + return true + } + } + return false + } + pods, err := r.Pods(filterFunc) + if err != nil { + return nil, err + } + if len(pods) < 1 { + return response, nil + } + for _, pod := range pods { + err := r.removePod(context.TODO(), pod, true, false) + response[pod.ID()] = err + } + return response, nil +} |