Move "containers" to daemon/list.go
This is part of an effort to break apart the deprecated server/ package Docker-DCO-1.1-Signed-off-by: Solomon Hykes <solomon@docker.com> (github: shykes)
This commit is contained in:
parent
aa49632fef
commit
d037007658
3 changed files with 19 additions and 21 deletions
|
@ -161,14 +161,12 @@ func (daemon *Daemon) Install(eng *engine.Engine) error {
|
|||
if err := eng.Register("top", daemon.ContainerTop); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := eng.Register("containers", daemon.Containers); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// List returns an array of all containers registered in the daemon.
|
||||
func (daemon *Daemon) List() []*Container {
|
||||
return daemon.containers.List()
|
||||
}
|
||||
|
||||
// Get looks for a container by the specified ID or name, and returns it.
|
||||
// If the container is not found, or if an error occurs, nil is returned.
|
||||
func (daemon *Daemon) Get(name string) *Container {
|
||||
|
|
|
@ -1,20 +1,21 @@
|
|||
// DEPRECATION NOTICE. PLEASE DO NOT ADD ANYTHING TO THIS FILE.
|
||||
//
|
||||
// For additional commments see server/server.go
|
||||
//
|
||||
package server
|
||||
package daemon
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/daemon"
|
||||
"github.com/docker/docker/engine"
|
||||
"github.com/docker/docker/pkg/graphdb"
|
||||
|
||||
"github.com/docker/docker/engine"
|
||||
)
|
||||
|
||||
func (srv *Server) Containers(job *engine.Job) engine.Status {
|
||||
// List returns an array of all containers registered in the daemon.
|
||||
func (daemon *Daemon) List() []*Container {
|
||||
return daemon.containers.List()
|
||||
}
|
||||
|
||||
func (daemon *Daemon) Containers(job *engine.Job) engine.Status {
|
||||
var (
|
||||
foundBefore bool
|
||||
displayed int
|
||||
|
@ -27,28 +28,28 @@ func (srv *Server) Containers(job *engine.Job) engine.Status {
|
|||
outs := engine.NewTable("Created", 0)
|
||||
|
||||
names := map[string][]string{}
|
||||
srv.daemon.ContainerGraph().Walk("/", func(p string, e *graphdb.Entity) error {
|
||||
daemon.ContainerGraph().Walk("/", func(p string, e *graphdb.Entity) error {
|
||||
names[e.ID()] = append(names[e.ID()], p)
|
||||
return nil
|
||||
}, -1)
|
||||
|
||||
var beforeCont, sinceCont *daemon.Container
|
||||
var beforeCont, sinceCont *Container
|
||||
if before != "" {
|
||||
beforeCont = srv.daemon.Get(before)
|
||||
beforeCont = daemon.Get(before)
|
||||
if beforeCont == nil {
|
||||
return job.Error(fmt.Errorf("Could not find container with name or id %s", before))
|
||||
}
|
||||
}
|
||||
|
||||
if since != "" {
|
||||
sinceCont = srv.daemon.Get(since)
|
||||
sinceCont = daemon.Get(since)
|
||||
if sinceCont == nil {
|
||||
return job.Error(fmt.Errorf("Could not find container with name or id %s", since))
|
||||
}
|
||||
}
|
||||
|
||||
errLast := errors.New("last container")
|
||||
writeCont := func(container *daemon.Container) error {
|
||||
writeCont := func(container *Container) error {
|
||||
container.Lock()
|
||||
defer container.Unlock()
|
||||
if !container.State.IsRunning() && !all && n <= 0 && since == "" && before == "" {
|
||||
|
@ -72,7 +73,7 @@ func (srv *Server) Containers(job *engine.Job) engine.Status {
|
|||
out := &engine.Env{}
|
||||
out.Set("Id", container.ID)
|
||||
out.SetList("Names", names[container.ID])
|
||||
out.Set("Image", srv.daemon.Repositories().ImageName(container.Image))
|
||||
out.Set("Image", daemon.Repositories().ImageName(container.Image))
|
||||
if len(container.Args) > 0 {
|
||||
args := []string{}
|
||||
for _, arg := range container.Args {
|
||||
|
@ -104,7 +105,7 @@ func (srv *Server) Containers(job *engine.Job) engine.Status {
|
|||
return nil
|
||||
}
|
||||
|
||||
for _, container := range srv.daemon.List() {
|
||||
for _, container := range daemon.List() {
|
||||
if err := writeCont(container); err != nil {
|
||||
if err != errLast {
|
||||
return job.Error(err)
|
|
@ -100,7 +100,6 @@ func InitServer(job *engine.Job) engine.Status {
|
|||
"image_delete": srv.ImageDelete,
|
||||
"events": srv.Events,
|
||||
"push": srv.ImagePush,
|
||||
"containers": srv.Containers,
|
||||
} {
|
||||
if err := job.Eng.Register(name, srv.handlerWrap(handler)); err != nil {
|
||||
return job.Error(err)
|
||||
|
|
Loading…
Reference in a new issue