36 lines
803 B
Bash
Executable File
36 lines
803 B
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
IFACE=$1
|
|
# vm<vm_id>.<num>
|
|
|
|
source /etc/libvirt/hooks/$IFACE
|
|
echo CLUSTER=$CLUSTER
|
|
|
|
if ! [[ $CLUSTER =~ ^[0-9]+$ ]]; then
|
|
echo "CLUSTER seems not to be valid"
|
|
exit 10
|
|
fi
|
|
|
|
LOOPBACKIP=$(dig a +short $HOSTNAME)
|
|
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}
|