2018-07-26 03:57:41 -05:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
IFACE=$1
|
|
|
|
# vm<vm_id>.<num>
|
|
|
|
|
|
|
|
CLUSTER=$(curl -s -H 'X-Wit-Auth: true' http://10.0.0.1:4000/get-by-iface/${IFACE} | sed 's/"//g' | awk '{print $1}')
|
|
|
|
|
|
|
|
if ! [[ $CLUSTER =~ ^[0-9]+$ ]]; then
|
|
|
|
echo "CLUSTER seems not to be valid"
|
|
|
|
exit 10
|
|
|
|
fi
|
|
|
|
|
2018-09-13 16:51:03 -05:00
|
|
|
LOOPBACKIP=$(dig a +short $HOSTNAME)
|
2018-07-26 03:57:41 -05:00
|
|
|
BRIDGE=br${CLUSTER}
|
|
|
|
VXLAN=vxlan${CLUSTER}
|
|
|
|
VNI=${CLUSTER}
|
|
|
|
|
|
|
|
ip link set up ${IFACE}
|
|
|
|
|
|
|
|
if ! ip link show dev ${VXLAN} &>/dev/null; then
|
|
|
|
ip link add ${VXLAN} type vxlan id ${VNI} dstport 4789 local ${LOOPBACKIP} nolearning
|
|
|
|
ip link set up ${VXLAN}
|
|
|
|
fi
|
|
|
|
|
|
|
|
if ! ip link show dev ${BRIDGE} &>/dev/null; then
|
|
|
|
brctl addbr ${BRIDGE}
|
|
|
|
brctl stp ${BRIDGE} off
|
|
|
|
brctl addif ${BRIDGE} ${VXLAN}
|
|
|
|
ip link set up dev ${BRIDGE}
|
|
|
|
bridge vlan del dev ${BRIDGE} vid 1 self
|
|
|
|
echo 1 >/sys/class/net/${BRIDGE}/bridge/vlan_filtering
|
|
|
|
fi
|
|
|
|
|
|
|
|
brctl addif ${BRIDGE} ${IFACE}
|