diff options
author | OpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com> | 2020-03-19 15:50:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-19 15:50:50 +0100 |
commit | 1be61789151c80d46c0c4b75a02fb23a6937df7b (patch) | |
tree | a3bb96491a3d2c2f2b76269e33af5c7919bdcc73 /pkg/api/handlers/utils/pods.go | |
parent | e87fe4dbbbc55be42d7a31f5415f55d2ff99f81b (diff) | |
parent | 15326f051d6938e5d3cdcec2f95f86ad3aa5c5fa (diff) | |
download | podman-1be61789151c80d46c0c4b75a02fb23a6937df7b.tar.gz podman-1be61789151c80d46c0c4b75a02fb23a6937df7b.tar.bz2 podman-1be61789151c80d46c0c4b75a02fb23a6937df7b.zip |
Merge pull request #5445 from sujil02/podFilter-new
Filter pods through pod list api
Diffstat (limited to 'pkg/api/handlers/utils/pods.go')
-rw-r--r-- | pkg/api/handlers/utils/pods.go | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/pkg/api/handlers/utils/pods.go b/pkg/api/handlers/utils/pods.go new file mode 100644 index 000000000..266ad9a4b --- /dev/null +++ b/pkg/api/handlers/utils/pods.go @@ -0,0 +1,45 @@ +package utils + +import ( + "fmt" + "net/http" + + "github.com/containers/libpod/cmd/podman/shared" + "github.com/containers/libpod/libpod" + "github.com/gorilla/schema" +) + +func GetPods(w http.ResponseWriter, r *http.Request) ([]*libpod.Pod, error) { + runtime := r.Context().Value("runtime").(*libpod.Runtime) + decoder := r.Context().Value("decoder").(*schema.Decoder) + + query := struct { + All bool + Filters map[string][]string `schema:"filters"` + Digests bool + }{} + + if err := decoder.Decode(&query, r.URL.Query()); err != nil { + return nil, err + } + var filters = []string{} + if _, found := r.URL.Query()["digests"]; found && query.Digests { + UnSupportedParameter("digests") + } + + if len(query.Filters) > 0 { + for k, v := range query.Filters { + for _, val := range v { + filters = append(filters, fmt.Sprintf("%s=%s", k, val)) + } + } + filterFuncs, err := shared.GenerateFilterFunction(runtime, filters) + if err != nil { + return nil, err + } + return shared.FilterAllPodsWithFilterFunc(runtime, filterFuncs...) + } + + return runtime.GetAllPods() + +} |