Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
| ... | ... |
@@ -238,10 +238,7 @@ func getImagesViz(srv *Server, version float64, w http.ResponseWriter, r *http.R |
| 238 | 238 |
w.WriteHeader(http.StatusNotFound) |
| 239 | 239 |
return fmt.Errorf("This is now implemented in the client.")
|
| 240 | 240 |
} |
| 241 |
- |
|
| 242 |
- if err := srv.ImagesViz(w); err != nil {
|
|
| 243 |
- return err |
|
| 244 |
- } |
|
| 241 |
+ srv.Eng.ServeHTTP(w, r) |
|
| 245 | 242 |
return nil |
| 246 | 243 |
} |
| 247 | 244 |
|
| ... | ... |
@@ -16,8 +16,10 @@ import ( |
| 16 | 16 |
// as the exit status. |
| 17 | 17 |
// |
| 18 | 18 |
func (eng *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
| 19 |
- jobName := path.Base(r.URL.Path) |
|
| 20 |
- jobArgs, exists := r.URL.Query()["a"] |
|
| 19 |
+ var ( |
|
| 20 |
+ jobName = path.Base(r.URL.Path) |
|
| 21 |
+ jobArgs, exists = r.URL.Query()["a"] |
|
| 22 |
+ ) |
|
| 21 | 23 |
if !exists {
|
| 22 | 24 |
jobArgs = []string{}
|
| 23 | 25 |
} |
| ... | ... |
@@ -135,6 +135,10 @@ func jobInitApi(job *engine.Job) engine.Status {
|
| 135 | 135 |
job.Error(err) |
| 136 | 136 |
return engine.StatusErr |
| 137 | 137 |
} |
| 138 |
+ if err := job.Eng.Register("viz", srv.ImagesViz); err != nil {
|
|
| 139 |
+ job.Error(err) |
|
| 140 |
+ return engine.StatusErr |
|
| 141 |
+ } |
|
| 138 | 142 |
return engine.StatusOK |
| 139 | 143 |
} |
| 140 | 144 |
|
| ... | ... |
@@ -538,12 +542,12 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer, sf *utils. |
| 538 | 538 |
return nil |
| 539 | 539 |
} |
| 540 | 540 |
|
| 541 |
-func (srv *Server) ImagesViz(out io.Writer) error {
|
|
| 541 |
+func (srv *Server) ImagesViz(job *engine.Job) engine.Status {
|
|
| 542 | 542 |
images, _ := srv.runtime.graph.Map() |
| 543 | 543 |
if images == nil {
|
| 544 |
- return nil |
|
| 544 |
+ return engine.StatusOK |
|
| 545 | 545 |
} |
| 546 |
- out.Write([]byte("digraph docker {\n"))
|
|
| 546 |
+ job.Stdout.Write([]byte("digraph docker {\n"))
|
|
| 547 | 547 |
|
| 548 | 548 |
var ( |
| 549 | 549 |
parentImage *Image |
| ... | ... |
@@ -552,12 +556,13 @@ func (srv *Server) ImagesViz(out io.Writer) error {
|
| 552 | 552 |
for _, image := range images {
|
| 553 | 553 |
parentImage, err = image.GetParent() |
| 554 | 554 |
if err != nil {
|
| 555 |
- return fmt.Errorf("Error while getting parent image: %v", err)
|
|
| 555 |
+ job.Errorf("Error while getting parent image: %v", err)
|
|
| 556 |
+ return engine.StatusErr |
|
| 556 | 557 |
} |
| 557 | 558 |
if parentImage != nil {
|
| 558 |
- out.Write([]byte(" \"" + parentImage.ID + "\" -> \"" + image.ID + "\"\n"))
|
|
| 559 |
+ job.Stdout.Write([]byte(" \"" + parentImage.ID + "\" -> \"" + image.ID + "\"\n"))
|
|
| 559 | 560 |
} else {
|
| 560 |
- out.Write([]byte(" base -> \"" + image.ID + "\" [style=invis]\n"))
|
|
| 561 |
+ job.Stdout.Write([]byte(" base -> \"" + image.ID + "\" [style=invis]\n"))
|
|
| 561 | 562 |
} |
| 562 | 563 |
} |
| 563 | 564 |
|
| ... | ... |
@@ -570,10 +575,10 @@ func (srv *Server) ImagesViz(out io.Writer) error {
|
| 570 | 570 |
} |
| 571 | 571 |
|
| 572 | 572 |
for id, repos := range reporefs {
|
| 573 |
- out.Write([]byte(" \"" + id + "\" [label=\"" + id + "\\n" + strings.Join(repos, "\\n") + "\",shape=box,fillcolor=\"paleturquoise\",style=\"filled,rounded\"];\n"))
|
|
| 573 |
+ job.Stdout.Write([]byte(" \"" + id + "\" [label=\"" + id + "\\n" + strings.Join(repos, "\\n") + "\",shape=box,fillcolor=\"paleturquoise\",style=\"filled,rounded\"];\n"))
|
|
| 574 | 574 |
} |
| 575 |
- out.Write([]byte(" base [style=invisible]\n}\n"))
|
|
| 576 |
- return nil |
|
| 575 |
+ job.Stdout.Write([]byte(" base [style=invisible]\n}\n"))
|
|
| 576 |
+ return engine.StatusOK |
|
| 577 | 577 |
} |
| 578 | 578 |
|
| 579 | 579 |
func (srv *Server) Images(job *engine.Job) engine.Status {
|