Created
March 20, 2015 14:01
-
-
Save framer99/56429ea00d1df4d44e24 to your computer and use it in GitHub Desktop.
# Automated nmcli/NetworkManager config script for 7 NIC server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# | |
# Automated nmcli/NetworkManager config script for 7 NIC server | |
# 1 NIC for dedicated management is ignored by this script | |
# 6 NICs configured in 3 active backup teams | |
# Ethtool link watchers only | |
# | |
# Set this to the NetworkManager connection name of the management | |
# interface which you do not want to be touched. | |
# | |
# Use something like this to setup your dedicated management nic | |
# outside this script | |
# nmcli conn add type ethernet con-name man ifname ens1 ip4 10.1.1.101/24 gw4 10.1.1.1 | |
IGNORED_MGMT_CONN_NAME="man" | |
# List of team names | |
TEAMS="ccom stor traf" | |
# Map of member ports to <teamname>_MEMBERS variables | |
# The first listed port for each will become the preferred | |
# port for that team | |
ccom_MEMBERS="enp2s0f0 enp9s0f0" | |
stor_MEMBERS="enp2s0f1 enp10s0f1" | |
traf_MEMBERS="enp9s0f1 enp10s0f0" | |
# IP address option to nmcli add team command | |
ccom_IPOPTS="ip4 172.17.1.2/24" | |
stor_IPOPTS="ip4 172.17.2.2/24" | |
traf_IPOPTS="ip4 172.17.3.20/24 gw4 172.17.3.1" | |
# Template of team config. arp_ping watchers can be added to traf | |
# team later when gateway or futher upstream IPs are known. | |
# The ccom and stor team are direct wired from host to host for | |
# a single hot standby pair of servers so there is no need to use | |
# arp_ping anyway | |
TEAM_TEMPLATE=' | |
{ | |
\"device\": \"$team\", | |
\"runner\": { \"name\": \"activebackup\" }, | |
\"link_watch\": { \"name\": \"ethtool\" }, | |
\"ports\": { \"${team}-member-1\": { \"prio\": 100 }, | |
\"${team}-member-2\": { \"prio\": 95 }} | |
}' | |
#delete all exisitng conns | |
#nmcli -f NAME -t conn | xargs -d\\n nmcli conn delete | |
for x in $(nmcli -f NAME -t conn ) ; do | |
if [ "$x"x != "$IGNORED_MGMT_CONN_NAME"x ] ; then | |
sleep 1 # going to fast causes bogus errors sometimes | |
echo "Delete $x" | |
nmcli conn delete $x | |
fi | |
done | |
# create management nic link | |
#nmcli conn add type ethernet con-name man ifname ens1 ip4 10.1.1.101/24 gw4 10.1.1.1 | |
for team in $TEAMS; do | |
#add team device | |
config=$(eval echo $TEAM_TEMPLATE) | |
eval ipopts=\$${team}_IPOPTS | |
nmcli conn add type team con-name $team ifname $team config "$config" $ipopts | |
#add member ports to the team | |
eval members=\$${team}_MEMBERS | |
x=0 | |
for member in $members ; do | |
x=$((x+1)) | |
nmcli conn add type team-slave ifname $member con-name ${team}-member-$x master $team | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment