Merge pull request #159 from rade/140_weave_connect

add `weave connect` to dynamically add peers to running router
This commit is contained in:
Michael Bridgen committed 2014-10-27 14:47:32 +00:00
commit 765bfbb49d
3 files changed
+42 -19

No files matched your search

+1 -1
View File
@@ -11,7 +11,7 @@ const (
EthernetOverhead = 14
UDPOverhead = 28 // 20 bytes for IPv4, 8 bytes for UDP
Port = 6783
StatusPort = Port + 1
HttpPort = Port + 1
DefaultPMTU = 65535
MaxUDPPacketSize = 65536
ChannelSize = 16
+32 -17
View File
@@ -3,20 +3,21 @@ set -e
usage() {
echo "Usage:"
echo "weave launch [-password <password>] <peer> ..."
echo "weave run <cidr> <docker run args> ..."
echo "weave start <cidr> <container_id>"
echo "weave attach <cidr> <container_id>"
echo "weave detach <cidr> <container_id>"
echo "weave expose <cidr>"
echo "weave hide <cidr>"
echo "weave launch [-password <password>] <peer> ..."
echo "weave connect <peer>"
echo "weave run <cidr> <docker run args> ..."
echo "weave start <cidr> <container_id>"
echo "weave attach <cidr> <container_id>"
echo "weave detach <cidr> <container_id>"
echo "weave expose <cidr>"
echo "weave hide <cidr>"
echo "weave status"
echo "weave version"
echo "weave stop"
echo "weave reset"
echo
echo "where <cidr> is of the form <ip_address>/<routing_prefix_length>, and"
echo " <peer> is of the form <ip_address_or_fqdn>[:<port>]"
echo "where <peer> is of the form <ip_address_or_fqdn>[:<port>], and"
echo " <cidr> is of the form <ip_address>/<routing_prefix_length>"
exit 1
}
@@ -133,6 +134,17 @@ destroy_bridge() {
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
with_container_netns () {
CONTAINER="$1"
@@ -285,16 +297,19 @@ case "$COMMAND" in
with_container_netns $CONTAINER launch
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)
[ $# -eq 0 ] || usage
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
docker_ip
if command_exists wget ; then
wget -O - -q $DOCKERIP:$HTTP_PORT/status
elif command_exists curl ; then
+9 -1
View File
@@ -141,7 +141,15 @@ func handleHttp(router *weave.Router) {
http.HandleFunc("/status", func(w http.ResponseWriter, r *http.Request) {
io.WriteString(w, router.Status())
})
address := fmt.Sprintf(":%d", weave.StatusPort)
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)
err := http.ListenAndServe(address, nil)
if err != nil {
log.Fatal("Unable to create http listener: ", err)