Skip to content

Commit

Permalink
Merge pull request #36 from indigo-dc/fix-dhcp
Browse files Browse the repository at this point in the history
Fix DHCP problems
  • Loading branch information
dealfonso authored Jun 23, 2016
2 parents 853a097 + 5f00960 commit d6548c6
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 12 deletions.
52 changes: 44 additions & 8 deletions docker-manage-network
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ function create_device {
ip link set dev $VETH0 up
ip netns exec $NSDOCK ip link set dev $VETH1 name $DEVNAME
ip netns exec $NSDOCK ip link set dev $DEVNAME up
ip netns exec $NSDOCK sysctl net.ipv6.conf.all.disable_ipv6=1
ip netns exec $NSDOCK sysctl net.ipv6.conf.default.disable_ipv6=1
ip netns exec $NSDOCK sysctl net.ipv6.conf.lo.disable_ipv6=1

set +e
log_debug "device $DEVNAME created in container $DOCKID \
and attached to bridge $BRNAME"
Expand Down Expand Up @@ -244,18 +248,34 @@ function get_ip_dhcp {

DOCKID=$1
DEVNAME=$2
set +u
DHCP=$3
[ "$DHCP" == "" ] && DHCP=dhclient
set -u
PIDFILE=$3

NSDOCK=$(build_ns $DOCKID)
set -e
ip netns exec $NSDOCK dhclient $DEVNAME -nw
ip netns exec $NSDOCK dhclient $DEVNAME -nw -pf "$PIDFILE"
set +e
log_debug "dhcp client launched for device $DEVNAME in container $DOCKID"
}

function release_dhcp {
#
# @Syntax: get_ip_dhcp $1 $2 $3 (default=dhclient) ]
#
# This function launches a dhcp client stated in $3 (optional parameter which defaults to dhclient) for device $2 in container $1
# * NOTE: the current parameters for the dhcp client are only tested for dhclient.
#

DOCKID=$1
DEVNAME=$2
PIDFILE=$3

NSDOCK=$(build_ns $DOCKID)
set -e
ip netns exec $NSDOCK dhclient $DEVNAME -r -pf "$PIDFILE"
set +e
log_debug "dhcp client killed for device $DEVNAME in container $DOCKID"
}

function read_param {
#
# @Syntax: read_param $1 $@
Expand Down Expand Up @@ -338,7 +358,9 @@ MACADDR=
DHCP=no
CLEAN_NAMESPACES=no
GW=
DHCPPIDFILE=

RELEASEDHCP=False
CREATE=False
UPDATE=False
DELETE=False
Expand Down Expand Up @@ -384,9 +406,16 @@ while [ $# -gt 0 ]; do
exit_on_error "missing parameter for --mac"
shift;;
--ip|-i) read_param IPADDR $@
exit_on_error "missing paramter for --ip"
exit_on_error "missing parameter for --ip"
shift;;
--dhcp) DHCP=yes
read_param DHCPPIDFILE $@
exit_on_error "missing parameter for --dhcp"
shift;;
--release-dhcp) RELEASEDHCP=yes
read_param DHCPPIDFILE $@
exit_on_error "missing parameter for --release-dhcp"
shift;;
--dhcp) DHCP=yes;;
--gateway|-g) read_param GW $@
exit_on_error "missing parameter for --gateway"
shift;;
Expand Down Expand Up @@ -427,9 +456,16 @@ if is_true $CREATE; then
create_device $ID $BRIDGENAME $DEVICENAME
fi

if is_true $UPDATE; then
if is_true $RELEASEDHCP; then
UPDATE=False
release_dhcp $ID "$DEVICENAME" "$DHCPPIDFILE"
fi
fi

if is_true $CREATE || is_true $UPDATE; then
[ "$MACADDR" != "" ] && assign_mac $ID "$DEVICENAME" "$MACADDR"
[ "$DHCP" == "yes" ] && get_ip_dhcp $ID "$DEVICENAME"
[ "$DHCP" == "yes" ] && get_ip_dhcp $ID "$DEVICENAME" "$DHCPPIDFILE"
[ "$IPADDR" != "" ] && assign_ip $ID "$DEVICENAME" "$IPADDR"
[ "$GW" != "" ] && assign_gw $ID "$DEVICENAME" "$GW"
fi
Expand Down
5 changes: 2 additions & 3 deletions vmm/onedock/cancel
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ source ${DRIVER_PATH}/vmmfnc.sh

NAME=$1

log_onedock_debug $(docker stop "$NAME" && docker rm "$NAME")
ERR=$?

ONEDOCK_CONTAINER_FOLDER=${ONEDOCK_FOLDER}/${NAME}
mkdir -p "$ONEDOCK_CONTAINER_FOLDER"
ONEDOCK_CLEANUP_FILE=${ONEDOCK_CONTAINER_FOLDER}/deployment.cleanup
Expand All @@ -36,6 +33,8 @@ if [ -e "$ONEDOCK_CLEANUP_FILE" ]; then
exec_file "$ONEDOCK_CLEANUP_FILE" "Failed to cleanup container ($CLEANUP)"
fi

log_onedock_debug $(docker stop "$NAME" && docker rm "$NAME")
ERR=$?

# This is just to clean possible snapshots (maybe there are none)
DISKIMAGENAME=$(build_dock_name "$LOCAL_SERVER" "" "$NAME" "0")
Expand Down
14 changes: 13 additions & 1 deletion vmm/onedock/vmmfnc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ function setup_network {
BOOTSTRAP_FILE=$5
ONEDOCK_CONTAINER_FOLDER=$6

CONTNAME="one-$(echo "$DOMXML" | xmlstarlet sel -t -v /VM/ID)"

cat <<EOT > $NETWORKFILE
EOT
NICS="$(echo "$DOMXML" | xmlstarlet sel -t \
Expand All @@ -262,6 +264,7 @@ EOT

NICNAME=eth${NIC_ID}
NIC_STR="--create-device $NICNAME"
NIC_STR_UPDATE="--update-device $NICNAME"
[ "$BRIDGE" != "" ] && BRIDGE_STR="--bridge $BRIDGE"
[ "$MAC" != "" ] && MAC_STR="--mac $MAC"
if [ "$IP" != "" ]; then
Expand Down Expand Up @@ -315,16 +318,25 @@ EOT
fi

# If there is a missing value, let's check if we should use DHCP
USING_DHCP=False
if [ "$IP_STR" == "" -o "$GW_STR" == "" ]; then
if [ "$MAC_STR" != "" ]; then
if is_true "$ONEDOCK_DEFAULT_DHCP"; then
IP_STR="--dhcp"
USING_DHCP=True
IP_STR="--dhcp /var/run/dhclient.$CONTNAME-$NICNAME.pid"
IP_STR2="--release-dhcp /var/run/dhclient.$CONTNAME-$NICNAME.pid"
# IP_STR="--dhcp"
GW_STR=
fi
fi
fi
echo "$SUDO $DN --container-name $CONTAINERNAME \
$BRIDGE_STR $MAC_STR $IP_STR $NIC_STR $GW_STR" >> $NETWORKFILE

if [ "$USING_DHCP" == "True" ]; then
echo "$SUDO $DN --container-name $CONTAINERNAME \
$BRIDGE_STR $IP_STR2 $NIC_STR_UPDATE" >> $CLEANUP_FILE
fi
done

if [ "$ONEDOCK_OVERRIDE_DNS" != "" ]; then
Expand Down

0 comments on commit d6548c6

Please sign in to comment.