From 741c2848f47603a7bf38891d5ee522781f5b98cc Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Fri, 16 Jan 2015 01:07:24 +0000 Subject: [PATCH] add docker images support Signed-off-by: Victor Vieux --- api/README.md | 2 -- api/api.go | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/api/README.md b/api/README.md index d0cf334fa5..8c4e8aaafe 100644 --- a/api/README.md +++ b/api/README.md @@ -8,8 +8,6 @@ Here are the main differences: ####Some endpoints are not (yet) implemented ``` -GET "/images/json" -GET "/images/json" GET "/images/get" GET "/images/{name:.*}/get" GET "/images/{name:.*}/history" diff --git a/api/api.go b/api/api.go index 4330a2160e..d861140c0f 100644 --- a/api/api.go +++ b/api/api.go @@ -13,6 +13,7 @@ import ( "strings" log "github.com/Sirupsen/logrus" + dockerfilters "github.com/docker/docker/pkg/parsers/filters" "github.com/docker/swarm/cluster" "github.com/docker/swarm/scheduler" "github.com/docker/swarm/scheduler/filter" @@ -79,6 +80,45 @@ func getVersion(c *context, w http.ResponseWriter, r *http.Request) { json.NewEncoder(w).Encode(version) } +// GET /images/json +func getImagesJSON(c *context, w http.ResponseWriter, r *http.Request) { + if err := r.ParseForm(); err != nil { + httpError(w, err.Error(), http.StatusInternalServerError) + return + } + + filters, err := dockerfilters.FromParam(r.Form.Get("filters")) + if err != nil { + httpError(w, err.Error(), http.StatusInternalServerError) + return + } + + accepteds, _ := filters["node"] + images := []*dockerclient.Image{} + + for _, node := range c.cluster.Nodes() { + if len(accepteds) != 0 { + found := false + for _, accepted := range accepteds { + if accepted == node.Name || accepted == node.ID { + found = true + break + } + } + if !found { + continue + } + } + + for _, image := range node.Images() { + images = append(images, image) + } + } + + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(images) +} + // GET /containers/ps // GET /containers/json func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) { @@ -310,7 +350,7 @@ func createRouter(c *context, enableCors bool) *mux.Router { "/events": getEvents, "/info": getInfo, "/version": getVersion, - "/images/json": notImplementedHandler, + "/images/json": getImagesJSON, "/images/viz": notImplementedHandler, "/images/search": proxyRandom, "/images/get": notImplementedHandler,