From 4319552cf89e72925a80c63f427e5ef0a6376046 Mon Sep 17 00:00:00 2001 From: Peter Hunt Date: Mon, 15 Apr 2019 15:44:32 -0400 Subject: Added remote pod prune Signed-off-by: Peter Hunt --- pkg/varlinkapi/pods.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'pkg/varlinkapi/pods.go') diff --git a/pkg/varlinkapi/pods.go b/pkg/varlinkapi/pods.go index ac8e24747..f34375bf5 100644 --- a/pkg/varlinkapi/pods.go +++ b/pkg/varlinkapi/pods.go @@ -101,6 +101,28 @@ func (i *LibpodAPI) GetPod(call iopodman.VarlinkCall, name string) error { return call.ReplyGetPod(listPod) } +// GetPodsByStatus returns a slice of pods filtered by a libpod status +func (i *LibpodAPI) GetPodsByStatus(call iopodman.VarlinkCall, statuses []string) error { + filterFuncs := func(p *libpod.Pod) bool { + state, _ := shared.GetPodStatus(p) + for _, status := range statuses { + if state == status { + return true + } + } + return false + } + filteredPods, err := i.Runtime.Pods(filterFuncs) + if err != nil { + return call.ReplyErrorOccurred(err.Error()) + } + podIDs := make([]string, 0, len(filteredPods)) + for _, p := range filteredPods { + podIDs = append(podIDs, p.ID()) + } + return call.ReplyGetPodsByStatus(podIDs) +} + // InspectPod ... func (i *LibpodAPI) InspectPod(call iopodman.VarlinkCall, name string) error { pod, err := i.Runtime.LookupPod(name) -- cgit v1.2.3-54-g00ecf