1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Deprecated of docker ps since and before options for v1.12

Deprecated note https://github.com/docker/docker/blob/master/docs/deprecated.md#docker-ps-before-and-since-options

Signed-off-by: Wen Cheng Ma <wenchma@cn.ibm.com>
This commit is contained in:
Wen Cheng Ma 2016-04-19 13:50:09 +08:00
parent 7fd53f7c71
commit 91b7157064
4 changed files with 2 additions and 120 deletions

View file

@ -26,8 +26,6 @@ func (cli *DockerCli) CmdPs(args ...string) error {
all = cmd.Bool([]string{"a", "-all"}, false, "Show all containers (default shows just running)") all = cmd.Bool([]string{"a", "-all"}, false, "Show all containers (default shows just running)")
noTrunc = cmd.Bool([]string{"-no-trunc"}, false, "Don't truncate output") noTrunc = cmd.Bool([]string{"-no-trunc"}, false, "Don't truncate output")
nLatest = cmd.Bool([]string{"l", "-latest"}, false, "Show the latest created container (includes all states)") nLatest = cmd.Bool([]string{"l", "-latest"}, false, "Show the latest created container (includes all states)")
since = cmd.String([]string{"#-since"}, "", "Show containers created since Id or Name (includes all states)")
before = cmd.String([]string{"#-before"}, "", "Only show containers created before Id or Name")
last = cmd.Int([]string{"n"}, -1, "Show n last created containers (includes all states)") last = cmd.Int([]string{"n"}, -1, "Show n last created containers (includes all states)")
format = cmd.String([]string{"-format"}, "", "Pretty-print containers using a Go template") format = cmd.String([]string{"-format"}, "", "Pretty-print containers using a Go template")
flFilter = opts.NewListOpts(nil) flFilter = opts.NewListOpts(nil)
@ -52,8 +50,6 @@ func (cli *DockerCli) CmdPs(args ...string) error {
options := types.ContainerListOptions{ options := types.ContainerListOptions{
All: *all, All: *all,
Limit: *last, Limit: *last,
Since: *since,
Before: *before,
Size: *size, Size: *size,
Filter: psFilterArgs, Filter: psFilterArgs,
} }

View file

@ -174,8 +174,6 @@ func (daemon *Daemon) foldFilter(config *types.ContainerListOptions) (*listConte
} }
var beforeContFilter, sinceContFilter *container.Container var beforeContFilter, sinceContFilter *container.Container
// FIXME remove this for 1.12 as --since and --before are deprecated
var beforeContainer, sinceContainer *container.Container
err = psFilters.WalkValues("before", func(value string) error { err = psFilters.WalkValues("before", func(value string) error {
beforeContFilter, err = daemon.GetContainer(value) beforeContFilter, err = daemon.GetContainer(value)
@ -213,29 +211,11 @@ func (daemon *Daemon) foldFilter(config *types.ContainerListOptions) (*listConte
}) })
} }
// FIXME remove this for 1.12 as --since and --before are deprecated
if config.Before != "" {
beforeContainer, err = daemon.GetContainer(config.Before)
if err != nil {
return nil, err
}
}
// FIXME remove this for 1.12 as --since and --before are deprecated
if config.Since != "" {
sinceContainer, err = daemon.GetContainer(config.Since)
if err != nil {
return nil, err
}
}
return &listContext{ return &listContext{
filters: psFilters, filters: psFilters,
ancestorFilter: ancestorFilter, ancestorFilter: ancestorFilter,
images: imagesFilter, images: imagesFilter,
exitAllowed: filtExited, exitAllowed: filtExited,
beforeContainer: beforeContainer,
sinceContainer: sinceContainer,
beforeFilter: beforeContFilter, beforeFilter: beforeContFilter,
sinceFilter: sinceContFilter, sinceFilter: sinceContFilter,
ContainerListOptions: config, ContainerListOptions: config,
@ -263,8 +243,7 @@ func includeContainerInList(container *container.Container, ctx *listContext) it
} }
// Do not include container if it's stopped and we're not filters // Do not include container if it's stopped and we're not filters
// FIXME remove the ctx.beforContainer and ctx.sinceContainer part of the condition for 1.12 as --since and --before are deprecated if !container.Running && !ctx.All && ctx.Limit <= 0 {
if !container.Running && !ctx.All && ctx.Limit <= 0 && ctx.beforeContainer == nil && ctx.sinceContainer == nil {
return excludeContainer return excludeContainer
} }
@ -288,21 +267,6 @@ func includeContainerInList(container *container.Container, ctx *listContext) it
return excludeContainer return excludeContainer
} }
// FIXME remove this for 1.12 as --since and --before are deprecated
if ctx.beforeContainer != nil {
if container.ID == ctx.beforeContainer.ID {
ctx.beforeContainer = nil
}
return excludeContainer
}
// FIXME remove this for 1.12 as --since and --before are deprecated
if ctx.sinceContainer != nil {
if container.ID == ctx.sinceContainer.ID {
return stopIteration
}
}
// Stop iteration when the index is over the limit // Stop iteration when the index is over the limit
if ctx.Limit > 0 && ctx.idx == ctx.Limit { if ctx.Limit > 0 && ctx.idx == ctx.Limit {
return stopIteration return stopIteration

View file

@ -48,7 +48,7 @@ defining it at container creation (`POST /containers/create`).
**Deprecated In Release: [v1.10.0](https://github.com/docker/docker/releases/tag/v1.10.0)** **Deprecated In Release: [v1.10.0](https://github.com/docker/docker/releases/tag/v1.10.0)**
**Target For Removal In Release: v1.12** **Removed In Release: v1.12**
The `docker ps --before` and `docker ps --since` options are deprecated. The `docker ps --before` and `docker ps --since` options are deprecated.
Use `docker ps --filter=before=...` and `docker ps --filter=since=...` instead. Use `docker ps --filter=before=...` and `docker ps --filter=since=...` instead.

View file

@ -117,86 +117,8 @@ func (s *DockerSuite) TestPsListContainersBase(c *check.C) {
} }
// FIXME remove this for 1.12 as --since and --before are deprecated
func (s *DockerSuite) TestPsListContainersDeprecatedSinceAndBefore(c *check.C) {
out, _ := runSleepingContainer(c, "-d")
firstID := strings.TrimSpace(out)
out, _ = runSleepingContainer(c, "-d")
secondID := strings.TrimSpace(out)
// not long running
out, _ = dockerCmd(c, "run", "-d", "busybox", "true")
thirdID := strings.TrimSpace(out)
out, _ = runSleepingContainer(c, "-d")
fourthID := strings.TrimSpace(out)
// make sure the second is running
c.Assert(waitRun(secondID), checker.IsNil)
// make sure third one is not running
dockerCmd(c, "wait", thirdID)
// make sure the forth is running
c.Assert(waitRun(fourthID), checker.IsNil)
// since
out, _ = dockerCmd(c, "ps", "--since="+firstID, "-a")
expected := []string{fourthID, thirdID, secondID}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE & ALL: Container list is not in the correct order: %v \n%s", expected, out))
out, _ = dockerCmd(c, "ps", "--since="+firstID)
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE: Container list is not in the correct order: %v \n%s", expected, out))
// before
out, _ = dockerCmd(c, "ps", "--before="+thirdID, "-a")
expected = []string{secondID, firstID}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE & ALL: Container list is not in the correct order: %v \n%s", expected, out))
out, _ = dockerCmd(c, "ps", "--before="+thirdID)
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE: Container list is not in the correct order: %v \n%s", expected, out))
// since & before
out, _ = dockerCmd(c, "ps", "--since="+firstID, "--before="+fourthID, "-a")
expected = []string{thirdID, secondID}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, BEFORE & ALL: Container list is not in the correct order: %v \n%s", expected, out))
out, _ = dockerCmd(c, "ps", "--since="+firstID, "--before="+fourthID)
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, BEFORE: Container list is not in the correct order: %v \n%s", expected, out))
// since & limit
out, _ = dockerCmd(c, "ps", "--since="+firstID, "-n=2", "-a")
expected = []string{fourthID, thirdID}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, LIMIT & ALL: Container list is not in the correct order: %v \n%s", expected, out))
out, _ = dockerCmd(c, "ps", "--since="+firstID, "-n=2")
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, LIMIT: Container list is not in the correct order: %v \n%s", expected, out))
// before & limit
out, _ = dockerCmd(c, "ps", "--before="+fourthID, "-n=1", "-a")
expected = []string{thirdID}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE, LIMIT & ALL: Container list is not in the correct order: %v \n%s", expected, out))
out, _ = dockerCmd(c, "ps", "--before="+fourthID, "-n=1")
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("BEFORE, LIMIT: Container list is not in the correct order: %v \n%s", expected, out))
// since & before & limit
out, _ = dockerCmd(c, "ps", "--since="+firstID, "--before="+fourthID, "-n=1", "-a")
expected = []string{thirdID}
c.Assert(assertContainerList(out, expected), checker.Equals, true, check.Commentf("SINCE, BEFORE, LIMIT & ALL: Container list is not in the correct order: %v \n%s", expected, out))
}
func assertContainerList(out string, expected []string) bool { func assertContainerList(out string, expected []string) bool {
lines := strings.Split(strings.Trim(out, "\n "), "\n") lines := strings.Split(strings.Trim(out, "\n "), "\n")
// FIXME remove this for 1.12 as --since and --before are deprecated
// This is here to remove potential Warning: lines (printed out with deprecated flags)
for i := 0; i < 2; i++ {
if strings.Contains(lines[0], "Warning:") {
lines = lines[1:]
}
}
if len(lines)-1 != len(expected) { if len(lines)-1 != len(expected) {
return false return false