| 1 |
#!/bin/sh |
| 2 |
|
| 3 |
set -e |
| 4 |
set -x |
| 5 |
|
| 6 |
# Re-add the namespace |
| 7 |
ip netns add amphora-haproxy || true |
| 8 |
|
| 9 |
# Load the system sysctl into the new namespace |
| 10 |
ip netns exec amphora-haproxy sysctl --system |
| 11 |
|
| 12 |
# Enable kernel module ip_vs for lvs function in amphora network namespace |
| 13 |
ip netns exec amphora-haproxy modprobe ip_vs |
| 14 |
|
| 15 |
# Enable ip_forward and conntrack kernel configuration |
| 16 |
ip netns exec amphora-haproxy sysctl -w net.ipv4.ip_forward=1 |
| 17 |
ip netns exec amphora-haproxy sysctl -w net.ipv4.vs.conntrack=1 |
| 18 |
ip netns exec amphora-haproxy sysctl -w net.ipv6.conf.all.forwarding=1 |
| 19 |
|
| 20 |
# Wait until /var/lib/octavia/plugged_interfaces appears |
| 21 |
TIMESTAMP_TIMEOUT=$(date -d "now + 5 min" +%s) |
| 22 |
while [ ! -f /var/lib/octavia/plugged_interfaces ] && [ $(date +%s) -lt "${TIMESTAMP_TIMEOUT}" ] ; do |
| 23 |
sleep 2 |
| 24 |
done |
| 25 |
if [ ! -f /var/lib/octavia/plugged_interfaces ] ; then |
| 26 |
exit 1 |
| 27 |
fi |
| 28 |
|
| 29 |
# We need the plugged_interfaces file sorted to join the host interfaces |
| 30 |
/usr/bin/sort -k 1 /var/lib/octavia/plugged_interfaces > /var/lib/octavia/plugged_interfaces.sorted |
| 31 |
|
| 32 |
# Assign the interfaces into the namespace with the appropriate name |
| 33 |
ip link | awk '{getline n; print $0,n}' \ |
| 34 |
| awk '{sub(":","",$2)} { for(i=1;i<=NF;i++) if ($i == "link/ether") {print $(i+1) " " $2} }' \ |
| 35 |
| sort -k 1 | join -j 1 - /var/lib/octavia/plugged_interfaces.sorted \ |
| 36 |
| awk '{system("ip link set "$2" netns amphora-haproxy name "$3"")}' |
| 37 |
|
| 38 |
# Bring up all of the namespace interfaces |
| 39 |
ip netns exec amphora-haproxy ifup -a |
| 40 |
|
| 41 |
exit 0 |