introduce 'weave connect' to connect a running router to other peers
Getting this to work with 'wget' is just too cumbersome especially when it comes to getting the error message out. So 'curl' only.
This commit is contained in:
1 parent
acbabc4f9e
commit
6393e545ae
2 files changed
+38
-15
No files matched your search
@@ -3,13 +3,14 @@ set -e
|
|||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "Usage:"
|
echo "Usage:"
|
||||||
echo "weave launch <cidr> [-password <password>] <peer> ..."
|
echo "weave launch <cidr> [-password <password>] <peer> ..."
|
||||||
echo "weave run <cidr> <docker run args> ..."
|
echo "weave run <cidr> <docker run args> ..."
|
||||||
echo "weave start <cidr> <container_id>"
|
echo "weave start <cidr> <container_id>"
|
||||||
echo "weave attach <cidr> <container_id>"
|
echo "weave attach <cidr> <container_id>"
|
||||||
echo "weave detach <cidr> <container_id>"
|
echo "weave detach <cidr> <container_id>"
|
||||||
echo "weave expose <cidr>"
|
echo "weave expose <cidr>"
|
||||||
echo "weave hide <cidr>"
|
echo "weave hide <cidr>"
|
||||||
|
echo "weave connect <peer>"
|
||||||
echo "weave status"
|
echo "weave status"
|
||||||
echo "weave version"
|
echo "weave version"
|
||||||
echo "weave stop"
|
echo "weave stop"
|
||||||
@@ -126,6 +127,17 @@ stop_masquerading() {
|
|||||||
run_iptables -t nat -X WEAVE >/dev/null 2>&1 || true
|
run_iptables -t nat -X WEAVE >/dev/null 2>&1 || true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
docker_ip() {
|
||||||
|
if ! DOCKERIP=$(docker inspect --format='{{ .NetworkSettings.IPAddress }}' $CONTAINER_NAME 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
|
||||||
|
}
|
||||||
|
|
||||||
# the following borrows from https://github.com/jpetazzo/pipework
|
# the following borrows from https://github.com/jpetazzo/pipework
|
||||||
with_container_netns () {
|
with_container_netns () {
|
||||||
CONTAINER="$1"
|
CONTAINER="$1"
|
||||||
@@ -269,16 +281,19 @@ case "$COMMAND" in
|
|||||||
with_container_netns $CONTAINER attach $CIDR eth0
|
with_container_netns $CONTAINER attach $CIDR eth0
|
||||||
echo $CONTAINER
|
echo $CONTAINER
|
||||||
;;
|
;;
|
||||||
|
connect)
|
||||||
|
[ $# -eq 1 ] || usage
|
||||||
|
docker_ip
|
||||||
|
if command_exists curl ; then
|
||||||
|
curl -d peer=$1 $DOCKERIP:$HTTP_PORT/connect
|
||||||
|
else
|
||||||
|
echo "Cannot find curl. Install it for 'weave connect' to function." >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
;;
|
||||||
status)
|
status)
|
||||||
[ $# -eq 0 ] || usage
|
[ $# -eq 0 ] || usage
|
||||||
if ! DOCKERIP=$(docker inspect --format='{{ .NetworkSettings.IPAddress }}' $CONTAINER_NAME 2>/dev/null) ; then
|
docker_ip
|
||||||
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
|
if command_exists wget ; then
|
||||||
wget -O - -q $DOCKERIP:$HTTP_PORT/status
|
wget -O - -q $DOCKERIP:$HTTP_PORT/status
|
||||||
elif command_exists curl ; then
|
elif command_exists curl ; then
|
||||||
|
|||||||
@@ -141,6 +141,14 @@ func handleHttp(router *weave.Router) {
|
|||||||
http.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) {
|
http.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) {
|
||||||
io.WriteString(w, router.Status())
|
io.WriteString(w, router.Status())
|
||||||
})
|
})
|
||||||
|
http.HandleFunc("/connect", func (w http.ResponseWriter, r *http.Request) {
|
||||||
|
peer := r.FormValue("peer")
|
||||||
|
if addr, err := net.ResolveTCPAddr("tcp4", weave.NormalisePeerAddr(peer)); err == nil {
|
||||||
|
router.ConnectionMaker.InitiateConnection(addr.String())
|
||||||
|
} else {
|
||||||
|
http.Error(w, fmt.Sprint("invalid peer address: ", err), http.StatusBadRequest)
|
||||||
|
}
|
||||||
|
})
|
||||||
address := fmt.Sprintf(":%d", weave.HttpPort)
|
address := fmt.Sprintf(":%d", weave.HttpPort)
|
||||||
err := http.ListenAndServe(address, nil)
|
err := http.ListenAndServe(address, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in new issue
Block a user