This commit is contained in:
Nate Jones 2013-10-08 13:41:44 +00:00
Родитель dcf0279a50
Коммит 2a5998baf1
3 изменённых файлов: 23 добавлений и 48 удалений

8
api.go
Просмотреть файл

@ -203,13 +203,6 @@ func getImagesJSON(srv *Server, version float64, w http.ResponseWriter, r *http.
}
}
func getImagesViz(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := srv.ImagesViz(w); err != nil {
return err
}
return nil
}
func getInfo(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
return writeJSON(w, http.StatusOK, srv.DockerInfo())
}
@ -1046,7 +1039,6 @@ func createRouter(srv *Server, logging bool) (*mux.Router, error) {
"/info": getInfo,
"/version": getVersion,
"/images/json": getImagesJSON,
"/images/viz": getImagesViz,
"/images/search": getImagesSearch,
"/images/{name:.*}/history": getImagesHistory,
"/images/{name:.*}/json": getImagesByName,

Просмотреть файл

@ -1067,11 +1067,31 @@ func (cli *DockerCli) CmdImages(args ...string) error {
}
if *flViz {
body, _, err := cli.call("GET", "/images/viz", false)
body, _, err := cli.call("GET", "/images/json?all=1", nil)
if err != nil {
return err
}
fmt.Fprintf(cli.out, "%s", body)
var outs []APIImages
err = json.Unmarshal(body, &outs)
if err != nil {
return err
}
fmt.Fprintf(cli.out, "digraph docker {\n")
for _, image := range outs {
if image.ParentId == "" {
fmt.Fprintf(cli.out, " base -> \"%s\" [style=invis]\n", utils.TruncateID(image.ID))
} else {
fmt.Fprintf(cli.out, " \"%s\" -> \"%s\"\n", utils.TruncateID(image.ParentId), utils.TruncateID(image.ID))
}
if image.RepoTags[0] != "<none>:<none>" {
fmt.Fprintf(cli.out, " \"%s\" [label=\"%s\\n%s\",shape=box,fillcolor=\"paleturquoise\",style=\"filled,rounded\"];\n", utils.TruncateID(image.ID), utils.TruncateID(image.ID), strings.Join(image.RepoTags, "\\n"))
}
}
fmt.Fprintf(cli.out, " base [style=invisible]\n}\n")
} else {
v := url.Values{}
if cmd.NArg() == 1 {

Просмотреть файл

@ -233,44 +233,6 @@ func (srv *Server) ImageInsert(name, url, path string, out io.Writer, sf *utils.
return img.ShortID(), nil
}
func (srv *Server) ImagesViz(out io.Writer) error {
images, _ := srv.runtime.graph.Map()
if images == nil {
return nil
}
out.Write([]byte("digraph docker {\n"))
var (
parentImage *Image
err error
)
for _, image := range images {
parentImage, err = image.GetParent()
if err != nil {
return err
}
if parentImage != nil {
out.Write([]byte(" \"" + parentImage.ShortID() + "\" -> \"" + image.ShortID() + "\"\n"))
} else {
out.Write([]byte(" base -> \"" + image.ShortID() + "\" [style=invis]\n"))
}
}
reporefs := make(map[string][]string)
for name, repository := range srv.runtime.repositories.Repositories {
for tag, id := range repository {
reporefs[utils.TruncateID(id)] = append(reporefs[utils.TruncateID(id)], fmt.Sprintf("%s:%s", name, tag))
}
}
for id, repos := range reporefs {
out.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
}
func (srv *Server) Images(all bool, filter string) ([]APIImages, error) {
var (
allImages map[string]*Image
@ -330,6 +292,7 @@ func (srv *Server) Images(all bool, filter string) ([]APIImages, error) {
for _, image := range allImages {
var out APIImages
out.ID = image.ID
out.ParentId = image.Parent
out.RepoTags = []string{"<none>:<none>"}
out.Created = image.Created.Unix()
out.Size = image.Size