#!/bin/bash set -e IFACE=$1 # vm. 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 LOOPBACKIP=$(hostname -i) 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}