From 195d3799cc5d76820565ea18f55a0aa8a10314ca Mon Sep 17 00:00:00 2001 From: Alex Ruiz Estradera Date: Fri, 23 Sep 2016 15:49:46 +0200 Subject: [PATCH] Fix shellscript for gateway static Change-Id: I40001520f6175aa31bde51a33a7b13685d83ffcc --- manifests/gateway/static.pp | 2 +- .../gateway/create_fake_uplink_l2.sh.erb | 20 +++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifests/gateway/static.pp b/manifests/gateway/static.pp index 9d9f394..793e25b 100644 --- a/manifests/gateway/static.pp +++ b/manifests/gateway/static.pp @@ -93,7 +93,7 @@ class midonet::gateway::static ( $uplink_script = 'create_fake_uplink_l2.sh', $ensure_scripts = 'present', $hostname = $::hostname, - $masquerade = true + $masquerade = 'on' ) { # Place script and helper files before executing it diff --git a/templates/gateway/create_fake_uplink_l2.sh.erb b/templates/gateway/create_fake_uplink_l2.sh.erb index a4dd556..07ecbcd 100644 --- a/templates/gateway/create_fake_uplink_l2.sh.erb +++ b/templates/gateway/create_fake_uplink_l2.sh.erb @@ -23,14 +23,14 @@ EDGE_ROUTER=<%= @edge_router %> VETH0_IP=<%= @veth0_ip %> VETH1_IP=<%= @veth1_ip %> VETH_NETWORK=<%= @veth_network %> -HOSTNAME=<% @hostname %> -MASQUERADE_ON= <% @masquerade %> +HOSTNAME=<%= @hostname %> +MASQUERADE_ON=<%= @masquerade %> HOST_ID=$(midonet-cli -A -e host list | grep ${HOSTNAME} | awk '{ print $2 }') BINDING=$(midonet-cli -A -e host ${HOST_ID} list binding interface veth1) # Create veth pair -if [ -z "$(ip l | /bin/grep -e veth0 -e veth)"]; then +if [ -z "$(ip l | /bin/grep -e veth0 -e veth)" ]; then ip link add type veth echo "Succesfully created veth pair" fi @@ -39,18 +39,18 @@ ip link set dev veth0 up ip link set dev veth1 up # Create a bridge, set an IP address and attach veth0 -if [-z "$(ip l | /bin/grep -e uplinkbridge)"]; then +if [ -z "$(ip l | /bin/grep -e uplinkbridge)" ]; then brctl addbr uplinkbridge fi -if [-z "$(brctl show uplinkbridge | /bin/grep veth0)"]; then +if [ -z "$(brctl show | /bin/grep uplinkbridge | head -n1)" ]; then brctl addif uplinkbridge veth0 echo "ZzZ..." sleep 3 fi -IP_NETNL = $(echo ${VETH_NETWORK} | cut -d'/' -f2) -if [ -z "$(ip a | grep ${VETH0_IP})"]; then +IP_NETNL=$(echo ${VETH_NETWORK} | cut -d'/' -f2) +if [ -z "$(ip a | grep ${VETH0_IP})" ]; then ip addr add ${VETH0_IP}/$(echo ${IP_NETNL} | cut -d'/' -f2) dev uplinkbridge echo "ZzZ..." sleep 3 @@ -66,7 +66,7 @@ sleep 3 sysctl -w net.ipv4.ip_forward=1 # Route packets towards floating IP network through the bridge -if [ -z "$(ip route | /bin/grep '${FIP} via ${VETH_1}')"]; then +if [ -z "$(ip route | /bin/grep "${FIP} via ${VETH_1}")" ]; then ip route add ${FIP} via ${VETH1_IP} echo "Succesfully added route to send packets on the bridge" fi @@ -75,7 +75,7 @@ fi ROUTER_ID=$(midonet-cli -A -e router list | grep ${EDGE_ROUTER} | awk '{ print $2 }') PORT_ID=$(midonet-cli -A -e router ${ROUTER_ID} port list | grep ${VETH1_IP} | cut -f 2 -d " ") -if [ -z "$(midonet-cli -A -e router ${ROUTER_ID} route list | grep 'src 0.0.0.0/0 dst 0.0.0.0/0 port ${PORT_ID}')"]; then +if [ -z "$(midonet-cli -A -e router ${ROUTER_ID} route list | grep "src 0.0.0.0/0 dst 0.0.0.0/0 port ${PORT_ID}")"]; then midonet-cli -e router ${ROUTER_ID} add route src 0.0.0.0/0 dst 0.0.0.0/0 \ type normal port router ${ROUTER_ID} port ${PORT_ID} gw ${VETH0_IP} echo "Successfully added default route on edge router" @@ -85,7 +85,7 @@ fi #port ${PORT_ID} interface veth1 # Add masquerading to enable NATing -if [ "${MASQUERADE_ON} = true "]; then +if [ "${MASQUERADE_ON} = 'on' " ]; then iptables -t nat -I POSTROUTING -o ${NIC} -s ${FIP} -j MASQUERADE iptables -I FORWARD -s ${FIP} -j ACCEPT echo "Succesfully enabled masquerading"