Merge branch '67_attach' of https://github.com/bboreham/weave into bboreham-67_attach
This commit is contained in:
commit
8fa24fd6d4
1 file changed
+20
-18
+20
-18
@@ -113,7 +113,6 @@ container_netns_preamble() {
|
|||||||
echo "Container $1 unknown to Docker." >&2
|
echo "Container $1 unknown to Docker." >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
NSPID=$DOCKERPID
|
NSPID=$DOCKERPID
|
||||||
|
|
||||||
[ ! -d /var/run/netns ] && mkdir -p /var/run/netns
|
[ ! -d /var/run/netns ] && mkdir -p /var/run/netns
|
||||||
@@ -133,20 +132,21 @@ container_netns_cleanup() {
|
|||||||
configure_container_networking() {
|
configure_container_networking() {
|
||||||
container_netns_preamble $1
|
container_netns_preamble $1
|
||||||
|
|
||||||
EXITCODE=1
|
|
||||||
|
|
||||||
# If veth name already exists then assume we set it up already;
|
# If veth name already exists then assume we set it up already;
|
||||||
# just add the IP address
|
# just add the IP address, if it's not already there
|
||||||
if ip link show $LOCAL_IFNAME >/dev/null 2>&1 ; then
|
if ip link show $LOCAL_IFNAME >/dev/null 2>&1 ; then
|
||||||
if ip netns exec $NSPID ip addr add $2 dev $CONTAINER_IFNAME ; then
|
if ! ip netns exec $NSPID ip addr list dev $CONTAINER_IFNAME | grep -qF $2 ; then
|
||||||
EXITCODE=0
|
if ! ip netns exec $NSPID ip addr add $2 dev $CONTAINER_IFNAME ; then
|
||||||
else
|
echo "Failed to attach address $2 to container $1" >&2
|
||||||
echo "Failed to attach address $2 to container $1" >&2
|
container_netns_cleanup
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
container_netns_cleanup
|
container_netns_cleanup
|
||||||
return $EXITCODE
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
EXITCODE=1
|
||||||
IP_TMPFILE=/tmp/weave_ip_output_$$
|
IP_TMPFILE=/tmp/weave_ip_output_$$
|
||||||
rm -f $IP_TMPFILE
|
rm -f $IP_TMPFILE
|
||||||
if ip link add name $LOCAL_IFNAME mtu $MTU type veth peer name $GUEST_IFNAME mtu $MTU >$IP_TMPFILE 2>&1 ; then
|
if ip link add name $LOCAL_IFNAME mtu $MTU type veth peer name $GUEST_IFNAME mtu $MTU >$IP_TMPFILE 2>&1 ; then
|
||||||
@@ -185,19 +185,21 @@ detach() {
|
|||||||
container_netns_preamble $1
|
container_netns_preamble $1
|
||||||
|
|
||||||
EXITCODE=1
|
EXITCODE=1
|
||||||
if ip netns exec $NSPID ip addr del $2 dev $CONTAINER_IFNAME ; then
|
if ip netns exec $NSPID ip addr list dev $CONTAINER_IFNAME | grep -qF $2 ; then
|
||||||
# if no inet addresses remain then delete the veth
|
if ip netns exec $NSPID ip addr del $2 dev $CONTAINER_IFNAME ; then
|
||||||
if [ -z "$(ip netns exec $NSPID ip -f inet addr list dev ethwe)" ] ; then
|
# if no inet addresses remain then delete the veth
|
||||||
if ip link del $LOCAL_IFNAME type veth ; then
|
if [ -z "$(ip netns exec $NSPID ip -f inet addr list dev ethwe)" ] ; then
|
||||||
EXITCODE=0
|
if ip link del $LOCAL_IFNAME type veth ; then
|
||||||
|
EXITCODE=0
|
||||||
|
else
|
||||||
|
echo "Failed to delete virtual ethernet device $LOCAL_IFNAME from container $1" >&2
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "Failed to delete virtual ethernet device $LOCAL_IFNAME from container $1" >&2
|
EXITCODE=0
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
EXITCODE=0
|
echo "Failed to detach address $2 from container $1" >&2
|
||||||
fi
|
fi
|
||||||
else
|
|
||||||
echo "Failed to detach address $2 from container $1" >&2
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
container_netns_cleanup
|
container_netns_cleanup
|
||||||
|
|||||||
Reference in new issue
Block a user