From e7065eabf7c3f892ac9a778d3c832867f6a003d4 Mon Sep 17 00:00:00 2001 From: Xian Chaobo Date: Fri, 11 Mar 2016 10:31:33 +0800 Subject: [PATCH] add support ps node filter Signed-off-by: Xian Chaobo --- api/handlers.go | 3 +++ test/integration/api/ps.bats | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/api/handlers.go b/api/handlers.go index c19dbeebd4..e7f571105a 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -378,6 +378,9 @@ func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) { if !filters.Match("status", container.Info.State.StateString()) { continue } + if !filters.Match("node", container.Engine.Name) { + continue + } if len(filtExited) > 0 { shouldSkip := true diff --git a/test/integration/api/ps.bats b/test/integration/api/ps.bats index 061bfc0ab7..61001abb43 100644 --- a/test/integration/api/ps.bats +++ b/test/integration/api/ps.bats @@ -144,3 +144,16 @@ function teardown() { [[ "$output" == *"$secondID"* ]] [[ "$output" != *"$thirdID"* ]] } + +@test "docker ps --filter node" { + start_docker_with_busybox 2 + swarm_manage + + docker_swarm run --name c1 -e constraint:node==node-0 -d busybox:latest sleep 100 + docker_swarm run --name c2 -e constraint:node==node-1 -d busybox:latest sleep 100 + + run docker_swarm ps --filter node=node-0 + [ "$status" -eq 0 ] + [[ "${output}" == *"node-0/c1"* ]] + [[ "${output}" != *"node-1/c2"* ]] +}