2013-02-05 18:34:12 +00:00
#!/bin/sh
2013-01-18 18:06:10 +00:00
# IBM(c) 2013 EPL license http://www.eclipse.org/legal/epl-v10.html
# xCAT post script for configuring ib adaptors.
2013-03-01 03:39:58 +00:00
# Work for both IPv4 and IPv6
2013-01-18 18:06:10 +00:00
# The following are a sample of the env used:
2013-01-18 21:25:08 +00:00
# NIC_IBNICS=ib0,ib1
# NIC_IBAPORTS=1 (or 2)
2013-01-18 18:06:10 +00:00
# OSVER=sles11.1
2013-01-18 21:25:08 +00:00
# NICNODE=dxm360m4n04
2013-01-18 18:06:10 +00:00
# NICIPS='eth0!10.1.34.242,ib1!15.0.1.242,ib2!15.0.2.242'
# NICHOSTNAMESUFFIXES='eth1!-eth1,ib1!-ib1,ib2!-ib2'
# NICTYPES='eth1!ethernet,ib1!infiniband,ib2!infiniband'
# NICNETWORKS='eth0!10_1_0_0-255_255_255_0,ib1!ib1,ib2!ib2'
# NETWORKS_LINES=3
# NETWORKS_LINE1='netname=10_1_0_0-255_255_255_0||net=10.1.0.0||mask=255.255.255.0||mgtifname=eth1||gateway=<xcatmaster>||dhcpserver=10.1.0.205||tftpserver=10.1.0.205||nameservers=||ntpservers=||logservers=||dynamicrange=||staticrange=||staticrangeincrement=||nodehostname=||ddnsdomain=||vlanid=||domain=||disable=||comments='
# NETWORKS_LINE2='netname=ib1||net=15.0.1.0||mask=255.255.255.0||mgtifname=||gateway=15.0.1.254||dhcpserver=||tftpserver=||nameservers=||ntpservers=||logservers=||dynamicrange=||staticrange=||staticrangeincrement=||nodehostname=||ddnsdomain=||vlanid=||domain=||disable=||comments='
# NETWORKS_LINE3='netname=ib3||net=15.0.3.0||mask=255.255.255.0||mgtifname=||gateway=||dhcpserver=||tftpserver=||nameservers=||ntpservers=||logservers=||dynamicrange=||staticrange=||staticrangeincrement=||nodehostname=||ddnsdomain=||vlanid=||domain=||disable=||comments='
2013-01-18 21:25:08 +00:00
#This is the number of ports for each ib adpator.
2013-01-18 18:06:10 +00:00
portnum=1
2013-01-23 22:14:26 +00:00
if [ -n "$NIC_IBAPORTS" ]; then
2013-01-18 21:25:08 +00:00
portnum=$NIC_IBAPORTS
fi
2013-01-18 18:06:10 +00:00
# pmatch determines if 1st argument string is matched by 2nd argument pattern
pmatch ()
{
case $1 in
$2) return 0;; # zero return code means string matched by pattern
esac
return 1 # non-zero return code means string not matched by pattern
}
convert_netmask_to_cidr() {
let cidrnum=0
OLFIFS=$IFS
IFS=.
for x in $1
do
case $x in
255) cidrnum=$(expr $cidrnum + 8);;
254) cidrnum=$(expr $cidrnum + 7);;
252) cidrnum=$(expr $cidrnum + 6);;
248) cidrnum=$(expr $cidrnum + 5);;
240) cidrnum=$(expr $cidrnum + 4);;
224) cidrnum=$(expr $cidrnum + 3);;
192) cidrnum=$(expr $cidrnum + 2);;
128) cidrnum=$(expr $cidrnum + 1);;
0);;
esac
done
IFS=$OLDIFS
echo $cidrnum
}
2013-07-10 09:07:51 +00:00
#if $NIC_IBNICS is not defined, all ib nics' configuration files will be deleted.
2013-01-18 21:25:08 +00:00
if [ -z "$NIC_IBNICS" ]; then
2013-01-18 18:06:10 +00:00
echo "nothing to do."
fi
#find correct IB driver
PLTFRM=`uname`
if [[ $OSVER == rhels5* || "$OSVER" == rhels6* ]]
then
ib_driver="rdma"
/sbin/service $ib_driver status
if [ $? -eq 1 ]
then
ib_driver="openibd"
/sbin/service $ib_driver status
if [ $? -eq 1 ]
then
echo "Not found the driver dameon: rdma or openibd"
2013-03-01 03:39:58 +00:00
logger -p local4.info -t xcat "Not found the driver dameon: rdma or openibd"
2013-01-18 18:06:10 +00:00
exit
fi
fi
else
ib_driver="openibd"
fi
#make changes to the confiuration file
if [ $PLTFRM == "Linux" ]
then
if [ -f "/etc/rdma/rdma.conf" ]
then
2013-04-29 20:27:22 +00:00
TMP1=`sed "s/SDP_LOAD=yes/SDP_LOAD=no/g" /etc/rdma/rdma.conf`
echo "$TMP1" > /etc/rdma/rdma.conf
2013-01-18 18:06:10 +00:00
elif [ -f "/etc/infiniband/openib.conf" ]
then
2013-04-29 20:27:22 +00:00
TMP1=`sed "s/SDP_LOAD=yes/SDP_LOAD=no/g" /etc/infiniband/openib.conf`
echo "$TMP1" > /etc/infiniband/openib.conf
2013-01-18 18:06:10 +00:00
fi
if [ -f "/etc/modprobe.conf" ]
then
2013-04-29 20:27:22 +00:00
if [ "$portnum" == "1" ]; then
TMP2=`sed "/options ib_ehca nr_ports/d" /etc/modprobe.conf`
echo "$TMP2" > /etc/modprobe.conf
2013-01-18 18:06:10 +00:00
echo 'options ib_ehca nr_ports=1' >> /etc/modprobe.conf
2013-04-29 20:27:22 +00:00
else
TMP2=`sed "/options ib_ehca nr_ports=1/d" /etc/modprobe.conf`
echo "$TMP2" > /etc/modprobe.conf
fi
TMP3=`sed "/options ib_ehca lock_hcalls/d" /etc/modprobe.conf`
echo "$TMP3" > /etc/modprobe.conf
2013-01-18 18:06:10 +00:00
echo 'options ib_ehca lock_hcalls=0' >> /etc/modprobe.conf
fi
2013-04-24 07:57:20 +00:00
/sbin/chkconfig --level 2345 $ib_driver on > /dev/null 2>&1
2013-01-18 18:06:10 +00:00
/sbin/service $ib_driver restart
sysctl -p
fi
#clean up existing ib nic configrations
if [ $PLTFRM == "Linux" ]
then
if [ -f /etc/redhat-release ]
then
OS_name="redhat"
elif [ -f /etc/SuSE-release ]
then
OS_name="suse"
else
echo "Unsupported to config IB on this OS!"
2013-03-01 03:39:58 +00:00
logger -p local4.info -t xcat "Unsupported to config IB on this OS!"
2013-01-18 18:06:10 +00:00
exit
fi
if [ $OS_name == 'suse' ]
then
dir="/etc/sysconfig/network"
else
dir="/etc/sysconfig/network-scripts"
fi
2013-07-10 09:07:51 +00:00
#`rm -f $dir/ifcfg-$nic` 2>&1 1>/dev/null
2013-03-01 03:39:58 +00:00
# nic aliases
2013-07-10 09:07:51 +00:00
`rm -f $dir/ifcfg-ib*` 2>&1 1>/dev/null
2013-01-18 18:06:10 +00:00
else
2013-03-08 19:49:02 +00:00
loop_number=`lsdev | grep "IP over Infiniband Network Interface" | wc -l`
num=0
while [ $num -lt $loop_number ]
do
if [ "$portnum" == "2" ]; then
num0=`expr $num \* 2`
num1=`expr $num0 + 1`
`rmdev -d -l ib$num0 >/dev/null 2>&1`
`rmdev -d -l ib$num1 >/dev/null 2>&1`
`rmdev -d -l ml$num >/dev/null 2>&1`
num=`expr $num + 1`
else
`rmdev -d -l ib$num >/dev/null 2>&1`
n=`expr $num % 2`
if [ $n == 1 ]
then
mlnum=`expr $num / 2`
`rmdev -d -l ml$mlnum >/dev/null 2>&1`
fi
num=`expr $num + 1`
fi
2013-01-18 18:06:10 +00:00
done
2013-03-08 19:49:02 +00:00
2013-03-06 20:18:37 +00:00
`rmdev -dl icm >/dev/null 2>&1`
2013-03-08 19:49:02 +00:00
#restart the managers
2013-03-06 20:18:37 +00:00
mkdev -c management -s infiniband -t icm
cfgmgr
2013-01-18 18:06:10 +00:00
fi
goodnics=""
2013-01-18 21:25:08 +00:00
for nic in `echo "$NIC_IBNICS" | tr "," "\n"`
2013-01-18 18:06:10 +00:00
do
2013-03-01 03:39:58 +00:00
#Get nic ips
nicips=""
2013-01-18 18:06:10 +00:00
for tmp in `echo "$NICIPS" | tr "," "\n"`
do
2013-03-01 03:39:58 +00:00
nic_tmp=`echo "$tmp" | awk -F"!" '{print $1}'`;
if [ $nic_tmp == $nic ]; then
# nicips=ip1|ip2|ip3
nicips=`echo "$tmp" | awk -F"!" '{print $2}'`;
break
fi
2013-01-18 18:06:10 +00:00
done
# echo "nic=$nic, nicip=$nicip"
2013-03-01 03:39:58 +00:00
#get nic networks name
nicnets=""
2013-01-18 18:06:10 +00:00
for tmp in `echo "$NICNETWORKS" | tr "," "\n"`
do
nic_tmp=`echo "$tmp" | awk -F"!" '{print $1}'`;
if [ $nic_tmp == $nic ]; then
2013-03-01 03:39:58 +00:00
# nicnets=net1|net2|net3
nicnets=`echo "$tmp" | awk -F"!" '{print $2}'`;
break
2013-01-18 18:06:10 +00:00
fi
done
#echo "nic=$nic, nicnet=$nicnet"
2013-03-01 03:39:58 +00:00
if [ -z "$nicnets" ]; then
2013-01-18 18:06:10 +00:00
echo "No network defined for $nic"
logger -p local4.info -t xcat "No network defined for $nic"
continue
fi
2013-03-01 03:39:58 +00:00
ipindex=0
for nicip in `echo $nicips | tr "|" "\n"`
2013-01-18 18:06:10 +00:00
do
2013-03-01 03:39:58 +00:00
ipindex=`expr $ipindex + 1`
nicnet=`echo $nicnets | cut -d '|' -f$ipindex`
2013-01-18 18:06:10 +00:00
2013-03-01 03:39:58 +00:00
#get netmask and gateway
index=0;
found=0
while [ $index -lt $NETWORKS_LINES ]
do
index=$((index+1))
eval netline=\$NETWORKS_LINE$index
if [[ -n "$netline" ]]; then
for tmp in `echo "$netline" | tr "\|" "\n"`
do
key=`echo "$tmp" | awk -F"=" '{print $1}'`;
case $key in
netname)
netname=`echo "$tmp" | awk -F"=" '{print $2}'`
if [ "$netname" != "$nicnet" ];
then
break;
fi
;;
net)
net=`echo "$tmp" | awk -F"=" '{print $2}'`
;;
mask)
netmask=`echo "$tmp" | awk -F"=" '{print $2}'`
# remove the prefix "/" from ipv6 mask
if echo $netmask | grep "/" 2>&1 1>/dev/null
then
netmask=`echo $netmask | awk -F'/' '{print $2}'`
fi
;;
gateway)
gateway=`echo "$tmp" | awk -F"=" '{print $2}'`
found=1
;;
esac
if [ $found -eq 1 ]; then
break;
fi
done # end for tmp in `echo "$netline" | tr "\|" "\n"`
if [ $found -eq 1 ]; then
break;
fi
fi # end if [[ -n "$netline" ]]
done # end while [ $index -lt $NETWORKS_LINES ]
#echo "found=$found"
#echo "index=$index netname=$nicnet net=$net mask=$netmask gateway=$gateway"
# Setup goodnics list
if [ "$found" == "0" ]; then
echo "Cannot find network $nicnet for $nic"
logger -p local4.info -t xcat "Cannot find network $nicnet for $nic"
continue
2013-01-18 18:06:10 +00:00
else
2013-03-01 03:39:58 +00:00
if [ -z "$goodnics" ]; then
goodnics=$nic
else
goodnics="$goodnics,$nic"
fi
2013-01-18 18:06:10 +00:00
fi
2013-03-01 03:39:58 +00:00
#there should be only one gateway on a node and that should go through the to the xcat management node and would be set up from the install nic. Anything else should be a route
if [ "$gateway" == "<xcatmaster>" ]; then
gateway=''
fi
2013-01-18 18:06:10 +00:00
2013-03-01 03:39:58 +00:00
if [ $PLTFRM == "Linux" ]
2013-01-18 18:06:10 +00:00
then
2013-03-01 03:39:58 +00:00
# Issue openibd for Linux at boot time
2013-01-18 18:06:10 +00:00
2013-03-01 03:39:58 +00:00
if [ -f /etc/sysctl.conf ]
then
2014-02-28 20:05:59 +00:00
TMP1=`sed "/net.ipv4.conf.$nic.arp_filter=1/d" /etc/sysctl.conf`
2013-04-29 20:27:22 +00:00
echo "$TMP1" > /etc/sysctl.conf
2014-02-28 20:05:59 +00:00
TMP2=`sed "/net.ipv4.conf.$nic.arp_ignore=1/d" /etc/sysctl.conf`
2013-04-29 20:27:22 +00:00
echo "$TMP2" > /etc/sysctl.conf
2013-03-01 03:39:58 +00:00
cfg="net.ipv4.conf.$nic.arp_filter=1"
grep "$cfg" /etc/sysctl.conf 2>&1 1>/dev/null
if [ $? -ne 0 ]
then
echo "net.ipv4.conf.$nic.arp_filter=1" >> /etc/sysctl.conf
fi
cfg="net.ipv4.conf.$nic.arp_ignore=1"
grep "$cfg" /etc/sysctl.conf 2>&1 1>/dev/null
if [ $? -ne 0 ]
then
echo "net.ipv4.conf.$nic.arp_ignore=1" >> /etc/sysctl.conf
fi
fi
if [ $OS_name == 'suse' ]
then
# First ip address
if [ $ipindex -eq 1 ]
then
# Write the info to the ifcfg file
echo "DEVICE=$nic
2013-05-02 15:01:28 +00:00
NM_CONTROLLED=no
2013-01-18 18:06:10 +00:00
BOOTPROTO=static
2013-03-01 03:39:58 +00:00
STARTMODE=onboot
IPADDR=$nicip" > $dir/ifcfg-$nic
# ipv6
if echo $nicip | grep : 2>&1 1>/dev/null
then
echo "PREFIXLEN=$netmask" >> $dir/ifcfg-$nic
else
echo "NETMASK=$netmask" >> $dir/ifcfg-$nic
fi
if [ -n "$gateway" ]; then
2013-04-03 09:16:43 +00:00
# Do not add duplicate default gateway entry
grep -E "default\\s+$gateway\\s+" /etc/sysconfig/network/routes 2>&1 1>/dev/null
if [ $? -ne 0 ]; then
echo "default $gateway - -" >> /etc/sysconfig/network/routes
fi
2013-03-01 03:39:58 +00:00
fi
else # not the first ip address
echo "LABEL_$ipindex=$ipindex
IPADDR_$ipindex=$nicip" >> $dir/ifcfg-$nic
# ipv6
if echo $nicip | grep : 2>&1 1>/dev/null
then
echo "PREFIXLEN_$ipindex=$netmask" >> $dir/ifcfg-$nic
else
echo "NETMASK_$ipindex=$netmask" >> $dir/ifcfg-$nic
fi
2013-04-03 09:16:43 +00:00
if [ -n "$gateway" ]; then
# Do not add duplicate default gateway entry
grep -E "default\\s+$gateway\\s+" /etc/sysconfig/network/routes 2>&1 1>/dev/null
if [ $? -ne 0 ]; then
echo "default $gateway - -" >> /etc/sysconfig/network/routes
fi
fi
2013-03-01 03:39:58 +00:00
fi # end if [ $ipindex -eq 1 ]
elif [ $OS_name == 'redhat' ]
then
# First ip address
if [ $ipindex -eq 1 ]
then
# Write the info to the ifcfg file
echo "DEVICE=$nic
2013-05-02 15:01:28 +00:00
NM_CONTROLLED=no
BOOTPROTO=none
2013-03-01 03:39:58 +00:00
ONBOOT=yes
IPADDR=$nicip" > $dir/ifcfg-$nic
# ipv6
if echo $nicip | grep : 2>&1 1>/dev/null
then
echo "PREFIXLEN=$netmask" >> $dir/ifcfg-$nic
else
if [[ "$OSVER" == rhels6* ]]
then
#get prefix from netmask, this is for IPv4 only
prefix=24
prefix=$(convert_netmask_to_cidr $netmask)
echo "PREFIX=$prefix" >> $dir/ifcfg-$nic
else
echo "NETMASK=$netmask" >> $dir/ifcfg-$nic
fi
fi
if [ -n "$gateway" ]; then
echo "GATEWAY=$gateway" >> $dir/ifcfg-$nic
fi
else # not the first ip address
# ipv6
if echo $nicip | grep : 2>&1 1>/dev/null
then
grep "IPV6INIT" $dir/ifcfg-$nic 2>&1 1>/dev/null
# The first ipv6 address
if [ $? -ne 0 ]
then
echo "IPV6INIT=yes
IPV6ADDR=$nicip/$netmask" >> $dir/ifcfg-$nic
else
echo "IPV6ADDR_SECONDARIES=$nicip/$netmask" >> $dir/ifcfg-$nic
fi
2013-04-03 09:16:43 +00:00
if [ -n "$gateway" ]; then
echo "IPV6_DEFAULTGW=$gateway" >> $dir/ifcfg-$nic
fi
2013-03-01 03:39:58 +00:00
else # ipv4 address
echo "DEVICE=$nic:$ipindex
2013-05-02 15:01:28 +00:00
NM_CONTROLLED=no
BOOTPROTO=none
2013-03-01 03:39:58 +00:00
ONBOOT=yes
IPADDR=$nicip" > $dir/ifcfg-$nic:$ipindex
if [[ "$OSVER" == rhels6* ]]
then
#get prefix from netmask, this is for IPv4 only
prefix=24
prefix=$(convert_netmask_to_cidr $netmask)
echo "PREFIX=$prefix" >> $dir/ifcfg-$nic:$ipindex
else
echo "NETMASK=$netmask" >> $dir/ifcfg-$nic:$ipindex
fi
if [ -n "$gateway" ]; then
echo "GATEWAY=$gateway" >> $dir/ifcfg-$nic:$ipindex
fi
# need to run ifup eth1:1 for RedHat
goodnics="$goodnics,$nic:$ipindex"
fi
fi # end not the first ip address
else
echo "Unsupported operating system"
logger -p local4.err -t xcat "Unsupported operating system"
fi
elif [ $PLTFRM == "AIX" ]; then
if ( pmatch $nic "ml*" ); then #for ml* interface
num=${nic##ml}
mlt="mlt$num"
2013-01-18 18:06:10 +00:00
#Check whether the mlt is available
2013-03-01 03:39:58 +00:00
lsdev -C | grep $mlt | grep Available 2>&1 >/dev/null
if [ $? -ne 0 ]
then
2013-01-18 18:06:10 +00:00
echo "$mltnum is not available."
2013-03-01 03:39:58 +00:00
logger -p local4.info -t xcat "$mltnum is not available."
continue
fi
2013-01-18 18:06:10 +00:00
#Check whether the ml0 is available
2013-03-01 03:39:58 +00:00
lsdev -C | grep $nic 2>&1 >/dev/null
if [ $? -ne 0 ]
then
2013-01-18 18:06:10 +00:00
cfgmgr 2>&1 >/dev/null
2013-03-01 03:39:58 +00:00
fi
chdev -l $nic -a state=detach 2>&1
chdev -l $nic -a netaddr=$nicip -a netmask=$netmask -a state=up 2>&1
else #assume it is ib*
2013-03-06 20:18:37 +00:00
#lsdev -C | grep icm | grep Available
#if [ $? -ne 0 ]
#then
# mkdev -c management -s infiniband -t icm
# if [ $? -ne 0 ]
# then
# mkdev -l icm
# if [ $? -ne 0 ]
# then
# exit $?
# fi
# fi
# fi
2013-03-01 03:39:58 +00:00
#Configure the IB interfaces. Customize the port num.
num=${nic##ib} #this assumes that all the nics starts with 'ib'
if [ "$portnum" == "1" ]; then
iba_num=$num
ib_adapter="iba$iba_num"
port=1
else
iba_num=`expr $num / 2`
ib_adapter="iba$iba_num"
if [ $(($num % 2)) == 0 ]
then
port=1
else
port=2
fi
2013-01-18 18:06:10 +00:00
fi
2013-03-06 20:18:37 +00:00
if [ $NODE ]; then
shortname=$NODE
else
shortname=`hostname -s`
fi
chdev -l $ib_adapter -a hostname=$shortname
2013-03-01 03:39:58 +00:00
mkiba -a $nicip -i $nic -A $ib_adapter -p $port -P -1 -S up -m $netmask
fi # end assume it is ib*
fi # end if AIX
done # end for nicip
done # end for nic
2013-01-18 18:06:10 +00:00
# echo "goodnics=$goodnics"
# Bringup all the ib interfaces
if [ $PLTFRM == "Linux" ]
then
/sbin/service $ib_driver restart
for nic in `echo "$goodnics" | tr "," "\n"`
do
sleep 5
if [[ "$OSVER" == rhels6* ]]
then
ip link set dev $nic up
else
ifup $nic
fi
done
fi