Commit 368a3f9a authored by glucas's avatar glucas

Add enhanced kvm-vif-bridge script.

parent 43b71c4f
#!/bin/bash
# Copyright (C) 2015-2018 Alsace Réseau Neutre
# Copyright (C) 2015-2016 Alsace Réseau Neutre
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
......@@ -16,86 +16,68 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# exit on error so ganeti is aware and outputs the message to the user
set -e
if [ "$MODE" = "routed" ]; then
# Include ARN variables
. /etc/ganeti/common-arn-vars
VMNETCONF=$CONFDIR/$INSTANCE/net.conf
# Include ARN variables
. /etc/ganeti/common-arn-vars
[ -r $VMNETCONF ] || exit 1
. $VMNETCONF
VMNETCONF=$CONFDIR/$INSTANCE/net.conf
[ -r $VMNETCONF ] || exit 1
. $VMNETCONF
# Next-hop to route VM's IPs and subnets
NHIPv4=169.254.42.2
NHIPv6=fe80::42:2
# Next-hop to route VM's IPs and subnets
NHIPv4=169.254.42.2
NHIPv6=fe80::42:2
MYV4=$(/bin/ip -4 a s dev loopback1 | grep -Po "(?<=inet )[0-9\.]+(?=/32 scope global loopback1$)")
MYV6=$(/bin/ip -6 a s dev loopback1 | grep -Po "(?<=inet6 )[0-9a-f:]+(?=/128 scope global)")
[ -n $MYV4 ] || exit 2
[ -n $MYV6 ] || exit 2
MYV4=$(/bin/ip -4 a s dev loopback1 | grep -Po "(?<=inet )[0-9\.]+(?=/32 scope global loopback1$)")
MYV6=$(/bin/ip -6 a s dev loopback1 | grep -Po "(?<=inet6 )[0-9a-f:]+(?=/128 scope global)")
[ -n $MYV4 ] || exit 2
[ -n $MYV6 ] || exit 2
# Set name to VM's iface (tap)
ip link set dev $INTERFACE alias $INSTANCE-$INTERFACE_INDEX
# Disabling IPv6 autoconfiguration from guest
/sbin/sysctl -w net.ipv6.conf.$INTERFACE.accept_ra=0
/sbin/sysctl -w net.ipv6.conf.$INTERFACE.autoconf=0
# exit on error so ganeti is aware and outputs the message to the user
set -e
ip link set $INTERFACE up
# Set name to VM's iface (tap)
ip link set dev $INTERFACE alias $INSTANCE-$INTERFACE_INDEX
# Addressing VM's iface (tap)
ip address add 169.254.42.1/24 dev $INTERFACE scope link
ip address add fe80::42:1/112 dev $INTERFACE
# Disabling IPv6 autoconfiguration from guest
/sbin/sysctl -w net.ipv6.conf.$INTERFACE.accept_ra=0
/sbin/sysctl -w net.ipv6.conf.$INTERFACE.autoconf=0
# Routing VM's IPs and subnets
if [ -n "$VIA" ]; then
viav4="via $NHIPv4"
viav6="via $NHIPv6"
fi
ip link set $INTERFACE up
for ip in $IPV4_NET; do
ip route replace $ip dev $INTERFACE $viav4 src $MYV4 proto ganeti
done
for ip in $IPV6_NET; do
ip route replace $ip dev $INTERFACE $viav6 src $MYV6 proto ganeti
done
# Addressing VM's iface (tap)
ip address add 169.254.42.1/24 dev $INTERFACE scope link
ip address add fe80::42:1/112 dev $INTERFACE
# DDNS to allow VNC usage
if [[ $INSTANCE == *"vps-"* ]]; then
echo "server 89.234.141.65
zone arn-fai.net
update delete $INSTANCE-vnc.arn-fai.net CNAME
update add $INSTANCE-vnc.arn-fai.net 60 CNAME `hostname -f`
show
send" | nsupdate -v
fi
elif [ "$MODE" = "bridged" ]; then
# Fix the autogenerated MAC to have the first octet set to "fe"
# to discourage the bridge from using the TAP dev's MAC
FIXED_MAC=$(ip link show $INTERFACE | \
awk '{if ($1 == "link/ether") printf("fe%s",substr($2,3,15))}')
# Routing VM's IPs and subnets
if [ -n "$VIA" ]; then
viav4="via $NHIPv4"
viav6="via $NHIPv6"
fi
for ip in $IPV4_NET; do
ip route replace $ip dev $INTERFACE $viav4 src $MYV4 proto ganeti
done
# in case of a vif (xen_netback device) this action is not allowed
ip link set $INTERFACE address $FIXED_MAC || true
ip link set $INTERFACE up
ip link set $INTERFACE mtu $(</sys/class/net/${LINK}/mtu)
for ip in $IPV6_NET; do
ip route replace $ip dev $INTERFACE $viav6 src $MYV6 proto ganeti
done
# Connect the interface to the bridge
brctl addif $LINK $INTERFACE
# DDNS to allow VNC usage
if [[ $INSTANCE == *"vps-"* ]] || [[ $INSTANCE == *"vpsto-"* ]] ; then
echo "server 89.234.141.65
zone arn-fai.net
update delete $INSTANCE-vnc.arn-fai.net CNAME
update add $INSTANCE-vnc.arn-fai.net 60 CNAME `hostname -f`
show
send" | nsupdate -v
fi
exit 0
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment