From 86c96da8d082866fe96cd8345fc80197efae1009 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Fri, 4 Oct 2013 13:21:28 -0700 Subject: [PATCH] Allow trun ids with links Only now full ids with docker ls -a --- api.go | 14 +++++++++++++- commands.go | 8 +++++++- runtime.go | 13 +++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/api.go b/api.go index e69e3c75a..be10b5567 100644 --- a/api.go +++ b/api.go @@ -1015,11 +1015,22 @@ func makeHttpHandler(srv *Server, logging bool, localMethod string, localRoute s } func getContainersLinks(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error { + if err := parseForm(r); err != nil { + return err + } + runtime := srv.runtime + all, err := getBoolParam(r.Form.Get("all")) + if err != nil { + return err + } out := []APILink{} - err := runtime.containerGraph.Walk("/", func(p string, e *gograph.Entity) error { + err = runtime.containerGraph.Walk("/", func(p string, e *gograph.Entity) error { if container := runtime.Get(e.ID()); container != nil { + if !all && strings.Contains(p, container.ID) { + return nil + } out = append(out, APILink{ Path: p, ContainerID: container.ID, @@ -1028,6 +1039,7 @@ func getContainersLinks(srv *Server, version float64, w http.ResponseWriter, r * } return nil }, -1) + if err != nil { return err } diff --git a/commands.go b/commands.go index e7563000e..f69414ba4 100644 --- a/commands.go +++ b/commands.go @@ -1131,11 +1131,17 @@ func (cli *DockerCli) CmdPs(args ...string) error { func (cli *DockerCli) CmdLs(args ...string) error { cmd := Subcmd("ls", "", "List links for containers") + flAll := cmd.Bool("a", false, "Show all links") + if err := cmd.Parse(args); err != nil { return nil } + v := url.Values{} + if *flAll { + v.Set("all", "1") + } - body, _, err := cli.call("GET", "/containers/links", nil) + body, _, err := cli.call("GET", "/containers/links?"+v.Encode(), nil) if err != nil { return err } diff --git a/runtime.go b/runtime.go index fbc0a8f72..f894bed1a 100644 --- a/runtime.go +++ b/runtime.go @@ -473,6 +473,10 @@ func (runtime *Runtime) Commit(container *Container, repository, tag, comment, a } func (runtime *Runtime) GetByName(name string) (*Container, error) { + if id, err := runtime.idIndex.Get(name); err == nil { + name = id + } + entity := runtime.containerGraph.Get(name) if entity == nil { return nil, fmt.Errorf("Could not find entity for %s", name) @@ -503,6 +507,9 @@ func (runtime *Runtime) Children(name string) (map[string]*Container, error) { } func (runtime *Runtime) RenameLink(oldName, newName string) error { + if id, err := runtime.idIndex.Get(oldName); err == nil { + oldName = id + } entity := runtime.containerGraph.Get(oldName) if entity == nil { return fmt.Errorf("Could not find entity for %s", oldName) @@ -518,10 +525,16 @@ func (runtime *Runtime) RenameLink(oldName, newName string) error { } func (runtime *Runtime) Link(parentName, childName, alias string) error { + if id, err := runtime.idIndex.Get(parentName); err == nil { + parentName = id + } parent := runtime.containerGraph.Get(parentName) if parent == nil { return fmt.Errorf("Could not get container for %s", parentName) } + if id, err := runtime.idIndex.Get(childName); err == nil { + childName = id + } child := runtime.containerGraph.Get(childName) if child == nil { return fmt.Errorf("Could not get container for %s", childName)