From dce73559b76847fb50b05ad2d5a6372ac7579b99 Mon Sep 17 00:00:00 2001 From: Michael Bridgen Date: Mon, 17 Nov 2014 15:58:11 +0000 Subject: [PATCH] Differentiate between failure cases in http_call .. otherwise, no networking can look like no running container. --- weave | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/weave b/weave index b00eadcc..b1b01072 100755 --- a/weave +++ b/weave @@ -270,19 +270,28 @@ detach() { # Call url $4 on container $2 at port $3 with http verb $1 http_call() { http_verb="$1" - if ! DOCKERIP=$(docker inspect --format='{{ .NetworkSettings.IPAddress }}' $2 2>/dev/null) ; then - echo "$2 is not running." >&2 - exit 1 - fi - if [ -z "$DOCKERIP" ] ; then - echo "$2 is not running." >&2 + if ! status=$(docker inspect --format='{{ .State.Running }} {{ .NetworkSettings.IPAddress }}' $2 2>/dev/null); then + echo "$2 is not a container; have you launched it?" >&2 exit 1 fi + case "$status" in + "true ") + echo "$2 has no IP address; is Docker networking running?" >&2 + exit 1 + ;; + true*) + ip=$(echo $status | sed -e 's/true //') + ;; + *) + echo "$2 is not running." >&2 + exit 1 + ;; + esac port="$3" url="$4" shift 4 if command_exists curl ; then - curl -s -X $http_verb "$@" http://$DOCKERIP:$port$url + curl -s -X $http_verb "$@" http://$ip:$port$url else echo "Cannot find curl, which is required for this operation." >&2 exit 1