1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

add legacy compat

Docker-DCO-1.1-Signed-off-by: Victor Vieux <victor.vieux@docker.com> (github: vieux)
This commit is contained in:
Victor Vieux 2014-01-13 11:20:33 -08:00
parent 3a610f754f
commit aca1270104
4 changed files with 26 additions and 75 deletions

1
api.go
View file

@ -185,6 +185,7 @@ func getImagesJSON(srv *Server, version float64, w http.ResponseWriter, r *http.
job.Setenv("filter", r.Form.Get("filter")) job.Setenv("filter", r.Form.Get("filter"))
job.Setenv("all", r.Form.Get("all")) job.Setenv("all", r.Form.Get("all"))
job.SetenvBool("list", version <= 1.8) job.SetenvBool("list", version <= 1.8)
job.SetenvBool("legacy", version <= 1.7)
job.Stdout.Add(w) job.Stdout.Add(w)
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
if err := job.Run(); err != nil { if err := job.Run(); err != nil {

View file

@ -1,7 +1,5 @@
package docker package docker
import "strings"
type ( type (
APIHistory struct { APIHistory struct {
ID string `json:"Id"` ID string `json:"Id"`
@ -11,24 +9,6 @@ type (
Size int64 Size int64
} }
APIImages struct {
ID string `json:"Id"`
RepoTags []string `json:",omitempty"`
Created int64
Size int64
VirtualSize int64
ParentId string `json:",omitempty"`
}
APIImagesOld struct {
Repository string `json:",omitempty"`
Tag string `json:",omitempty"`
ID string `json:"Id"`
Created int64
Size int64
VirtualSize int64
}
APITop struct { APITop struct {
Titles []string Titles []string
Processes [][]string Processes [][]string
@ -101,22 +81,6 @@ type (
} }
) )
func (api APIImages) ToLegacy() []APIImagesOld {
outs := []APIImagesOld{}
for _, repotag := range api.RepoTags {
components := strings.SplitN(repotag, ":", 2)
outs = append(outs, APIImagesOld{
ID: api.ID,
Repository: components[0],
Tag: components[1],
Created: api.Created,
Size: api.Size,
VirtualSize: api.VirtualSize,
})
}
return outs
}
func (api APIContainers) ToLegacy() *APIContainersOld { func (api APIContainers) ToLegacy() *APIContainersOld {
return &APIContainersOld{ return &APIContainersOld{
ID: api.ID, ID: api.ID,

View file

@ -601,13 +601,27 @@ func (srv *Server) Images(job *engine.Job) engine.Status {
} }
if out, exists := lookup[id]; exists { if out, exists := lookup[id]; exists {
repotag := fmt.Sprintf("%s:%s", name, tag) if job.GetenvBool("legacy") {
out.SetList("RepoTags", append(out.GetList("RepoTags"), repotag)) out2 := &engine.Env{}
out2.Set("Repository", name)
out2.Set("Tag", tag)
out2.Set("ID", out.Get("ID"))
out2.SetInt64("Created", out.GetInt64("Created"))
out2.SetInt64("Size", out.GetInt64("Size"))
out2.SetInt64("VirtualSize", out.GetInt64("VirtualSize"))
} else {
out.SetList("RepoTags", append(out.GetList("RepoTags"), fmt.Sprintf("%s:%s", name, tag)))
}
} else { } else {
out := &engine.Env{} out := &engine.Env{}
delete(allImages, id) delete(allImages, id)
out.Set("ParentId", image.Parent) if job.GetenvBool("legacy") {
out.SetList("RepoTags", []string{fmt.Sprintf("%s:%s", name, tag)}) out.Set("Repository", name)
out.Set("Tag", tag)
} else {
out.Set("ParentId", image.Parent)
out.SetList("RepoTags", []string{fmt.Sprintf("%s:%s", name, tag)})
}
out.Set("ID", image.ID) out.Set("ID", image.ID)
out.SetInt64("Created", image.Created.Unix()) out.SetInt64("Created", image.Created.Unix())
out.SetInt64("Size", image.Size) out.SetInt64("Size", image.Size)
@ -627,8 +641,13 @@ func (srv *Server) Images(job *engine.Job) engine.Status {
if job.Getenv("filter") == "" { if job.Getenv("filter") == "" {
for _, image := range allImages { for _, image := range allImages {
out := &engine.Env{} out := &engine.Env{}
out.Set("ParentId", image.Parent) if job.GetenvBool("legacy") {
out.SetList("RepoTags", []string{"<none>:<none>"}) out.Set("Repository", "<none>")
out.Set("Tag", "<none>")
} else {
out.Set("ParentId", image.Parent)
out.SetList("RepoTags", []string{"<none>:<none>"})
}
out.Set("ID", image.ID) out.Set("ID", image.ID)
out.SetInt64("Created", image.Created.Unix()) out.SetInt64("Created", image.Created.Unix())
out.SetInt64("Size", image.Size) out.SetInt64("Size", image.Size)

View file

@ -2,39 +2,6 @@ package docker
import "sort" import "sort"
type imageSorter struct {
images []APIImages
by func(i1, i2 *APIImages) bool // Closure used in the Less method.
}
// Len is part of sort.Interface.
func (s *imageSorter) Len() int {
return len(s.images)
}
// Swap is part of sort.Interface.
func (s *imageSorter) Swap(i, j int) {
s.images[i], s.images[j] = s.images[j], s.images[i]
}
// Less is part of sort.Interface. It is implemented by calling the "by" closure in the sorter.
func (s *imageSorter) Less(i, j int) bool {
return s.by(&s.images[i], &s.images[j])
}
// Sort []ApiImages by most recent creation date and tag name.
func sortImagesByCreationAndTag(images []APIImages) {
creationAndTag := func(i1, i2 *APIImages) bool {
return i1.Created > i2.Created
}
sorter := &imageSorter{
images: images,
by: creationAndTag}
sort.Sort(sorter)
}
type portSorter struct { type portSorter struct {
ports []Port ports []Port
by func(i, j Port) bool by func(i, j Port) bool