removed hijack on viz

This commit is contained in:
Victor Vieux 2013-05-09 23:10:26 +02:00
parent 0862183c86
commit 0ecf5e245d
4 changed files with 64 additions and 32 deletions

42
api.go
View File

@ -115,37 +115,34 @@ func getContainersExport(srv *Server, w http.ResponseWriter, r *http.Request) ([
}
func getImages(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte, error) {
vars := mux.Vars(r)
format := vars["format"]
if err := parseForm(r); err != nil {
return nil, err
}
viz := r.Form.Get("viz") == "1"
if viz {
in, out, err := hijackServer(w)
if format == "viz" {
if err := srv.ImagesViz(w); err != nil {
return nil, err
}
return nil, nil
} else if format == "" || format == "json" {
all := r.Form.Get("all") == "1"
filter := r.Form.Get("filter")
only_ids := r.Form.Get("only_ids") == "1"
outs, err := srv.Images(all, only_ids, filter)
if err != nil {
return nil, err
}
defer in.Close()
fmt.Fprintf(out, "HTTP/1.1 200 OK\r\nContent-Type: application/vnd.docker.raw-stream\r\n\r\n")
if err := srv.ImagesViz(out); err != nil {
fmt.Fprintf(out, "Error: %s\n", err)
b, err := json.Marshal(outs)
if err != nil {
return nil, err
}
return nil, nil
return b, nil
}
all := r.Form.Get("all") == "1"
filter := r.Form.Get("filter")
only_ids := r.Form.Get("only_ids") == "1"
outs, err := srv.Images(all, only_ids, filter)
if err != nil {
return nil, err
}
b, err := json.Marshal(outs)
if err != nil {
return nil, err
}
return b, nil
return nil, fmt.Errorf("No such format: %s", format)
}
func getInfo(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte, error) {
@ -526,6 +523,7 @@ func ListenAndServe(addr string, srv *Server) error {
"/version": getVersion,
"/containers/{name:.*}/export": getContainersExport,
"/images": getImages,
"/images/{format}": getImages,
"/info": getInfo,
"/images/search": getImagesSearch,
"/images/{name:.*}/history": getImagesHistory,

View File

@ -699,9 +699,11 @@ func CmdImages(args ...string) error {
}
if *flViz {
if err := hijack("GET", "/images?viz=1", false); err != nil {
body, _, err := call("GET", "/images/viz", false)
if err != nil {
return err
}
fmt.Printf("%s", body)
} else {
v := url.Values{}
if cmd.NArg() == 1 {

View File

@ -460,15 +460,16 @@ List Images
***********
.. http:get:: /images
.. http:get:: /images/(format)
List images
List images ``format`` could be json or viz (json default)
**Example request**:
.. sourcecode:: http
GET /images?all=0&only_ids=0 HTTP/1.1
GET /images/json?all=0&only_ids=0 HTTP/1.1
**Example response**:
.. sourcecode:: http
@ -490,6 +491,38 @@ List Images
"Created":1364102658
}
]
**Example request**:
.. sourcecode:: http
GET /images/viz HTTP/1.1
**Example response**:
.. sourcecode:: http
HTTP/1.1 200 OK
Content-Type: text/plain
digraph docker {
"d82cbacda43a" -> "074be284591f"
"1496068ca813" -> "08306dc45919"
"08306dc45919" -> "0e7893146ac2"
"b750fe79269d" -> "1496068ca813"
base -> "27cf78414709" [style=invis]
"f71189fff3de" -> "9a33b36209ed"
"27cf78414709" -> "b750fe79269d"
"0e7893146ac2" -> "d6434d954665"
"d6434d954665" -> "d82cbacda43a"
base -> "e9aa60c60128" [style=invis]
"074be284591f" -> "f71189fff3de"
"b750fe79269d" [label="b750fe79269d\nbase",shape=box,fillcolor="paleturquoise",style="filled,rounded"];
"e9aa60c60128" [label="e9aa60c60128\nbase2",shape=box,fillcolor="paleturquoise",style="filled,rounded"];
"9a33b36209ed" [label="9a33b36209ed\ntest",shape=box,fillcolor="paleturquoise",style="filled,rounded"];
base [style=invisible]
}
:query only_ids: 1 or 0, Only display numeric IDs. Default 0
:query all: 1 or 0, Show all containers. Only running containers are shown by default

View File

@ -102,8 +102,7 @@ func (srv *Server) ImagesViz(out io.Writer) error {
if images == nil {
return nil
}
fmt.Fprintf(out, "digraph docker {\n")
out.Write([]byte("digraph docker {\n"))
var (
parentImage *Image
@ -115,9 +114,9 @@ func (srv *Server) ImagesViz(out io.Writer) error {
return fmt.Errorf("Error while getting parent image: %v", err)
}
if parentImage != nil {
fmt.Fprintf(out, " \"%s\" -> \"%s\"\n", parentImage.ShortId(), image.ShortId())
out.Write([]byte(" \"" + parentImage.ShortId() + "\" -> \"" + image.ShortId() + "\"\n"))
} else {
fmt.Fprintf(out, " base -> \"%s\" [style=invis]\n", image.ShortId())
out.Write([]byte(" base -> \"" + image.ShortId() + "\" [style=invis]\n"))
}
}
@ -130,9 +129,9 @@ func (srv *Server) ImagesViz(out io.Writer) error {
}
for id, repos := range reporefs {
fmt.Fprintf(out, " \"%s\" [label=\"%s\\n%s\",shape=box,fillcolor=\"paleturquoise\",style=\"filled,rounded\"];\n", id, id, strings.Join(repos, "\\n"))
out.Write([]byte(" \"" + id + "\" [label=\"" + id + "\\n" + strings.Join(repos, "\\n") + "\",shape=box,fillcolor=\"paleturquoise\",style=\"filled,rounded\"];\n"))
}
fmt.Fprintf(out, " base [style=invisible]\n}\n")
out.Write([]byte(" base [style=invisible]\n}\n"))
return nil
}