diff --git a/api/handlers.go b/api/handlers.go index 45682a61d1..95e6a340b6 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -158,7 +158,7 @@ func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) { if !filters.MatchKVList("label", container.Config.Labels) { continue } - if !filters.Match("status", container.StateString()) { + if !filters.Match("status", container.Info.State.StateString()) { continue } @@ -193,7 +193,7 @@ func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) { // Update the Status. The one we have is stale from the last `docker ps` the engine sent. // `Status()` will generate a new one - tmp.Status = container.Status() + tmp.Status = container.Info.State.String() if !container.Engine.IsHealthy() { tmp.Status = "Pending" } diff --git a/cluster/container.go b/cluster/container.go index 3c3c8d7909..ad8004f912 100644 --- a/cluster/container.go +++ b/cluster/container.go @@ -1,12 +1,6 @@ package cluster -import ( - "fmt" - "time" - - "github.com/docker/docker/pkg/units" - "github.com/samalba/dockerclient" -) +import "github.com/samalba/dockerclient" // Container is exported type Container struct { @@ -16,50 +10,3 @@ type Container struct { Info dockerclient.ContainerInfo Engine *Engine } - -// Status returns a human-readable description of the state -// Stoken from docker/docker/daemon/state.go -func (c *Container) Status() string { - s := c.Info.State - if s.Running { - if s.Paused { - return fmt.Sprintf("Up %s (Paused)", units.HumanDuration(time.Now().UTC().Sub(s.StartedAt))) - } - if s.Restarting { - return fmt.Sprintf("Restarting (%d) %s ago", s.ExitCode, units.HumanDuration(time.Now().UTC().Sub(s.FinishedAt))) - } - - return fmt.Sprintf("Up %s", units.HumanDuration(time.Now().UTC().Sub(s.StartedAt))) - } - - if s.Dead { - return "Dead" - } - - if s.FinishedAt.IsZero() { - return "" - } - - return fmt.Sprintf("Exited (%d) %s ago", s.ExitCode, units.HumanDuration(time.Now().UTC().Sub(s.FinishedAt))) -} - -// StateString returns a single string to describe state -// Stoken from docker/docker/daemon/state.go -func (c *Container) StateString() string { - s := c.Info.State - if s.Running { - if s.Paused { - return "paused" - } - if s.Restarting { - return "restarting" - } - return "running" - } - - if s.Dead { - return "dead" - } - - return "exited" -}