From 44b4b2dc381c3dd575c5a83a7ff05ee21a906564 Mon Sep 17 00:00:00 2001 From: Carlos A Date: Tue, 21 Jun 2016 15:55:41 +0200 Subject: [PATCH 1/4] release dhcp --- docker-manage-network | 48 +++++++++++++++++++++++++++++++++++-------- vmm/onedock/vmmfnc.sh | 14 ++++++++++++- 2 files changed, 53 insertions(+), 9 deletions(-) diff --git a/docker-manage-network b/docker-manage-network index 0b6635f..d911a4e 100755 --- a/docker-manage-network +++ b/docker-manage-network @@ -244,18 +244,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 +354,9 @@ MACADDR= DHCP=no CLEAN_NAMESPACES=no GW= +DHCPPIDFILE= +RELEASEDHCP=False CREATE=False UPDATE=False DELETE=False @@ -384,9 +402,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 +452,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/vmmfnc.sh b/vmm/onedock/vmmfnc.sh index 1c5ba78..c957dcc 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 From af418bce16faf472ce43f916f863d01235606104 Mon Sep 17 00:00:00 2001 From: Carlos A Date: Tue, 21 Jun 2016 16:06:02 +0200 Subject: [PATCH 2/4] cleaning before killing --- vmm/onedock/cancel | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) 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") From 207b5133ebb2e86485774beb14456d780d4a2c64 Mon Sep 17 00:00:00 2001 From: Carlos A Date: Thu, 23 Jun 2016 16:29:36 +0200 Subject: [PATCH 3/4] removing ipv6 --- docker-manage-network | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docker-manage-network b/docker-manage-network index d911a4e..52afabf 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" From 5f009605dd93f81c1298e8b0e9539319ee236028 Mon Sep 17 00:00:00 2001 From: Carlos A Date: Thu, 23 Jun 2016 16:40:32 +0200 Subject: [PATCH 4/4] bashating --- docker-manage-network | 2 +- vmm/onedock/vmmfnc.sh | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docker-manage-network b/docker-manage-network index 52afabf..a5de14d 100755 --- a/docker-manage-network +++ b/docker-manage-network @@ -162,7 +162,7 @@ function create_device { 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" diff --git a/vmm/onedock/vmmfnc.sh b/vmm/onedock/vmmfnc.sh index c957dcc..69e9ed1 100644 --- a/vmm/onedock/vmmfnc.sh +++ b/vmm/onedock/vmmfnc.sh @@ -248,7 +248,7 @@ function setup_network { ONEDOCK_CONTAINER_FOLDER=$6 CONTNAME="one-$(echo "$DOMXML" | xmlstarlet sel -t -v /VM/ID)" - + cat < $NETWORKFILE EOT NICS="$(echo "$DOMXML" | xmlstarlet sel -t \ @@ -333,7 +333,7 @@ EOT echo "$SUDO $DN --container-name $CONTAINERNAME \ $BRIDGE_STR $MAC_STR $IP_STR $NIC_STR $GW_STR" >> $NETWORKFILE - if [ "$USING_DHCP" == "True" ]; then + if [ "$USING_DHCP" == "True" ]; then echo "$SUDO $DN --container-name $CONTAINERNAME \ $BRIDGE_STR $IP_STR2 $NIC_STR_UPDATE" >> $CLEANUP_FILE fi