79 lines
2.1 KiB
Bash
Executable file
79 lines
2.1 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
source scan-netdev
|
|
modprobe bonding
|
|
|
|
# All vlans are using netmask /22
|
|
MASK=22
|
|
CTLPLANE=110 # ctlplane vlan
|
|
VLANS='110 218 222 226 306 321 480 1000'
|
|
SPEED=25000
|
|
MTU=9000
|
|
|
|
for VLAN in $VLANS ; do
|
|
if [[ -f /etc/netdev/vlan.$VLAN.csv ]] ; then
|
|
VLAN_CONF=`grep $SERVER_SERIAL \
|
|
/etc/netdev/vlan.$VLAN.csv`
|
|
else
|
|
VLAN_CONF=
|
|
fi
|
|
[[ -z $VLAN_CONF ]] && continue
|
|
MY_HOSTNAME=`hostname`
|
|
#HOSTNAME,SERIAL,IP_ADDRESS,BOND,MODE,SLAVE0,SLAVE1,GW
|
|
VLAN_HOSTNAME=`cut -d ',' -f 1 <<< $VLAN_CONF`
|
|
if [[ -n $VLAN_HOSTNAME ]] ; then
|
|
if [[ "$MY_HOSTNAME" != "$VLAN_HOSTNAME" ]] ; then
|
|
hostname $VLAN_HOSTNAME
|
|
fi
|
|
fi
|
|
VLAN_IP=`cut -d ',' -f 3 <<< $VLAN_CONF`
|
|
VLAN_BOND=`cut -d ',' -f 4 <<< $VLAN_CONF`
|
|
BOND_MODE=`cut -d ',' -f 5 <<< $VLAN_CONF`
|
|
SLAVE_0=`cut -d ',' -f 6 <<< $VLAN_CONF`
|
|
SLAVE_1=`cut -d ',' -f 7 <<< $VLAN_CONF`
|
|
[[ -z $VLAN_BOND ]] && continue
|
|
if [[ ! -d /sys/class/net/$VLAN_BOND ]] ; then
|
|
if [[ ! -f /sys/class/net/bonding_masters ]] ; then
|
|
echo "Missing bonding_masters special file"
|
|
exit 22
|
|
fi
|
|
echo "+$VLAN_BOND" \
|
|
> /sys/class/net/bonding_masters
|
|
sleep 3
|
|
if [[ ! -d /sys/class/net/$VLAN_BOND ]] ; then
|
|
echo "$VLAN_BOND not available"
|
|
exit 23
|
|
fi
|
|
MY_MODE=`cut -d ' ' -f 2 /sys/class/net/$VLAN_BOND/bonding/mode`
|
|
if [[ "$MY_MODE" != "$BOND_MODE" ]] ; then
|
|
echo $BOND_MODE \
|
|
> /sys/class/net/$VLAN_BOND/bonding/mode
|
|
sleep 2
|
|
fi
|
|
ip link set $VLAN_BOND up
|
|
[[ -n $MTU ]] && ip link set $VLAN_BOND mtu $MTU
|
|
if [[ -n $SPEED ]] ; then
|
|
ethtool -s $SLAVE_0 autoneg off speed $SPEED duplex full
|
|
ethtool -s $SLAVE_1 autoneg off speed $SPEED duplex full
|
|
fi
|
|
sleep 5
|
|
ifenslave $VLAN_BOND $SLAVE_0 $SLAVE_1
|
|
sleep 5
|
|
fi
|
|
if [[ $VLAN == $CTLPLANE ]] ; then
|
|
ip addr add $VLAN_IP/$MASK dev $VLAN_BOND
|
|
GATEWAY=`cut -d ',' -f 8 <<< $VLAN_CONF`
|
|
if [[ -n $GATEWAY ]] ; then
|
|
ip route add default via $GATEWAY
|
|
fi
|
|
else
|
|
ip link add link $VLAN_BOND \
|
|
name $VLAN_BOND.$VLAN \
|
|
type vlan id $VLAN
|
|
ip link set $VLAN_BOND.$VLAN up
|
|
ip addr add $VLAN_IP/$MASK dev $VLAN_BOND.$VLAN
|
|
fi
|
|
done
|
|
|
|
systemctl restart sshd
|
|
|