mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Move "images" to graph/list.go
Signed-off-by: Solomon Hykes <solomon@docker.com>
This commit is contained in:
parent
55235e121e
commit
51dd68d659
4 changed files with 104 additions and 94 deletions
103
graph/list.go
Normal file
103
graph/list.go
Normal file
|
@ -0,0 +1,103 @@
|
|||
package graph
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/engine"
|
||||
"github.com/docker/docker/image"
|
||||
"github.com/docker/docker/pkg/parsers/filters"
|
||||
)
|
||||
|
||||
func (s *TagStore) CmdImages(job *engine.Job) engine.Status {
|
||||
var (
|
||||
allImages map[string]*image.Image
|
||||
err error
|
||||
filt_tagged = true
|
||||
)
|
||||
|
||||
imageFilters, err := filters.FromParam(job.Getenv("filters"))
|
||||
if err != nil {
|
||||
return job.Error(err)
|
||||
}
|
||||
if i, ok := imageFilters["dangling"]; ok {
|
||||
for _, value := range i {
|
||||
if strings.ToLower(value) == "true" {
|
||||
filt_tagged = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if job.GetenvBool("all") && filt_tagged {
|
||||
allImages, err = s.graph.Map()
|
||||
} else {
|
||||
allImages, err = s.graph.Heads()
|
||||
}
|
||||
if err != nil {
|
||||
return job.Error(err)
|
||||
}
|
||||
lookup := make(map[string]*engine.Env)
|
||||
s.Lock()
|
||||
for name, repository := range s.Repositories {
|
||||
if job.Getenv("filter") != "" {
|
||||
if match, _ := path.Match(job.Getenv("filter"), name); !match {
|
||||
continue
|
||||
}
|
||||
}
|
||||
for tag, id := range repository {
|
||||
image, err := s.graph.Get(id)
|
||||
if err != nil {
|
||||
log.Printf("Warning: couldn't load %s from %s/%s: %s", id, name, tag, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if out, exists := lookup[id]; exists {
|
||||
if filt_tagged {
|
||||
out.SetList("RepoTags", append(out.GetList("RepoTags"), fmt.Sprintf("%s:%s", name, tag)))
|
||||
}
|
||||
} else {
|
||||
// get the boolean list for if only the untagged images are requested
|
||||
delete(allImages, id)
|
||||
if filt_tagged {
|
||||
out := &engine.Env{}
|
||||
out.Set("ParentId", image.Parent)
|
||||
out.SetList("RepoTags", []string{fmt.Sprintf("%s:%s", name, tag)})
|
||||
out.Set("Id", image.ID)
|
||||
out.SetInt64("Created", image.Created.Unix())
|
||||
out.SetInt64("Size", image.Size)
|
||||
out.SetInt64("VirtualSize", image.GetParentsSize(0)+image.Size)
|
||||
lookup[id] = out
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
s.Unlock()
|
||||
|
||||
outs := engine.NewTable("Created", len(lookup))
|
||||
for _, value := range lookup {
|
||||
outs.Add(value)
|
||||
}
|
||||
|
||||
// Display images which aren't part of a repository/tag
|
||||
if job.Getenv("filter") == "" {
|
||||
for _, image := range allImages {
|
||||
out := &engine.Env{}
|
||||
out.Set("ParentId", image.Parent)
|
||||
out.SetList("RepoTags", []string{"<none>:<none>"})
|
||||
out.Set("Id", image.ID)
|
||||
out.SetInt64("Created", image.Created.Unix())
|
||||
out.SetInt64("Size", image.Size)
|
||||
out.SetInt64("VirtualSize", image.GetParentsSize(0)+image.Size)
|
||||
outs.Add(out)
|
||||
}
|
||||
}
|
||||
|
||||
outs.ReverseSort()
|
||||
if _, err := outs.WriteListTo(job.Stdout); err != nil {
|
||||
return job.Error(err)
|
||||
}
|
||||
return engine.StatusOK
|
||||
}
|
|
@ -17,6 +17,7 @@ func (s *TagStore) Install(eng *engine.Engine) error {
|
|||
eng.Register("image_tarlayer", s.CmdTarLayer)
|
||||
eng.Register("image_export", s.CmdImageExport)
|
||||
eng.Register("history", s.CmdHistory)
|
||||
eng.Register("images", s.CmdImages)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
|
@ -25,7 +24,6 @@ import (
|
|||
"github.com/docker/docker/graph"
|
||||
"github.com/docker/docker/image"
|
||||
"github.com/docker/docker/pkg/parsers"
|
||||
"github.com/docker/docker/pkg/parsers/filters"
|
||||
"github.com/docker/docker/registry"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
@ -244,97 +242,6 @@ func (srv *Server) ImagesViz(job *engine.Job) engine.Status {
|
|||
return engine.StatusOK
|
||||
}
|
||||
|
||||
func (srv *Server) Images(job *engine.Job) engine.Status {
|
||||
var (
|
||||
allImages map[string]*image.Image
|
||||
err error
|
||||
filt_tagged = true
|
||||
)
|
||||
|
||||
imageFilters, err := filters.FromParam(job.Getenv("filters"))
|
||||
if err != nil {
|
||||
return job.Error(err)
|
||||
}
|
||||
if i, ok := imageFilters["dangling"]; ok {
|
||||
for _, value := range i {
|
||||
if strings.ToLower(value) == "true" {
|
||||
filt_tagged = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if job.GetenvBool("all") && filt_tagged {
|
||||
allImages, err = srv.daemon.Graph().Map()
|
||||
} else {
|
||||
allImages, err = srv.daemon.Graph().Heads()
|
||||
}
|
||||
if err != nil {
|
||||
return job.Error(err)
|
||||
}
|
||||
lookup := make(map[string]*engine.Env)
|
||||
srv.daemon.Repositories().Lock()
|
||||
for name, repository := range srv.daemon.Repositories().Repositories {
|
||||
if job.Getenv("filter") != "" {
|
||||
if match, _ := path.Match(job.Getenv("filter"), name); !match {
|
||||
continue
|
||||
}
|
||||
}
|
||||
for tag, id := range repository {
|
||||
image, err := srv.daemon.Graph().Get(id)
|
||||
if err != nil {
|
||||
log.Printf("Warning: couldn't load %s from %s/%s: %s", id, name, tag, err)
|
||||
continue
|
||||
}
|
||||
|
||||
if out, exists := lookup[id]; exists {
|
||||
if filt_tagged {
|
||||
out.SetList("RepoTags", append(out.GetList("RepoTags"), fmt.Sprintf("%s:%s", name, tag)))
|
||||
}
|
||||
} else {
|
||||
// get the boolean list for if only the untagged images are requested
|
||||
delete(allImages, id)
|
||||
if filt_tagged {
|
||||
out := &engine.Env{}
|
||||
out.Set("ParentId", image.Parent)
|
||||
out.SetList("RepoTags", []string{fmt.Sprintf("%s:%s", name, tag)})
|
||||
out.Set("Id", image.ID)
|
||||
out.SetInt64("Created", image.Created.Unix())
|
||||
out.SetInt64("Size", image.Size)
|
||||
out.SetInt64("VirtualSize", image.GetParentsSize(0)+image.Size)
|
||||
lookup[id] = out
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
srv.daemon.Repositories().Unlock()
|
||||
|
||||
outs := engine.NewTable("Created", len(lookup))
|
||||
for _, value := range lookup {
|
||||
outs.Add(value)
|
||||
}
|
||||
|
||||
// Display images which aren't part of a repository/tag
|
||||
if job.Getenv("filter") == "" {
|
||||
for _, image := range allImages {
|
||||
out := &engine.Env{}
|
||||
out.Set("ParentId", image.Parent)
|
||||
out.SetList("RepoTags", []string{"<none>:<none>"})
|
||||
out.Set("Id", image.ID)
|
||||
out.SetInt64("Created", image.Created.Unix())
|
||||
out.SetInt64("Size", image.Size)
|
||||
out.SetInt64("VirtualSize", image.GetParentsSize(0)+image.Size)
|
||||
outs.Add(out)
|
||||
}
|
||||
}
|
||||
|
||||
outs.ReverseSort()
|
||||
if _, err := outs.WriteListTo(job.Stdout); err != nil {
|
||||
return job.Error(err)
|
||||
}
|
||||
return engine.StatusOK
|
||||
}
|
||||
|
||||
func (srv *Server) ImageTag(job *engine.Job) engine.Status {
|
||||
if len(job.Args) != 2 && len(job.Args) != 3 {
|
||||
return job.Errorf("Usage: %s IMAGE REPOSITORY [TAG]\n", job.Name)
|
||||
|
|
|
@ -88,7 +88,6 @@ func InitServer(job *engine.Job) engine.Status {
|
|||
for name, handler := range map[string]engine.Handler{
|
||||
"tag": srv.ImageTag, // FIXME merge with "image_tag"
|
||||
"info": srv.DockerInfo,
|
||||
"images": srv.Images,
|
||||
"viz": srv.ImagesViz,
|
||||
"log": srv.Log,
|
||||
"load": srv.ImageLoad,
|
||||
|
|
Loading…
Reference in a new issue