wit-network-config/files/qemu-ifup

36 lines
803 B
Plaintext
Raw Normal View History

2018-07-26 03:57:41 -05:00
#!/bin/bash
set -e
IFACE=$1
# vm<vm_id>.<num>
source /etc/libvirt/hooks/$IFACE
echo CLUSTER=$CLUSTER
2018-07-26 03:57:41 -05:00
if ! [[ $CLUSTER =~ ^[0-9]+$ ]]; then
echo "CLUSTER seems not to be valid"
exit 10
fi
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}