From b307b9872a14683f8090d87f7782a45a41fe55fc Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Thu, 23 Feb 2017 15:52:47 +0000 Subject: [PATCH] Fetch list of container IDs inside weaveutil, for 'weave ps' --- prog/weaveutil/addrs.go | 17 ++++++++++++++++- weave | 4 ++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/prog/weaveutil/addrs.go b/prog/weaveutil/addrs.go index e48a9aa5..152fdc4e 100644 --- a/prog/weaveutil/addrs.go +++ b/prog/weaveutil/addrs.go @@ -27,10 +27,25 @@ func containerAddrs(args []string) error { return err } + containerArgs := []string{} + for _, cid := range args[1:] { + if cid == "weave:allids" { // expand to all container IDs + all, err := client.ListContainers(docker.ListContainersOptions{All: true}) + if err != nil { + return err + } + for _, c := range all { + containerArgs = append(containerArgs, c.ID) + } + } else { + containerArgs = append(containerArgs, cid) + } + } + var containerIDs []string containers := make(map[string]*docker.Container) - for _, cid := range args[1:] { + for _, cid := range containerArgs { if cid == "weave:expose" { netDev, err := weavenet.GetBridgeNetDev(bridgeName) if err != nil { diff --git a/weave b/weave index dd12f351..26353c33 100755 --- a/weave +++ b/weave @@ -1009,7 +1009,7 @@ with_container_addresses() { } echo_addresses() { - echo $1 $3 $4 + echo $(printf "%.12s" $1) $3 $4 } echo_ips() { @@ -2246,7 +2246,7 @@ EOF show_addrs $ALL_CIDRS ;; ps) - [ $# -eq 0 ] && CONTAINERS="weave:expose $(docker ps -q)" || CONTAINERS="$@" + [ $# -eq 0 ] && CONTAINERS="weave:expose weave:allids" || CONTAINERS="$@" with_container_addresses echo_addresses $CONTAINERS ;; stop)