update code

Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
Victor Vieux 2015-12-17 20:46:39 -08:00
parent 15a91b1c73
commit be0fce961f
4 changed files with 41 additions and 26 deletions

View File

@ -14,7 +14,7 @@ import (
"strings"
"time"
dockerfilters "github.com/docker/docker/pkg/parsers/filters"
dockerfilters "github.com/docker/docker/api/types/filters"
"github.com/docker/swarm/cluster"
"github.com/docker/swarm/version"
"github.com/gorilla/mux"
@ -121,7 +121,7 @@ func getImagesJSON(c *context, w http.ResponseWriter, r *http.Request) {
}
// TODO: apply node filter in engine?
accepteds, _ := filters["node"]
accepteds := filters.Get("node")
// this struct helps grouping images
// but still keeps their Engine infos as an array.
groupImages := make(map[string]dockerclient.Image)
@ -200,7 +200,7 @@ func getNetworks(c *context, w http.ResponseWriter, r *http.Request) {
}
out := []*dockerclient.NetworkResource{}
networks := c.cluster.Networks().Filter(filters["name"], filters["id"])
networks := c.cluster.Networks().Filter(filters.Get("name"), filters.Get("id"))
for _, network := range networks {
tmp := (*network).NetworkResource
if tmp.Scope == "local" {
@ -251,21 +251,17 @@ func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) {
return
}
filtExited := []int{}
if i, ok := filters["exited"]; ok {
for _, value := range i {
code, err := strconv.Atoi(value)
if err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
return
}
filtExited = append(filtExited, code)
for _, value := range filters.Get("exited") {
code, err := strconv.Atoi(value)
if err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
return
}
filtExited = append(filtExited, code)
}
if i, ok := filters["status"]; ok {
for _, value := range i {
if value == "exited" {
all = true
}
for _, value := range filters.Get("status") {
if value == "exited" {
all = true
}
}
@ -287,7 +283,7 @@ func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) {
if !filters.Match("name", strings.TrimPrefix(container.Names[0], "/")) {
continue
}
} else if len(filters["name"]) > 0 {
} else if len(filters.Get("name")) > 0 {
continue
}
if !filters.Match("id", container.Id) {

View File

@ -3,8 +3,7 @@ package cluster
import (
"strings"
"github.com/docker/docker/pkg/parsers"
dockerfilters "github.com/docker/docker/pkg/parsers/filters"
dockerfilters "github.com/docker/docker/api/types/filters"
"github.com/samalba/dockerclient"
)
@ -15,6 +14,26 @@ type Image struct {
Engine *Engine
}
// ParseRepositoryTag gets a repos name and returns the right reposName + tag|digest
// The tag can be confusing because of a port in a repository name.
// Ex: localhost.localdomain:5000/samalba/hipache:latest
// Digest ex: localhost:5000/foo/bar@sha256:bc8813ea7b3603864987522f02a76101c17ad122e1c46d790efc0fca78ca7bfb
func ParseRepositoryTag(repos string) (string, string) {
n := strings.Index(repos, "@")
if n >= 0 {
parts := strings.Split(repos, "@")
return parts[0], parts[1]
}
n = strings.LastIndex(repos, ":")
if n < 0 {
return repos, ""
}
if tag := repos[n+1:]; !strings.Contains(tag, "/") {
return repos[:n], tag
}
return repos, ""
}
// Match is exported
func (image *Image) Match(IDOrName string, matchTag bool) bool {
size := len(IDOrName)
@ -24,11 +43,11 @@ func (image *Image) Match(IDOrName string, matchTag bool) bool {
return true
}
repoName, tag := parsers.ParseRepositoryTag(IDOrName)
repoName, tag := ParseRepositoryTag(IDOrName)
// match repotag
for _, imageRepoTag := range image.RepoTags {
imageRepoName, imageTag := parsers.ParseRepositoryTag(imageRepoTag)
imageRepoName, imageTag := ParseRepositoryTag(imageRepoTag)
if matchTag == false && imageRepoName == repoName {
return true
@ -40,7 +59,7 @@ func (image *Image) Match(IDOrName string, matchTag bool) bool {
// match repodigests
for _, imageDigest := range image.RepoDigests {
imageRepoName, imageDigest := parsers.ParseRepositoryTag(imageDigest)
imageRepoName, imageDigest := ParseRepositoryTag(imageDigest)
if matchTag == false && imageRepoName == repoName {
return true
@ -74,7 +93,7 @@ func (images Images) Filter(opts ImageFilterOptions) Images {
}
includeFilter := func(image *Image) bool {
if opts.Filters == nil {
if opts.Filters.Len() == 0 {
return true
}
return opts.Filters.MatchKVList("label", image.Labels)
@ -85,7 +104,7 @@ func (images Images) Filter(opts ImageFilterOptions) Images {
return true
}
for _, repoTag := range image.RepoTags {
repoName, _ := parsers.ParseRepositoryTag(repoTag)
repoName, _ := ParseRepositoryTag(repoTag)
if repoTag == opts.NameFilter || repoName == opts.NameFilter {
return true
}

View File

@ -4,7 +4,7 @@ import (
"fmt"
"strings"
"github.com/docker/docker/pkg/units"
"github.com/docker/go-units"
"github.com/mesos/mesos-go/mesosproto"
)

View File

@ -12,7 +12,7 @@ import (
log "github.com/Sirupsen/logrus"
"github.com/docker/docker/pkg/stringid"
"github.com/docker/docker/pkg/units"
"github.com/docker/go-units"
"github.com/docker/swarm/cluster"
"github.com/docker/swarm/discovery"
"github.com/docker/swarm/scheduler"