diff --git a/docker-manage-network b/docker-manage-network index 0b6635f..a5de14d 100755 --- a/docker-manage-network +++ b/docker-manage-network @@ -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" @@ -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 $@ @@ -338,7 +358,9 @@ MACADDR= DHCP=no CLEAN_NAMESPACES=no GW= +DHCPPIDFILE= +RELEASEDHCP=False CREATE=False UPDATE=False DELETE=False @@ -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;; @@ -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 diff --git a/vmm/onedock/cancel b/vmm/onedock/cancel index e4bd1cd..b457d08 100755 --- a/vmm/onedock/cancel +++ b/vmm/onedock/cancel @@ -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 @@ -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") diff --git a/vmm/onedock/vmmfnc.sh b/vmm/onedock/vmmfnc.sh index 1c5ba78..69e9ed1 100644 --- a/vmm/onedock/vmmfnc.sh +++ b/vmm/onedock/vmmfnc.sh @@ -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 < $NETWORKFILE EOT NICS="$(echo "$DOMXML" | xmlstarlet sel -t \ @@ -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 @@ -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