mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
move viz to a job
Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
This commit is contained in:
parent
0113c087b2
commit
7fbc315aa9
3 changed files with 19 additions and 15 deletions
5
api.go
5
api.go
|
@ -238,10 +238,7 @@ func getImagesViz(srv *Server, version float64, w http.ResponseWriter, r *http.R
|
|||
w.WriteHeader(http.StatusNotFound)
|
||||
return fmt.Errorf("This is now implemented in the client.")
|
||||
}
|
||||
|
||||
if err := srv.ImagesViz(w); err != nil {
|
||||
return err
|
||||
}
|
||||
srv.Eng.ServeHTTP(w, r)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,10 @@ import (
|
|||
// as the exit status.
|
||||
//
|
||||
func (eng *Engine) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
jobName := path.Base(r.URL.Path)
|
||||
jobArgs, exists := r.URL.Query()["a"]
|
||||
var (
|
||||
jobName = path.Base(r.URL.Path)
|
||||
jobArgs, exists = r.URL.Query()["a"]
|
||||
)
|
||||
if !exists {
|
||||
jobArgs = []string{}
|
||||
}
|
||||
|
|
23
server.go
23
server.go
|
@ -135,6 +135,10 @@ func jobInitApi(job *engine.Job) engine.Status {
|
|||
job.Error(err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
if err := job.Eng.Register("viz", srv.ImagesViz); err != nil {
|
||||
job.Error(err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
return engine.StatusOK
|
||||
}
|
||||
|
||||
|
@ -538,12 +542,12 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer, sf *utils.
|
|||
return nil
|
||||
}
|
||||
|
||||
func (srv *Server) ImagesViz(out io.Writer) error {
|
||||
func (srv *Server) ImagesViz(job *engine.Job) engine.Status {
|
||||
images, _ := srv.runtime.graph.Map()
|
||||
if images == nil {
|
||||
return nil
|
||||
return engine.StatusOK
|
||||
}
|
||||
out.Write([]byte("digraph docker {\n"))
|
||||
job.Stdout.Write([]byte("digraph docker {\n"))
|
||||
|
||||
var (
|
||||
parentImage *Image
|
||||
|
@ -552,12 +556,13 @@ func (srv *Server) ImagesViz(out io.Writer) error {
|
|||
for _, image := range images {
|
||||
parentImage, err = image.GetParent()
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error while getting parent image: %v", err)
|
||||
job.Errorf("Error while getting parent image: %v", err)
|
||||
return engine.StatusErr
|
||||
}
|
||||
if parentImage != nil {
|
||||
out.Write([]byte(" \"" + parentImage.ID + "\" -> \"" + image.ID + "\"\n"))
|
||||
job.Stdout.Write([]byte(" \"" + parentImage.ID + "\" -> \"" + image.ID + "\"\n"))
|
||||
} else {
|
||||
out.Write([]byte(" base -> \"" + image.ID + "\" [style=invis]\n"))
|
||||
job.Stdout.Write([]byte(" base -> \"" + image.ID + "\" [style=invis]\n"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -570,10 +575,10 @@ func (srv *Server) ImagesViz(out io.Writer) error {
|
|||
}
|
||||
|
||||
for id, repos := range reporefs {
|
||||
out.Write([]byte(" \"" + id + "\" [label=\"" + id + "\\n" + strings.Join(repos, "\\n") + "\",shape=box,fillcolor=\"paleturquoise\",style=\"filled,rounded\"];\n"))
|
||||
job.Stdout.Write([]byte(" \"" + id + "\" [label=\"" + id + "\\n" + strings.Join(repos, "\\n") + "\",shape=box,fillcolor=\"paleturquoise\",style=\"filled,rounded\"];\n"))
|
||||
}
|
||||
out.Write([]byte(" base [style=invisible]\n}\n"))
|
||||
return nil
|
||||
job.Stdout.Write([]byte(" base [style=invisible]\n}\n"))
|
||||
return engine.StatusOK
|
||||
}
|
||||
|
||||
func (srv *Server) Images(job *engine.Job) engine.Status {
|
||||
|
|
Loading…
Reference in a new issue