2013-10-25 18:45:37 +00:00
|
|
|
#!/bin/bash
|
2013-08-02 10:14:45 +00:00
|
|
|
|
|
|
|
str_dir_name=`dirname $0`
|
|
|
|
. $str_dir_name/xcatlib.sh
|
|
|
|
|
|
|
|
#the nics' information contain:
|
|
|
|
#1. ip address
|
|
|
|
#2. nic network
|
|
|
|
#3. nic type
|
|
|
|
#4. custom scripts
|
|
|
|
#all of them are saved by different variable
|
|
|
|
#this function can split the varable for each nic, and svae the information for each nic
|
|
|
|
#into an hash, the key is nic name, the value are all information, which joined by ','
|
|
|
|
function splitconfig(){
|
|
|
|
if [ ! "$1" ];then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
old_ifs=$IFS
|
|
|
|
IFS=$','
|
|
|
|
array_conf_temp=($1)
|
|
|
|
IFS=$old_ifs
|
2014-05-21 08:37:35 +00:00
|
|
|
|
|
|
|
i=0
|
|
|
|
while [ $i -lt ${#array_conf_temp[@]} ]
|
2013-08-02 10:14:45 +00:00
|
|
|
do
|
2014-05-21 08:37:35 +00:00
|
|
|
token="${array_conf_temp[$i]}"
|
2013-08-02 10:14:45 +00:00
|
|
|
D=
|
2014-05-21 08:37:35 +00:00
|
|
|
if echo "$token" | grep "!"; then
|
2013-08-02 10:14:45 +00:00
|
|
|
D="!"
|
|
|
|
else
|
|
|
|
D=":"
|
|
|
|
fi
|
2014-05-21 08:37:35 +00:00
|
|
|
key=`echo "$token" | cut -d"$D" -f 1`
|
|
|
|
str_temp_value=`echo "$token" | cut -d"$D" -f 2`
|
2013-01-22 19:03:07 +00:00
|
|
|
|
2013-08-02 10:14:45 +00:00
|
|
|
str_temp=$(hashget hash_defined_nics $key)
|
|
|
|
if [ -n "$str_temp" ];then
|
|
|
|
str_temp=$str_temp",${str_temp_value}"
|
|
|
|
else
|
|
|
|
str_temp="$str_temp_value"
|
|
|
|
str_all_nics=$str_all_nics"$key "
|
|
|
|
fi
|
2014-05-21 08:37:35 +00:00
|
|
|
hashset hash_defined_nics $key "$str_temp"
|
|
|
|
i=$((i+1))
|
2013-08-02 10:14:45 +00:00
|
|
|
done
|
2013-06-14 18:54:50 +00:00
|
|
|
}
|
|
|
|
|
2013-11-01 10:34:35 +00:00
|
|
|
function findnetwork(){
|
2013-11-10 07:56:53 +00:00
|
|
|
local str_ip=$1
|
|
|
|
local str_network=''
|
|
|
|
local flag_v6=0
|
|
|
|
echo "$str_ip" | grep ':' > /dev/null
|
|
|
|
if [ $? -eq 0 ];then
|
|
|
|
flag_v6=1
|
|
|
|
fi
|
2013-11-01 10:34:35 +00:00
|
|
|
local num_i=1
|
|
|
|
while [ $num_i -le $NETWORKS_LINES ];do
|
|
|
|
eval str_temp=\$NETWORKS_LINE$num_i
|
|
|
|
str_net=`echo $str_temp | awk -F'net=' '{print $2}' | awk -F'|' '{print $1}'`
|
|
|
|
str_mask=`echo $str_temp | awk -F'mask=' '{print $2}' | awk -F'|' '{print $1}' | sed 's:^/::'`
|
|
|
|
echo $str_net | grep ':' > /dev/null
|
|
|
|
if [ $? -ne 0 ];then
|
2013-11-10 07:56:53 +00:00
|
|
|
if [ $flag_v6 -eq 0 ];then
|
|
|
|
str_temp_net1=$(v4calcnet $str_ip $str_mask)
|
|
|
|
str_temp_net2=$(v4calcnet $str_net $str_mask)
|
|
|
|
else
|
|
|
|
num_i=$((num_i+1))
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
if [ $flag_v6 -eq 1 ];then
|
|
|
|
str_temp_net1=$(v6calcnet $str_ip $str_mask)
|
|
|
|
str_temp_net2=$(v6calcnet $str_net $str_mask)
|
|
|
|
else
|
|
|
|
num_i=$((num_i+1))
|
|
|
|
continue
|
2013-11-01 10:34:35 +00:00
|
|
|
fi
|
|
|
|
fi
|
2013-11-10 07:56:53 +00:00
|
|
|
|
|
|
|
if [ "$str_temp_net1" = "$str_temp_net2" ];then
|
|
|
|
str_network=`echo $str_temp | awk -F'netname=' '{print $2}' | awk -F'|' '{print $1}'`
|
|
|
|
echo "$str_network"
|
|
|
|
return
|
|
|
|
fi
|
2013-11-01 10:34:35 +00:00
|
|
|
num_i=$((num_i+1))
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "Error: Can not find the corresponding network defination for ip address: $str_ip ."
|
|
|
|
}
|
|
|
|
|
|
|
|
function checknetwork(){
|
|
|
|
old_ifs=$IFS
|
|
|
|
IFS=$'|'
|
|
|
|
array_ip=($1)
|
|
|
|
IFS=$old_ifs
|
|
|
|
str_ret=''
|
|
|
|
|
|
|
|
num_length=${#array_ip[@]}
|
|
|
|
num_index=0
|
|
|
|
while [ $num_index -lt $num_length ]
|
|
|
|
do
|
|
|
|
str_ip=${array_ip[$num_index]}
|
2013-11-10 07:56:53 +00:00
|
|
|
str_networkname=$(findnetwork $str_ip)
|
|
|
|
echo "$str_networkname" | grep -i 'error' > /dev/null
|
|
|
|
if [ $? -eq 0 ];then
|
|
|
|
echo "$str_networkname"
|
|
|
|
return
|
2013-11-01 10:34:35 +00:00
|
|
|
fi
|
2013-11-10 07:56:53 +00:00
|
|
|
str_ret="${str_ret}${str_networkname},"
|
|
|
|
|
2013-11-01 10:34:35 +00:00
|
|
|
num_index=$((num_index+1))
|
|
|
|
done
|
|
|
|
|
|
|
|
str_ret=`echo $str_ret | sed 's/.$//'`
|
|
|
|
echo "$str_ret"
|
|
|
|
}
|
|
|
|
|
2013-08-02 10:14:45 +00:00
|
|
|
bool_cfg_inst_nic=0
|
|
|
|
str_inst_nic=''
|
|
|
|
str_ib_nics=''
|
|
|
|
str_os_type=`uname | tr 'A-Z' 'a-z'`
|
2013-10-28 11:46:25 +00:00
|
|
|
if [ "$str_os_type" = "aix" ];then
|
|
|
|
logger -t xcat -p local4.err "confignics: aix does not support in this build"
|
|
|
|
echo "confignics: aix does not support in this build"
|
|
|
|
exit 0
|
|
|
|
fi
|
2013-08-02 10:14:45 +00:00
|
|
|
bool_remove=0
|
|
|
|
num_iba_ports=
|
|
|
|
str_all_nics=''
|
|
|
|
for arg in "$@"
|
|
|
|
do
|
|
|
|
if [ "$arg" = "-s" ];then
|
|
|
|
bool_cfg_inst_nic=1
|
|
|
|
elif [ "$arg" = "-r" ];then
|
|
|
|
bool_remove=1
|
|
|
|
elif [ "${arg:0:10}" = "--ibaports" ];then
|
|
|
|
num_iba_ports=${arg#--ibaports=}
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2014-01-07 07:26:53 +00:00
|
|
|
if [ "$SETINSTALLNIC" = "1" ] || [ "$SETINSTALLNIC" = "yes" ]; then
|
|
|
|
bool_cfg_inst_nic=1
|
|
|
|
fi
|
|
|
|
|
2013-10-25 18:45:37 +00:00
|
|
|
boot_myscript=0
|
|
|
|
if [ $# -eq 2 ]
|
|
|
|
then
|
|
|
|
if [ "$1" = "--script" ]
|
|
|
|
then
|
|
|
|
if [ $bool_cfg_inst_nic -eq 1 -o $bool_remove -eq 1 -o ! -z "$num_iba_ports" ]
|
|
|
|
then
|
|
|
|
logger -t xcat -p local4.info "confignics --script <myscript> could Not be used with other options"
|
|
|
|
echo "confignics --script <myscript> could Not be used with other options"
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
boot_myscript=1
|
|
|
|
myscript=$2;
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-08-02 10:14:45 +00:00
|
|
|
logger -t xcat -p local4.info "confignics is called: config install nic:$bool_cfg_inst_nic, remove: $bool_remove, iba ports: $num_iba_ports"
|
|
|
|
echo "confignics on $NODE: config install nic:$bool_cfg_inst_nic, remove: $bool_remove, iba ports: $num_iba_ports"
|
|
|
|
|
|
|
|
str_temp=''
|
|
|
|
if [ ! $INSTALLNIC ];then
|
|
|
|
str_temp="mac"
|
|
|
|
else
|
|
|
|
str_temp=$INSTALLNIC
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$str_temp" = "mac" ];then
|
|
|
|
if [ "$str_os_type" = "aix" ];then
|
|
|
|
old_ifs=$IFS
|
|
|
|
IFS=$' '
|
|
|
|
str_temp=`ifconfig -l`
|
|
|
|
array_nicnames_temp=($str_temp)
|
|
|
|
IFS=$old_ifs
|
|
|
|
for temp_nic in ${array_nicnames_temp[@]}
|
|
|
|
do
|
|
|
|
entstat -t $temp_nic | grep -i "$MACADDRESS"
|
|
|
|
if [ $? -eq 0 ];then
|
|
|
|
str_inst_nic=$temp_nic
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
else
|
2014-05-27 16:31:27 +00:00
|
|
|
str_inst_nic=`ip -o link | grep -i "$MACADDRESS" | awk '{print $2;}' | sed s/://`
|
2013-08-02 10:14:45 +00:00
|
|
|
fi
|
2014-06-25 19:42:07 +00:00
|
|
|
elif [ `echo $str_temp | grep -E "e(n|th)[0-9a-z]+"` ];then
|
2013-08-02 10:14:45 +00:00
|
|
|
str_inst_nic=$str_temp
|
|
|
|
fi
|
|
|
|
|
2013-09-12 06:51:05 +00:00
|
|
|
if [ $bool_cfg_inst_nic -eq 1 ];then
|
|
|
|
configeth -s $str_inst_nic
|
|
|
|
fi
|
2013-08-02 10:14:45 +00:00
|
|
|
|
2013-09-04 09:46:23 +00:00
|
|
|
bool_exit_flag=0
|
|
|
|
#check the required attributes
|
|
|
|
if [ -z "$NICIPS" ];then
|
2013-11-10 07:56:53 +00:00
|
|
|
logger -t xcat -p local4.info "confignics: nicips attribute is not defined. "
|
|
|
|
echo "confignics on $NODE: nicips attribute is not defined. "
|
2013-09-04 09:46:23 +00:00
|
|
|
exit 0
|
|
|
|
fi
|
2013-08-02 10:14:45 +00:00
|
|
|
|
2014-05-21 08:37:35 +00:00
|
|
|
splitconfig "$NICIPS"
|
|
|
|
splitconfig "$NICCUSTOMSCRIPTS"
|
2013-08-02 10:14:45 +00:00
|
|
|
|
2013-10-25 18:45:37 +00:00
|
|
|
if [ $boot_myscript -eq 1 ];then
|
|
|
|
. $str_dir_name/$myscript
|
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
exit -1
|
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2013-08-02 10:14:45 +00:00
|
|
|
#get state of nic in "UP" status
|
|
|
|
#If bonded redhat then "SLAVE" or "MASTER" will be in the first line of stanza
|
|
|
|
#do not configure the loopback nic
|
|
|
|
if [ $bool_remove -eq 1 ];then
|
|
|
|
if [ "$str_os_type" = "aix" ];then
|
|
|
|
str_temp=`ifconfig -a | grep flags | grep -vi loopback | grep -v SALVE | grep -v MASTER | awk -F: {'print $1'}`
|
|
|
|
else
|
|
|
|
str_temp=`ip link show | grep -v link | grep -vi loopback | grep -v SALVE | grep -v MASTER | awk {'print $2'} | sed s/://`
|
|
|
|
fi
|
|
|
|
old_ifs=$IFS
|
|
|
|
IFS=$'\n'
|
|
|
|
array_nics_temp=($str_temp)
|
|
|
|
IFS=$old_ifs
|
|
|
|
for str_temp_nic in ${array_nics_temp[@]}
|
|
|
|
do
|
|
|
|
#the nic type should be ethernet
|
2014-06-25 19:42:07 +00:00
|
|
|
echo $str_temp_nic | grep -E "e(n|th)[0-9a-z]+"
|
2013-08-02 10:14:45 +00:00
|
|
|
if [ $? -ne 0 ];then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
if [ "$str_os_type" != "aix" ];then
|
|
|
|
brctl show 2>/dev/null | grep $str_temp_nic
|
|
|
|
#the nic belongs to a bridge, go to next
|
|
|
|
if [ $? -eq 0 ];then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
#the nic is defined this time
|
|
|
|
str_temp=$(hashget hash_defined_nics $str_temp_nic)
|
|
|
|
if [ -n "$str_temp" ];then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2013-09-12 06:51:05 +00:00
|
|
|
if [ "$str_temp_nic" = "$str_inst_nic" ];then
|
2013-08-02 10:14:45 +00:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
#ignore the vlan interface
|
|
|
|
echo $str_temp_nic | grep "\."
|
|
|
|
if [ $? -eq 0 ];then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
logger -t xcat -p local4.info "confignics: remove nic $str_temp_nic"
|
|
|
|
echo "confignics on $NODE: remove nic $str_temp_nic"
|
|
|
|
configeth -r $str_temp_nic
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
|
|
|
|
old_ifs=$IFS
|
|
|
|
IFS=$' '
|
|
|
|
array_nics_temp=($str_all_nics)
|
|
|
|
IFS=$old_ifs
|
|
|
|
for key in ${array_nics_temp[@]}
|
|
|
|
do
|
|
|
|
key=`echo $key | sed 's/^ \+//' | sed 's/ \+$//'`
|
|
|
|
str_nic_type=
|
|
|
|
str_value=$(hashget hash_defined_nics $key)
|
2013-09-12 06:51:05 +00:00
|
|
|
if [ "$key" = "$str_inst_nic" ];then
|
2013-08-02 10:14:45 +00:00
|
|
|
continue
|
|
|
|
fi
|
|
|
|
old_ifs=$IFS
|
|
|
|
IFS=$','
|
|
|
|
array_temp=($str_value)
|
|
|
|
IFS=$old_ifs
|
|
|
|
|
2013-11-10 07:56:53 +00:00
|
|
|
if [ -n "${array_temp[1]}" ];then
|
|
|
|
logger -t xcat -p local4.info "confignics: processing custom scripts: ${array_temp[1]} for interface $key"
|
|
|
|
echo "confignics on $NODE: processing custom scripts: ${array_temp[1]} for interface $key"
|
|
|
|
${array_temp[1]}
|
2013-08-02 10:14:45 +00:00
|
|
|
else
|
2014-06-25 19:42:07 +00:00
|
|
|
if [ `echo $key | grep -E 'e(n|th)[0-9a-z]+'` ];then
|
2013-11-01 10:34:35 +00:00
|
|
|
str_nic_type="ethernet"
|
2014-01-29 16:03:17 +00:00
|
|
|
elif [ `echo $key | grep -E 'ib[0-9]+'` ];then
|
2013-11-01 10:34:35 +00:00
|
|
|
str_nic_type="infiniband"
|
|
|
|
else
|
|
|
|
logger -t xcat -p local4.info "confignics: unknown nic type for $key: $str_value ."
|
|
|
|
echo "confignics on $NODE: unknown nic type for $key: $str_value ."
|
2013-09-04 09:46:23 +00:00
|
|
|
continue
|
|
|
|
fi
|
2013-11-01 10:34:35 +00:00
|
|
|
|
2013-11-10 07:56:53 +00:00
|
|
|
str_network=$(checknetwork ${array_temp[0]})
|
2013-11-01 10:34:35 +00:00
|
|
|
echo "$str_network" | grep -i 'error' > /dev/null
|
|
|
|
if [ $? -eq 0 ];then
|
|
|
|
logger -t xcat -p local4.info "$str_network"
|
|
|
|
echo "confignics on $NODE: $str_network"
|
|
|
|
continue
|
2013-08-02 10:14:45 +00:00
|
|
|
fi
|
|
|
|
|
2013-09-23 09:56:23 +00:00
|
|
|
if [ "$str_nic_type" = "ethernet" ];then
|
2013-11-01 10:34:35 +00:00
|
|
|
logger -t xcat -p local4.info "confignics: call 'configeth $key ${array_temp[0]} $str_network'"
|
|
|
|
echo "confignics on $NODE: call 'configeth $key ${array_temp[0]} $str_network'"
|
2013-11-10 07:56:53 +00:00
|
|
|
configeth $key ${array_temp[0]} $str_network
|
2013-09-23 09:56:23 +00:00
|
|
|
elif [ "$str_nic_type" = "infiniband" ];then
|
2013-08-02 10:14:45 +00:00
|
|
|
if [ $str_ib_nics ];then
|
|
|
|
str_ib_nics=$str_ib_nics","$key
|
|
|
|
else
|
|
|
|
str_ib_nics=$key
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
logger -t xcat -p local4.info "confignics: unknown type $str_nic_type for NIC: $key"
|
|
|
|
echo "confignics on $NODE: unknown type $str_nic_type for NIC: $key"
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ -n "$str_ib_nics" ];then
|
|
|
|
logger -t xcat -p local4.info "confignics: executed script: configib for nics: $str_ib_nics, ports: $num_iba_ports"
|
|
|
|
echo "confignics on $NODE: executed script: configib for nics: $str_ib_nics, ports: $num_iba_ports"
|
|
|
|
NIC_IBNICS=$str_ib_nics NIC_IBAPORTS=$num_iba_ports configib
|
|
|
|
else
|
|
|
|
if [ $bool_remove -eq 1 ];then
|
|
|
|
logger -t xcat -p local4.info "confignics: executed script: 'configib -u' to remove all ib nics and configuration files"
|
|
|
|
echo "confignics on $NODE: executed script: 'configib -r' to remove all ib nics and configuration files"
|
|
|
|
configib
|
|
|
|
fi
|
|
|
|
fi
|