Merge "Add more checks to gateway static!"
This commit is contained in:
commit
28c122ab6f
@ -92,6 +92,8 @@ class midonet::gateway::static (
|
||||
$scripts_dir = '/tmp',
|
||||
$uplink_script = 'create_fake_uplink_l2.sh',
|
||||
$ensure_scripts = 'present',
|
||||
$hostname = $::hostname,
|
||||
$masquerade = true
|
||||
) {
|
||||
|
||||
# Place script and helper files before executing it
|
||||
@ -102,11 +104,11 @@ class midonet::gateway::static (
|
||||
}
|
||||
|
||||
# Finally, execute the script
|
||||
exec { "/bin/bash -x ${scripts_dir}/create_fake_uplink_l2.sh 2>&1 | tee /tmp/bash.out":
|
||||
exec { 'run gateway static creation script':
|
||||
command => "/bin/bash -x ${scripts_dir}/create_fake_uplink_l2.sh 2>&1 | tee /tmp/bash.out",
|
||||
returns => ['0', '7'],
|
||||
require => [
|
||||
File['fake_uplink_script'],
|
||||
Package['python-midonetclient'],
|
||||
]
|
||||
}
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ describe 'midonet::gateway::static' do
|
||||
}
|
||||
end
|
||||
it { is_expected.to contain_file('fake_uplink_script').with_ensure('present') }
|
||||
it { is_expected.to contain_exec('/bin/bash -x /tmp/create_fake_uplink_l2.sh 2>&1 | tee /tmp/bash.out') }
|
||||
it { is_expected.to contain_exec('run gateway static creation script').with(
|
||||
'command' => '/bin/bash -x /tmp/create_fake_uplink_l2.sh 2>&1 | tee /tmp/bash.out'
|
||||
) }
|
||||
end
|
||||
end
|
||||
|
@ -23,31 +23,42 @@ EDGE_ROUTER=<%= @edge_router %>
|
||||
VETH0_IP=<%= @veth0_ip %>
|
||||
VETH1_IP=<%= @veth1_ip %>
|
||||
VETH_NETWORK=<%= @veth_network %>
|
||||
HOSTNAME=<% @hostname %>
|
||||
MASQUERADE_ON= <% @masquerade %>
|
||||
|
||||
HOSTNAME=$(hostname)
|
||||
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)
|
||||
|
||||
# If interface veth1 is bound already stop the script
|
||||
if [ -n "$(ip l | grep "veth")" ]; then
|
||||
echo "Interface veth1 is already bound to host id ${HOST_ID}" >&2
|
||||
exit 7
|
||||
# Create veth pair
|
||||
if [ -z "$(ip l | /bin/grep -e veth0 -e veth)"]; then
|
||||
ip link add type veth
|
||||
echo "Succesfully created veth pair"
|
||||
fi
|
||||
|
||||
# Create veth pair
|
||||
ip link add type veth
|
||||
ip link set dev veth0 up
|
||||
ip link set dev veth1 up
|
||||
|
||||
# Create a bridge, set an IP address and attach veth0
|
||||
brctl addbr uplinkbridge
|
||||
brctl addif uplinkbridge veth0
|
||||
echo "ZzZ..."
|
||||
sleep 3
|
||||
ip addr add ${VETH0_IP}/30 dev uplinkbridge
|
||||
echo "ZzZ..."
|
||||
sleep 3
|
||||
if [-z "$(ip l | /bin/grep -e uplinkbridge)"]; then
|
||||
brctl addbr uplinkbridge
|
||||
fi
|
||||
|
||||
if [-z "$(brctl show uplinkbridge | /bin/grep veth0)"]; 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 addr add ${VETH0_IP}/$(echo ${IP_NETNL} | cut -d'/' -f2) dev uplinkbridge
|
||||
echo "ZzZ..."
|
||||
sleep 3
|
||||
fi
|
||||
|
||||
|
||||
ip link set dev uplinkbridge up
|
||||
|
||||
echo "ZzZ..."
|
||||
sleep 3
|
||||
|
||||
@ -55,19 +66,27 @@ sleep 3
|
||||
sysctl -w net.ipv4.ip_forward=1
|
||||
|
||||
# Route packets towards floating IP network through the bridge
|
||||
ip route add ${FIP} via ${VETH1_IP}
|
||||
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
|
||||
|
||||
# Create a port on the edge router and bind it to the veth pair
|
||||
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 " ")
|
||||
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}
|
||||
|
||||
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"
|
||||
fi
|
||||
|
||||
#midonet-cli -e host ${HOST_ID} add binding port router ${ROUTER_ID} \
|
||||
#port ${PORT_ID} interface veth1
|
||||
|
||||
# Add masquerading to enable NATing
|
||||
iptables -t nat -I POSTROUTING -o ${NIC} -s ${FIP} -j MASQUERADE
|
||||
iptables -I FORWARD -s ${FIP} -j ACCEPT
|
||||
|
||||
echo "Successfully created fake uplink"
|
||||
exit 0
|
||||
if [ "${MASQUERADE_ON} = true "]; then
|
||||
iptables -t nat -I POSTROUTING -o ${NIC} -s ${FIP} -j MASQUERADE
|
||||
iptables -I FORWARD -s ${FIP} -j ACCEPT
|
||||
echo "Succesfully enabled masquerading"
|
||||
fi
|
||||
|
Loading…
x
Reference in New Issue
Block a user