From 8ea02d0b6033b6ffdc68d38f3276410f4e2e8eb9 Mon Sep 17 00:00:00 2001 From: Jakub Guzik Date: Thu, 18 Mar 2021 00:01:50 +0100 Subject: network prune filters for http compat and libpod api Signed-off-by: Jakub Guzik --- pkg/api/handlers/compat/networks.go | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'pkg/api/handlers/compat/networks.go') diff --git a/pkg/api/handlers/compat/networks.go b/pkg/api/handlers/compat/networks.go index dfb1d7fda..7e06cad66 100644 --- a/pkg/api/handlers/compat/networks.go +++ b/pkg/api/handlers/compat/networks.go @@ -400,10 +400,24 @@ func Disconnect(w http.ResponseWriter, r *http.Request) { // Prune removes unused networks func Prune(w http.ResponseWriter, r *http.Request) { - // TODO Filters are not implemented runtime := r.Context().Value("runtime").(*libpod.Runtime) + filters, err := filtersFromRequest(r) + if err != nil { + utils.Error(w, "Something went wrong.", http.StatusInternalServerError, errors.Wrap(err, "Decode()")) + return + } + filterMap := map[string][]string{} + for _, filter := range filters { + split := strings.SplitN(filter, "=", 2) + if len(split) > 1 { + filterMap[split[0]] = append(filterMap[split[0]], split[1]) + } + } + ic := abi.ContainerEngine{Libpod: runtime} - pruneOptions := entities.NetworkPruneOptions{} + pruneOptions := entities.NetworkPruneOptions{ + Filters: filterMap, + } pruneReports, err := ic.NetworkPrune(r.Context(), pruneOptions) if err != nil { utils.Error(w, "Something went wrong.", http.StatusInternalServerError, err) -- cgit v1.2.3-54-g00ecf