mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
added pagination on ps
This commit is contained in:
parent
075e1ebb0e
commit
bc3fa506e9
4 changed files with 33 additions and 6 deletions
4
api.go
4
api.go
|
@ -186,12 +186,14 @@ func getContainers(srv *Server, w http.ResponseWriter, r *http.Request) ([]byte,
|
|||
all := r.Form.Get("all") == "1"
|
||||
trunc_cmd := r.Form.Get("trunc_cmd") != "0"
|
||||
only_ids := r.Form.Get("only_ids") == "1"
|
||||
since := r.Form.Get("since")
|
||||
before := r.Form.Get("before")
|
||||
n, err := strconv.Atoi(r.Form.Get("limit"))
|
||||
if err != nil {
|
||||
n = -1
|
||||
}
|
||||
|
||||
outs := srv.Containers(all, trunc_cmd, only_ids, n)
|
||||
outs := srv.Containers(all, trunc_cmd, only_ids, n, since, before)
|
||||
b, err := json.Marshal(outs)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -766,6 +766,8 @@ func CmdPs(args ...string) error {
|
|||
all := cmd.Bool("a", false, "Show all containers. Only running containers are shown by default.")
|
||||
noTrunc := cmd.Bool("notrunc", false, "Don't truncate output")
|
||||
nLatest := cmd.Bool("l", false, "Show only the latest created container, include non-running ones.")
|
||||
since := cmd.String("sinceId", "", "Show only containers created since Id, include non-running ones.")
|
||||
before := cmd.String("beforeId", "", "Show only container created before Id, include non-running ones.")
|
||||
last := cmd.Int("n", -1, "Show n last created containers, include non-running ones.")
|
||||
|
||||
if err := cmd.Parse(args); err != nil {
|
||||
|
@ -787,6 +789,12 @@ func CmdPs(args ...string) error {
|
|||
if *last != -1 {
|
||||
v.Set("limit", strconv.Itoa(*last))
|
||||
}
|
||||
if *since != "" {
|
||||
v.Set("since", *since)
|
||||
}
|
||||
if *before != "" {
|
||||
v.Set("before", *before)
|
||||
}
|
||||
|
||||
body, _, err := call("GET", "/containers?"+v.Encode(), nil)
|
||||
if err != nil {
|
||||
|
|
|
@ -28,7 +28,7 @@ List containers
|
|||
|
||||
.. sourcecode:: http
|
||||
|
||||
GET /containers?trunc_cmd=0&all=1&only_ids=0 HTTP/1.1
|
||||
GET /containers?trunc_cmd=0&all=1&only_ids=0&before=8dfafdbc3a40 HTTP/1.1
|
||||
|
||||
**Example response**:
|
||||
|
||||
|
@ -71,6 +71,8 @@ List containers
|
|||
:query all: 1 or 0, Show all containers. Only running containers are shown by default
|
||||
:query trunc_cmd: 1 or 0, Truncate output. Output is truncated by default
|
||||
:query limit: Show ``limit`` last created containers, include non-running ones.
|
||||
:query since: Show only containers created since Id, include non-running ones.
|
||||
:query before: Show only containers created before Id, include non-running ones.
|
||||
:statuscode 200: no error
|
||||
:statuscode 500: server error
|
||||
|
||||
|
|
23
server.go
23
server.go
|
@ -235,15 +235,30 @@ func (srv *Server) ContainerChanges(name string) ([]Change, error) {
|
|||
return nil, fmt.Errorf("No such container: %s", name)
|
||||
}
|
||||
|
||||
func (srv *Server) Containers(all, trunc_cmd, only_ids bool, n int) []ApiContainers {
|
||||
func (srv *Server) Containers(all, trunc_cmd, only_ids bool, n int, since, before string) []ApiContainers {
|
||||
var outs []ApiContainers = []ApiContainers{} //produce [] when empty instead of 'null'
|
||||
for i, container := range srv.runtime.List() {
|
||||
if !container.State.Running && !all && n == -1 {
|
||||
var foundBefore bool
|
||||
var displayed int
|
||||
for _, container := range srv.runtime.List() {
|
||||
if !container.State.Running && !all && n == -1 && since == "" && before == "" {
|
||||
continue
|
||||
}
|
||||
if i == n {
|
||||
if before != "" {
|
||||
if container.ShortId() == before {
|
||||
foundBefore = true
|
||||
continue
|
||||
}
|
||||
if !foundBefore {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if displayed == n {
|
||||
break
|
||||
}
|
||||
if container.ShortId() == since {
|
||||
break
|
||||
}
|
||||
displayed += 1
|
||||
var out ApiContainers
|
||||
out.Id = container.ShortId()
|
||||
if !only_ids {
|
||||
|
|
Loading…
Add table
Reference in a new issue