From 6483c89a2b392d2bab709c0d162a6fef4b23a0cc Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Fri, 12 Sep 2014 17:51:30 +0100 Subject: [PATCH] Factor out commands implemented via the REST interface --- weaver/weave | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/weaver/weave b/weaver/weave index 5dab5d9b..ec57494c 100755 --- a/weaver/weave +++ b/weaver/weave @@ -68,6 +68,26 @@ setup_masquerading() { add_nat_rule "POSTROUTING -s $IPADDR ! -o $BRIDGE -j MASQUERADE" } +rest_command() { + RESTCOMMAND=$1 + if ! DOCKERIP=$(docker inspect --format='{{ .NetworkSettings.IPAddress }}' weave 2>/dev/null) ; then + echo "Weave is not running." >&2 + exit 1 + fi + if [ -z "$DOCKERIP" ] ; then + echo "Weave is not running." >&2 + exit 1 + fi + if command_exists wget ; then + wget -O - -q $DOCKERIP:6784/$RESTCOMMAND + elif command_exists curl ; then + curl $DOCKERIP:6784/$RESTCOMMAND + else + echo "Cannot find wget or curl. Install one of them for 'weave $RESTCOMMAND' to function." >&2 + exit 1 + fi +} + case "$COMMAND" in launch) [ $# -gt 0 ] || usage @@ -104,22 +124,7 @@ case "$COMMAND" in IFACE=eth0 ;; status) - if ! DOCKERIP=$(docker inspect --format='{{ .NetworkSettings.IPAddress }}' weave 2>/dev/null) ; then - echo "Weave is not running." >&2 - exit 1 - fi - if [ -z "$DOCKERIP" ] ; then - echo "Weave is not running." >&2 - exit 1 - fi - if command_exists wget ; then - wget -O - -q $DOCKERIP:6784/status - elif command_exists curl ; then - curl $DOCKERIP:6784/status - else - echo "Cannot find wget or curl. Install one of them for 'weave status' to function." >&2 - exit 1 - fi + rest_command status exit 0 ;; run)