Merge pull request #147 from bboreham/138_weave_ps
Add command `weave ps`
This commit is contained in:
commit
a88bb68447
1 file changed
+24
-5
@@ -11,6 +11,7 @@ usage() {
|
||||
echo "weave detach <cidr> <container_id>"
|
||||
echo "weave expose <cidr>"
|
||||
echo "weave hide <cidr>"
|
||||
echo "weave ps"
|
||||
echo "weave status"
|
||||
echo "weave version"
|
||||
echo "weave stop"
|
||||
@@ -146,6 +147,9 @@ docker_ip() {
|
||||
}
|
||||
|
||||
# the following borrows from https://github.com/jpetazzo/pipework
|
||||
|
||||
# run args $2 $3 ... as a command in the network namespace of container $1
|
||||
# if an error is caused by container dying, swallow output from error
|
||||
with_container_netns () {
|
||||
CONTAINER="$1"
|
||||
CONTAINER_PID=$(docker inspect --format='{{ .State.Pid }}' $CONTAINER)
|
||||
@@ -183,6 +187,7 @@ with_container_netns () {
|
||||
fi
|
||||
fi
|
||||
|
||||
cat $IP_TMPFILE # no error - send the output to stdout
|
||||
rm -f $IP_TMPFILE /var/run/netns/$NETNS
|
||||
return $STATUS
|
||||
}
|
||||
@@ -258,6 +263,10 @@ detach() {
|
||||
ip link del $LOCAL_IFNAME type veth
|
||||
}
|
||||
|
||||
container_weave_addrs() {
|
||||
ip netns exec $NETNS ip addr show dev $CONTAINER_IFNAME
|
||||
}
|
||||
|
||||
case "$COMMAND" in
|
||||
launch)
|
||||
case $(docker inspect --format '{{ .State.Running }} {{ .Config.Image }}' $CONTAINER_NAME 2>/dev/null) in
|
||||
@@ -294,7 +303,7 @@ case "$COMMAND" in
|
||||
# additional parameters, such as resource limits, to docker
|
||||
# when launching the weave container.
|
||||
CONTAINER=$(docker run --privileged -d --name=$CONTAINER_NAME -p $PORT:$PORT/tcp -p $PORT:$PORT/udp $WEAVE_DOCKER_ARGS $IMAGE -name $MACADDR "$@" | tail -n 1)
|
||||
with_container_netns $CONTAINER launch
|
||||
with_container_netns $CONTAINER launch >/dev/null
|
||||
echo $CONTAINER
|
||||
;;
|
||||
connect)
|
||||
@@ -319,6 +328,16 @@ case "$COMMAND" in
|
||||
exit 1
|
||||
fi
|
||||
;;
|
||||
ps)
|
||||
[ $# -eq 0 ] || usage
|
||||
for CONTAINER_ID in $(docker ps -q) ; do
|
||||
if CONTAINER_ADDRS=$(with_container_netns $CONTAINER_ID container_weave_addrs 2>&1) ; then
|
||||
CONTAINER_MAC=$(echo "$CONTAINER_ADDRS" | grep -o 'link/ether .*' | cut -d ' ' -f 2)
|
||||
CONTAINER_IPS=$(echo "$CONTAINER_ADDRS" | grep -o 'inet .*' | cut -d ' ' -f 2)
|
||||
echo $CONTAINER_ID $CONTAINER_MAC $CONTAINER_IPS
|
||||
fi
|
||||
done
|
||||
;;
|
||||
version)
|
||||
[ $# -eq 0 ] || usage
|
||||
# Try the running container first; if no luck try the image
|
||||
@@ -337,7 +356,7 @@ case "$COMMAND" in
|
||||
shift 1
|
||||
create_bridge
|
||||
CONTAINER=$(docker run -d "$@" | tail -n 1)
|
||||
with_container_netns $CONTAINER attach $CIDR
|
||||
with_container_netns $CONTAINER attach $CIDR >/dev/null
|
||||
echo $CONTAINER
|
||||
;;
|
||||
start)
|
||||
@@ -345,19 +364,19 @@ case "$COMMAND" in
|
||||
validate_cidr $1
|
||||
create_bridge
|
||||
CONTAINER=$(docker start $2)
|
||||
with_container_netns $CONTAINER attach $1
|
||||
with_container_netns $CONTAINER attach $1 >/dev/null
|
||||
echo $CONTAINER
|
||||
;;
|
||||
attach)
|
||||
[ $# -eq 2 ] || usage
|
||||
validate_cidr $1
|
||||
create_bridge
|
||||
with_container_netns $2 attach $1
|
||||
with_container_netns $2 attach $1 >/dev/null
|
||||
;;
|
||||
detach)
|
||||
[ $# -eq 2 ] || usage
|
||||
validate_cidr $1
|
||||
with_container_netns $2 detach $1
|
||||
with_container_netns $2 detach $1 >/dev/null
|
||||
;;
|
||||
expose)
|
||||
[ $# -eq 1 ] || usage
|
||||
|
||||
Reference in new issue
Block a user