Add view all links for the engine

This commit is contained in:
Michael Crosby
2013-09-17 23:36:49 +00:00
parent e1952ae844
commit a07d919ea1
4 changed files with 34 additions and 18 deletions
+17 -7
View File
@@ -961,11 +961,16 @@ func getLinksJSON(srv *Server, version float64, w http.ResponseWriter, r *http.R
out := []APILink{}
name := r.FormValue("name")
rawRm := r.FormValue("rm")
rawAll := r.FormValue("all")
rm, err := getBoolParam(rawRm)
if err != nil {
return err
}
all, err := getBoolParam(rawAll)
if err != nil {
return err
}
if rm {
link := srv.runtime.links.GetById(name)
@@ -979,15 +984,20 @@ func getLinksJSON(srv *Server, version float64, w http.ResponseWriter, r *http.R
w.WriteHeader(http.StatusNotFound)
return nil
}
if name == "" {
return fmt.Errorf("Name cannot be empty for link")
var links []*Link
if all {
links = srv.runtime.links.GetAll()
} else {
if name == "" {
return fmt.Errorf("Name cannot be empty for link")
}
container := srv.runtime.Get(name)
if container == nil {
return fmt.Errorf("Container not found %s", name)
}
links = srv.runtime.links.Get(container)
}
container := srv.runtime.Get(name)
if container == nil {
return fmt.Errorf("Container not found %s", name)
}
links := srv.runtime.links.Get(container)
for _, l := range links {
out = append(out, APILink{
ID: l.ID(),
+6
View File
@@ -96,6 +96,7 @@ func (cli *DockerCli) CmdHelp(args ...string) error {
{"insert", "Insert a file in an image"},
{"inspect", "Return low-level information on a container"},
{"kill", "Kill a running container"},
{"links", "View and modify links to running containers"},
{"login", "Register or Login to the docker registry server"},
{"logs", "Fetch the logs of a container"},
{"port", "Lookup the public-facing port which is NAT-ed to PRIVATE_PORT"},
@@ -1115,6 +1116,7 @@ func (cli *DockerCli) CmdPs(args ...string) error {
func (cli *DockerCli) CmdLinks(args ...string) error {
cmd := Subcmd("links", "[OPTIONS] CONTAINER", "Get the links for a container")
flRm := cmd.Bool("rm", false, "Remove an existing link by the link ID")
flAll := cmd.Bool("a", false, "Display all registered and active links")
if err := cmd.Parse(args); err != nil {
return err
@@ -1127,6 +1129,10 @@ func (cli *DockerCli) CmdLinks(args ...string) error {
v.Set("rm", "1")
}
if *flAll {
v.Set("all", "1")
}
body, statusCode, err := cli.call("GET", "/links/json?"+v.Encode(), nil)
if err != nil {
return err
+11
View File
@@ -132,6 +132,17 @@ func (l *LinkRepository) Get(c *Container) []*Link {
return out
}
// Return all links in the repository
func (l *LinkRepository) GetAll() []*Link {
out := make([]*Link, len(l.links))
var i int
for _, link := range l.links {
out[i] = link
i++
}
return out
}
// Get a link based on the link's ID
func (l *LinkRepository) GetById(id string) *Link {
return l.links[id]
-11
View File
@@ -1,11 +0,0 @@
package docker
// Returns a new virtual container for interfacing with the host interfaces
func NewHostContainer() (*Container, error) {
return nil, nil
}
// Returns a new virutal container for interfacing with the docker daemon
func NewDockerContainer() (*Container, error) {
return nil, nil
}