Merge branch '67_attach' of https://github.com/bboreham/weave into bboreham-67_attach

This commit is contained in:
Matthias Radestock committed 2014-09-24 11:41:28 +01:00
commit e64551c608
1 file changed
+26 -35
+26 -35
View File
@@ -118,22 +118,35 @@ container_netns_preamble() {
[ ! -d /var/run/netns ] && mkdir -p /var/run/netns
rm -f /var/run/netns/$NSPID
ln -s /proc/$NSPID/ns/net /var/run/netns/$NSPID
EXITCODE=1
LOCAL_IFNAME="v${CONTAINER_IFNAME}pl${NSPID}"
GUEST_IFNAME="v${CONTAINER_IFNAME}pg${NSPID}"
IP_TMPFILE=/tmp/weave_ip_output_$$
rm -f $IP_TMPFILE
return 0
}
container_netns_cleanup() {
container_netns_postamble() {
if [ "$EXITCODE" -ne 0 ] ; then
if ! ps -p $DOCKERPID >/dev/null 2>&1 ; then
echo "Container $1 died" >&2
else
echo "Failure during network configuration for container $1:" >&2
cat $IP_TMPFILE >&2
fi
fi
rm -f $IP_TMPFILE
rm -f /var/run/netns/$NSPID
}
# Parameters are container ID, CIDR address
configure_container_networking() {
# Attach Container-ID $1 to the weave network at CIDR address $2,
# creating a virtual ethernet device if necessary.
# Also turn off tx offload on device $3 inside the namespace.
attach() {
container_netns_preamble $1
EXITCODE=1
IP_TMPFILE=/tmp/weave_ip_output_$$
rm -f $IP_TMPFILE
# If veth name already exists then assume we set it up already;
# just add the IP address, if it's not already there
@@ -161,28 +174,16 @@ configure_container_networking() {
fi
fi
if [ "$EXITCODE" -ne 0 ] ; then
if ! ps -p $DOCKERPID >/dev/null 2>&1 ; then
echo "Container $1 died" >&2
else
echo "Failure during network configuration for container $1:" >&2
cat $IP_TMPFILE >&2
fi
fi
rm -f $IP_TMPFILE
container_netns_cleanup
container_netns_postamble $1
return $EXITCODE
}
# Parameters are container ID, CIDR address, interface-name
# Detach Container-ID $1 at CIDR address $2 from the weave network
# removing the virtual ethernet device if there are no more addresses
detach() {
container_netns_preamble $1
EXITCODE=1
IP_TMPFILE=/tmp/weave_ip_output_$$
rm -f $IP_TMPFILE
if (ip netns exec $NSPID ip addr list dev $CONTAINER_IFNAME | grep -qF $2) 2>$IP_TMPFILE ; then
if ip netns exec $NSPID ip addr del $2 dev $CONTAINER_IFNAME 2>$IP_TMPFILE ; then
# if no inet addresses remain then delete the veth
@@ -198,17 +199,7 @@ detach() {
EXITCODE=0
fi
if [ "$EXITCODE" -ne 0 ] ; then
if ! ps -p $DOCKERPID >/dev/null 2>&1 ; then
echo "Container $1 died" >&2
else
echo "Failure while detaching address $2 from container $1" >&2
cat $IP_TMPFILE >&2
fi
fi
rm -f $IP_TMPFILE
container_netns_cleanup
container_netns_postamble $1
return $EXITCODE
}
@@ -245,7 +236,7 @@ case "$COMMAND" in
# restarts.
MACADDR=`cat /sys/class/net/$BRIDGE/address`
CONTAINER=$(docker run --privileged -d --name=weave -p 6783:6783/tcp -p 6783:6783/udp $WEAVE_DOCKER_ARGS zettio/weave -name $MACADDR "$@")
configure_container_networking $CONTAINER $IPADDR eth0
attach $CONTAINER $IPADDR eth0
echo $CONTAINER
;;
status)
@@ -282,13 +273,13 @@ case "$COMMAND" in
shift 1
create_bridge
CONTAINER=$(docker run -d "$@")
configure_container_networking $CONTAINER $IPADDR $CONTAINER_IFNAME
attach $CONTAINER $IPADDR $CONTAINER_IFNAME
echo $CONTAINER
;;
attach)
[ $# -gt 1 ] || usage
create_bridge
configure_container_networking $2 $1 $CONTAINER_IFNAME
attach $2 $1 $CONTAINER_IFNAME
;;
detach)
[ $# -gt 1 ] || usage