From f39ac0e2c24bd32ef00793fb986a3dee863679c1 Mon Sep 17 00:00:00 2001 From: Xian Chaobo Date: Wed, 27 Apr 2016 15:10:54 +0800 Subject: [PATCH] add support ps --filter volume Signed-off-by: Xian Chaobo --- api/handlers.go | 15 ++++++++++++++- test/integration/api/ps.bats | 19 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/api/handlers.go b/api/handlers.go index ba5fb90e89..c8be15320b 100644 --- a/api/handlers.go +++ b/api/handlers.go @@ -400,7 +400,20 @@ func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) { if !filters.Match("node", container.Engine.Name) { continue } - + if filters.Include("volume") { + volumeExist := fmt.Errorf("volume mounted in container") + err := filters.WalkValues("volume", func(value string) error { + for _, mount := range container.Info.Mounts { + if mount.Name == value || mount.Destination == value { + return volumeExist + } + } + return nil + }) + if err != volumeExist { + continue + } + } if len(filtExited) > 0 { shouldSkip := true for _, code := range filtExited { diff --git a/test/integration/api/ps.bats b/test/integration/api/ps.bats index 61001abb43..b604ceca53 100644 --- a/test/integration/api/ps.bats +++ b/test/integration/api/ps.bats @@ -157,3 +157,22 @@ function teardown() { [[ "${output}" == *"node-0/c1"* ]] [[ "${output}" != *"node-1/c2"* ]] } + +@test "docker ps --filter node" { + run docker --version + if [[ "${output}" == "Docker version 1.9"* || "${output}" == "Docker version 1.10"* ]]; then + skip + fi + start_docker_with_busybox 2 + swarm_manage + + docker_swarm run --name c1 -v test_volume1:/abc -d busybox:latest sleep 100 + docker_swarm run --name c2 -v test_volume2:/def -d busybox:latest sleep 100 + docker_swarm run --name c3 -v test_volume3:/ghi -d busybox:latest sleep 100 + + run docker_swarm ps --filter volume=test_volume1 --filter volume=/def + [ "$status" -eq 0 ] + [[ "${output}" == *"node-0/c1"* ]] + [[ "${output}" == *"node-1/c2"* ]] + [[ "${output}" != *"node-1/c3"* ]] +}