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:
parent
3a610f754f
commit
aca1270104
4 changed files with 26 additions and 75 deletions
1
api.go
1
api.go
|
@ -185,6 +185,7 @@ func getImagesJSON(srv *Server, version float64, w http.ResponseWriter, r *http.
|
|||
job.Setenv("filter", r.Form.Get("filter"))
|
||||
job.Setenv("all", r.Form.Get("all"))
|
||||
job.SetenvBool("list", version <= 1.8)
|
||||
job.SetenvBool("legacy", version <= 1.7)
|
||||
job.Stdout.Add(w)
|
||||
w.WriteHeader(http.StatusOK)
|
||||
if err := job.Run(); err != nil {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package docker
|
||||
|
||||
import "strings"
|
||||
|
||||
type (
|
||||
APIHistory struct {
|
||||
ID string `json:"Id"`
|
||||
|
@ -11,24 +9,6 @@ type (
|
|||
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 {
|
||||
Titles []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 {
|
||||
return &APIContainersOld{
|
||||
ID: api.ID,
|
||||
|
|
31
server.go
31
server.go
|
@ -601,13 +601,27 @@ func (srv *Server) Images(job *engine.Job) engine.Status {
|
|||
}
|
||||
|
||||
if out, exists := lookup[id]; exists {
|
||||
repotag := fmt.Sprintf("%s:%s", name, tag)
|
||||
out.SetList("RepoTags", append(out.GetList("RepoTags"), repotag))
|
||||
if job.GetenvBool("legacy") {
|
||||
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 {
|
||||
out := &engine.Env{}
|
||||
delete(allImages, id)
|
||||
out.Set("ParentId", image.Parent)
|
||||
out.SetList("RepoTags", []string{fmt.Sprintf("%s:%s", name, tag)})
|
||||
if job.GetenvBool("legacy") {
|
||||
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.SetInt64("Created", image.Created.Unix())
|
||||
out.SetInt64("Size", image.Size)
|
||||
|
@ -627,8 +641,13 @@ func (srv *Server) Images(job *engine.Job) engine.Status {
|
|||
if job.Getenv("filter") == "" {
|
||||
for _, image := range allImages {
|
||||
out := &engine.Env{}
|
||||
out.Set("ParentId", image.Parent)
|
||||
out.SetList("RepoTags", []string{"<none>:<none>"})
|
||||
if job.GetenvBool("legacy") {
|
||||
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.SetInt64("Created", image.Created.Unix())
|
||||
out.SetInt64("Size", image.Size)
|
||||
|
|
33
sorter.go
33
sorter.go
|
@ -2,39 +2,6 @@ package docker
|
|||
|
||||
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 {
|
||||
ports []Port
|
||||
by func(i, j Port) bool
|
||||
|
|
Loading…
Reference in a new issue