Make nics.nicextraparams work for any user defined settings, fixed defect 4541 and 4542
This commit is contained in:
parent
d9d0ac7835
commit
edbe36c98d
@ -3,11 +3,20 @@
|
||||
# Internal script used by confignics only.
|
||||
# It configs the Ethernet adpaters on the node
|
||||
|
||||
# The extra parameter are specified in the nics.nicextraparams.
|
||||
# The extra parameter NICEXTRAPARAMS are specified in the nics.nicextraparams.
|
||||
# It has the following format:
|
||||
# eth2!MTU=65520 somethingelse=yes,eth3!MTU=1500
|
||||
# This function gets the values for the given nic,
|
||||
# It stores each parameter values in a separate array.
|
||||
|
||||
|
||||
# This function parse the NICEXTRAPARAMS into an array.
|
||||
# Each arry element contains all the extra params for an ip
|
||||
# For example:
|
||||
# NICEXTRAPARAMS="eth0!MTU=1500 sonething=x|MTU=1460,ib0!MTU=65520 CONNECTED_MODE=yes".
|
||||
# After calling this function with eth0:
|
||||
# array_extra_param[0]="MTU=1500 sonething=x"
|
||||
# array_extra_param[1]="MTU=1460"
|
||||
function get_nic_extra_params() {
|
||||
nic=$1
|
||||
if [ ! "$NICEXTRAPARAMS" ];then
|
||||
@ -17,6 +26,7 @@ function get_nic_extra_params() {
|
||||
IFS=$','
|
||||
array_conf_temp=($NICEXTRAPARAMS)
|
||||
IFS=$old_ifs
|
||||
#echo "NICEXTRA=$NICEXTRAPARAMS"
|
||||
|
||||
i=0
|
||||
while [ $i -lt ${#array_conf_temp[@]} ]
|
||||
@ -29,45 +39,50 @@ function get_nic_extra_params() {
|
||||
D=":"
|
||||
fi
|
||||
key=`echo "$token" | cut -d"$D" -f 1`
|
||||
#echo "key=$key nic=$nic"
|
||||
if [ "$key" == "$nic" ]; then
|
||||
str_temp_value=`echo "$token" | cut -d"$D" -f 2`
|
||||
#echo "token=$token, str_temp_value=$str_temp_value"
|
||||
old_ifs=$IFS
|
||||
IFS=$'|'
|
||||
nic_params_temp=($str_temp_value)
|
||||
array_nic_params=($str_temp_value)
|
||||
IFS=$old_ifs
|
||||
j=0
|
||||
while [ $j -lt ${#nic_params_temp[@]} ]
|
||||
do
|
||||
#token1="${nic_params_temp[$j]}"
|
||||
#echo "token1=$token1"
|
||||
old_ifs=$IFS
|
||||
IFS=$' '
|
||||
params_temp=(${nic_params_temp[$j]})
|
||||
IFS=$old_ifs
|
||||
k=0
|
||||
while [ $k -lt ${#params_temp[@]} ]
|
||||
do
|
||||
token2="${params_temp[$k]}"
|
||||
key=`echo "$token2" | cut -d'=' -f 1`
|
||||
value=`echo "$token2" | cut -d'=' -f 2`
|
||||
#echo "key=$key, value=$value"
|
||||
if [ "$key" = "mtu" ] || [ "$key" = "MTU" ]; then
|
||||
array_nic_mtu[$j]=$value
|
||||
fi
|
||||
k=$((k+1))
|
||||
done
|
||||
if [[ -z "${array_nic_mtu[$j]}" ]]; then
|
||||
array_nic_mtu[$j]=$str_default_token
|
||||
fi
|
||||
j=$((j+1))
|
||||
done
|
||||
return
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
}
|
||||
|
||||
# This functions parse the extra parameters for an ip address of a nic
|
||||
# Input is like this:
|
||||
# MTU=65520 something=yes
|
||||
# After the function is called:
|
||||
# array_extra_param_names[0]="MTU"
|
||||
# array_extra_param_values[0]="65520"
|
||||
# array_extra_param_names[1]="something"
|
||||
# array_extra_param_values[0]="yes"
|
||||
#
|
||||
function parse_nic_extra_params() {
|
||||
str_extra=$1
|
||||
|
||||
unset array_extra_param_names
|
||||
unset array_extra_param_values
|
||||
|
||||
old_ifs=$IFS
|
||||
IFS=$' '
|
||||
params_temp=($str_extra)
|
||||
IFS=$old_ifs
|
||||
k=0
|
||||
while [ $k -lt ${#params_temp[@]} ]
|
||||
do
|
||||
token2="${params_temp[$k]}"
|
||||
array_extra_param_names[$k]=`echo "$token2" | cut -d'=' -f 1`
|
||||
array_extra_param_values[$k]=`echo "$token2" | cut -d'=' -f 2`
|
||||
k=$((k+1))
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
if [ "$(uname -s|tr 'A-Z' 'a-z')" = "linux" ];then
|
||||
str_dir_name=`dirname $0`
|
||||
. $str_dir_name/xcatlib.sh
|
||||
@ -79,7 +94,12 @@ function configipv4(){
|
||||
str_v4net=$3
|
||||
str_v4mask=$4
|
||||
num_v4num=$5
|
||||
str_mtu=$6
|
||||
str_extra_params=$6
|
||||
|
||||
#parse the extra parameters
|
||||
if [ "$str_extra_params" != "$str_default_token" ]; then
|
||||
parse_nic_extra_params "$str_extra_params"
|
||||
fi
|
||||
|
||||
if [ "$str_os_type" = "sles" ];then
|
||||
str_conf_file="/etc/sysconfig/network/ifcfg-${str_if_name}"
|
||||
@ -92,17 +112,33 @@ function configipv4(){
|
||||
echo "STARTMODE=onboot" >> $str_conf_file
|
||||
echo "USERCONTROL=no" >> $str_conf_file
|
||||
echo "_nm_name=static-0" >> $str_conf_file
|
||||
if [ "$str_mtu" != "$str_default_token" ]; then
|
||||
echo "MTU=${str_mtu}" >> $str_conf_file
|
||||
fi
|
||||
|
||||
#add extra params
|
||||
i=0
|
||||
while [ $i -lt ${#array_extra_param_names[@]} ]
|
||||
do
|
||||
name="${array_extra_param_names[$i]}"
|
||||
value="${array_extra_param_values[$i]}"
|
||||
echo " $i: name=$name value=$value"
|
||||
echo "${name}=${value}" >> $str_conf_file
|
||||
i=$((i+1))
|
||||
done
|
||||
else
|
||||
echo "IPADDR_${num_v4num}=${str_v4ip}" >> $str_conf_file
|
||||
echo "NETMASK_${num_v4num}=${str_v4mask}" >> $str_conf_file
|
||||
echo "NETWORK_${num_v4num}=${str_v4net}" >> $str_conf_file
|
||||
echo "LABEL_${num_v4num}=${num_v4num}" >> $str_conf_file
|
||||
if [ "$str_mtu" != "$str_default_token" ]; then
|
||||
echo "MTU_${num_v4num}=${str_mtu}" >> $str_conf_file
|
||||
fi
|
||||
|
||||
#add extra params
|
||||
i=0
|
||||
while [ $i -lt ${#array_extra_param_names[@]} ]
|
||||
do
|
||||
name="${array_extra_param_names[$i]}"
|
||||
value="${array_extra_param_values[$i]}"
|
||||
echo " $i: name=$name value=$value"
|
||||
echo "${name}=${value}" >> $str_conf_file
|
||||
i=$((i+1))
|
||||
done
|
||||
fi
|
||||
|
||||
if [[ ${str_if_name} == [a-zA-Z0-9]*.[0-9]* ]]; then
|
||||
@ -121,9 +157,17 @@ function configipv4(){
|
||||
echo " address ${str_v4ip}" >> $str_conf_file
|
||||
echo " netmask ${str_v4mask}" >> $str_conf_file
|
||||
echo " network ${str_v4net}" >> $str_conf_file
|
||||
if [ "$str_mtu" != "$str_default_token" ]; then
|
||||
echo " mtu ${str_mtu}" >> $str_conf_file
|
||||
fi
|
||||
|
||||
#add extra params
|
||||
i=0
|
||||
while [ $i -lt ${#array_extra_param_names[@]} ]
|
||||
do
|
||||
name="${array_extra_param_names[$i]}"
|
||||
value="${array_extra_param_values[$i]}"
|
||||
echo " $i: name=$name value=$value"
|
||||
echo " ${name} ${value}" >> $str_conf_file
|
||||
i=$((i+1))
|
||||
done
|
||||
if [[ ${str_if_name} == [a-zA-Z0-9]*.[0-9]* ]]; then
|
||||
parent_device=`echo ${str_if_name} | sed -e 's/\([a-zA-Z0-9]*\)\.[0-9]*/\1/g'`
|
||||
echo " vlan-raw-device ${parent_device}" >> $str_conf_file
|
||||
@ -148,9 +192,17 @@ function configipv4(){
|
||||
if [[ ${str_if_name} == [a-zA-Z0-9]*.[0-9]* ]]; then
|
||||
echo "VLAN=yes" >> $str_conf_file
|
||||
fi
|
||||
if [ "$str_mtu" != "$str_default_token" ]; then
|
||||
echo "MTU=${str_mtu}" >> $str_conf_file
|
||||
fi
|
||||
|
||||
#add extra params
|
||||
i=0
|
||||
while [ $i -lt ${#array_extra_param_names[@]} ]
|
||||
do
|
||||
name="${array_extra_param_names[$i]}"
|
||||
value="${array_extra_param_values[$i]}"
|
||||
echo " $i: name=$name value=$value"
|
||||
echo "${name}=${value}" >> $str_conf_file
|
||||
i=$((i+1))
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
@ -162,8 +214,12 @@ configipv6(){
|
||||
num_v6num=$5
|
||||
num_v4num=$6
|
||||
str_v6gateway=$7
|
||||
str_mtu=$8
|
||||
str_extra_params=$8
|
||||
|
||||
#parse the extra parameters
|
||||
if [ "$str_extra_params" != "$str_default_token" ]; then
|
||||
parse_nic_extra_params "$str_extra_params"
|
||||
fi
|
||||
|
||||
#remove the prefix length from the subnet
|
||||
str_v6net=`echo $str_v6net | cut -d"/" -f 1`
|
||||
@ -188,9 +244,17 @@ configipv6(){
|
||||
echo "default $str_v6gateway - -" >> /etc/sysconfig/network/routes
|
||||
fi
|
||||
fi
|
||||
if [ "$str_mtu" != "$str_default_token" ]; then
|
||||
echo "MTU=${str_mtu}" >> $str_conf_file
|
||||
fi
|
||||
|
||||
#add extra params
|
||||
i=0
|
||||
while [ $i -lt ${#array_extra_param_names[@]} ]
|
||||
do
|
||||
name="${array_extra_param_names[$i]}"
|
||||
value="${array_extra_param_values[$i]}"
|
||||
echo " $i: name=$name value=$value"
|
||||
echo "${name}=${value}" >> $str_conf_file
|
||||
i=$((i+1))
|
||||
done
|
||||
elif [ "$str_os_type" = "debian" ];then
|
||||
#debian or ubuntu
|
||||
str_conf_file="/etc/network/interfaces.d/${str_if_name}"
|
||||
@ -205,9 +269,17 @@ configipv6(){
|
||||
if [ "$str_v6gateway" != "$str_default_token" ]; then
|
||||
echo " gateway ${str_v6gateway}" >> $str_conf_file
|
||||
fi
|
||||
if [ "$str_mtu" != "$str_default_token" ]; then
|
||||
echo " mtu ${str_mtu}" >> $str_conf_file
|
||||
fi
|
||||
|
||||
#add extra params
|
||||
i=0
|
||||
while [ $i -lt ${#array_extra_param_names[@]} ]
|
||||
do
|
||||
name="${array_extra_param_names[$i]}"
|
||||
value="${array_extra_param_values[$i]}"
|
||||
echo " $i: name=$name value=$value"
|
||||
echo " ${name} ${value}" >> $str_conf_file
|
||||
i=$((i+1))
|
||||
done
|
||||
else
|
||||
echo " post-up /sbin/ifconfig ${str_if_name} inet6 add ${str_v6ip}/${str_v6prefix}" >> $str_conf_file
|
||||
echo " pre-down /sbin/ifconfig ${str_if_name} inet6 del ${str_v6ip}/${str_v6prefix}" >> $str_conf_file
|
||||
@ -230,9 +302,17 @@ configipv6(){
|
||||
if [ "$str_v6gateway" != "$str_default_token" ] -a [ `echo $str_v6gateway | grep -v 'xcatmaster'` ];then
|
||||
echo "IPV6_DEFAULTGW=$str_v6gateway" >> $str_conf_file
|
||||
fi
|
||||
if [ "$str_mtu" != "$str_default_token" ]; then
|
||||
echo "MTU=${str_mtu}" >> $str_conf_file
|
||||
fi
|
||||
|
||||
#add extra params
|
||||
i=0
|
||||
while [ $i -lt ${#array_extra_param_names[@]} ]
|
||||
do
|
||||
name="${array_extra_param_names[$i]}"
|
||||
value="${array_extra_param_values[$i]}"
|
||||
echo " $i: name=$name value=$value"
|
||||
echo "${name}=${value}" >> $str_conf_file
|
||||
i=$((i+1))
|
||||
done
|
||||
fi
|
||||
}
|
||||
|
||||
@ -312,9 +392,15 @@ function add_ip_temporary(){
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
declare -a array_nic_params
|
||||
declare -a array_extra_param_names
|
||||
declare -a array_extra_param_values
|
||||
|
||||
# This token is used for the value of an attributes that has not been assigned any value.
|
||||
str_default_token="default"
|
||||
|
||||
|
||||
str_nic_name=''
|
||||
str_os_type=`uname | tr 'A-Z' 'a-z'`
|
||||
str_cfg_dir=''
|
||||
@ -338,6 +424,7 @@ else
|
||||
|
||||
fi
|
||||
|
||||
|
||||
logger -t xcat -p local4.err "configeth: os type: $str_os_type"
|
||||
echo "configeth on $NODE: os type: $str_os_type"
|
||||
if [ "$1" = "-r" ];then
|
||||
@ -404,6 +491,7 @@ elif [ "$1" = "-s" ];then
|
||||
str_inst_ip=''
|
||||
str_inst_mask=''
|
||||
str_inst_gateway=''
|
||||
|
||||
if [ "$str_os_type" = "aix" ];then
|
||||
logger -t xcat -p local4.err "configeth: aix does not support -s flag"
|
||||
echo "configeth on $NODE: aix does not support -s flag"
|
||||
@ -443,6 +531,14 @@ elif [ "$1" = "-s" ];then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
#get extra configration parameters for each nic
|
||||
#echo "str_inst_nic=$str_inst_nic, str_inst_ip=$str_inst_ip"
|
||||
get_nic_extra_params $str_inst_nic
|
||||
if [ ${#array_nic_params[@]} -gt 0 ]; then
|
||||
str_extra_params=${array_nic_params[0]}
|
||||
parse_nic_extra_params "$str_extra_params"
|
||||
fi
|
||||
|
||||
if [ -f "/etc/debian_version" ];then
|
||||
str_conf_file="/etc/network/interfaces.d/${str_inst_nic}"
|
||||
echo "auto ${str_inst_nic}" > $str_conf_file
|
||||
@ -453,6 +549,17 @@ elif [ "$1" = "-s" ];then
|
||||
if [ -n "$str_inst_gateway" ];then
|
||||
echo " gateway $str_inst_gateway" >> $str_conf_file
|
||||
fi
|
||||
#add extra params
|
||||
i=0
|
||||
while [ $i -lt ${#array_extra_param_names[@]} ]
|
||||
do
|
||||
name="${array_extra_param_names[$i]}"
|
||||
value="${array_extra_param_values[$i]}"
|
||||
echo " $i: name=$name value=$value"
|
||||
echo " ${name} ${value}" >> $str_conf_file
|
||||
i=$((i+1))
|
||||
done
|
||||
|
||||
hostname $NODE
|
||||
echo $NODE > /etc/hostname
|
||||
elif [ -f "/etc/SuSE-release" ];then
|
||||
@ -472,6 +579,18 @@ elif [ "$1" = "-s" ];then
|
||||
fi
|
||||
fi
|
||||
|
||||
#add extra params
|
||||
i=0
|
||||
while [ $i -lt ${#array_extra_param_names[@]} ]
|
||||
do
|
||||
name="${array_extra_param_names[$i]}"
|
||||
value="${array_extra_param_values[$i]}"
|
||||
echo " $i: name=$name value=$value"
|
||||
echo "${name}=${value}" >> $str_conf_file
|
||||
i=$((i+1))
|
||||
done
|
||||
|
||||
|
||||
hostname $NODE
|
||||
echo $NODE > /etc/HOSTNAME
|
||||
else
|
||||
@ -490,6 +609,18 @@ elif [ "$1" = "-s" ];then
|
||||
echo "GATEWAY=${str_inst_gateway}" >> /etc/sysconfig/network
|
||||
fi
|
||||
fi
|
||||
|
||||
#add extra params
|
||||
i=0
|
||||
while [ $i -lt ${#array_extra_param_names[@]} ]
|
||||
do
|
||||
name="${array_extra_param_names[$i]}"
|
||||
value="${array_extra_param_values[$i]}"
|
||||
echo " $i: name=$name value=$value"
|
||||
echo "${name}=${value}" >> $str_conf_file
|
||||
i=$((i+1))
|
||||
done
|
||||
|
||||
hostname $NODE
|
||||
if [ -f "/etc/hostname" ]; then
|
||||
echo $NODE > /etc/hostname
|
||||
@ -533,6 +664,7 @@ fi
|
||||
logger -t xcat -p local4.err "configeth: old configuration: $str_temp"
|
||||
echo "configeth on $NODE: old configuration: $str_temp"
|
||||
|
||||
|
||||
#parse the networks tables contains
|
||||
declare -a array_ip_mask
|
||||
declare -a array_ip_status
|
||||
@ -540,7 +672,17 @@ declare -a array_nic_network_config
|
||||
declare -a array_nic_subnet
|
||||
declare -a array_nic_netmask
|
||||
declare -a array_nic_gateway
|
||||
declare -a array_nic_mtu
|
||||
|
||||
#get extra configration parameters for each nic
|
||||
get_nic_extra_params $str_nic_name
|
||||
j=0
|
||||
while [ $j -lt ${#array_nic_params[@]} ]
|
||||
do
|
||||
token1="${array_nic_params[$j]}"
|
||||
echo "array_nic_params $j=$token1"
|
||||
j=$((j+1))
|
||||
done
|
||||
|
||||
|
||||
str_ip_mask_pair=''
|
||||
num_index=1
|
||||
@ -559,9 +701,6 @@ while [ $num_index -le $NETWORKS_LINES ];do
|
||||
num_index=$((num_index+1))
|
||||
done
|
||||
|
||||
#get extra configration parameters for each nic
|
||||
get_nic_extra_params $str_nic_name
|
||||
|
||||
logger -t xcat -p local4.err "configeth: new configuration"
|
||||
echo "configeth on $NODE: new configuration"
|
||||
num_index=0
|
||||
@ -764,16 +903,12 @@ else
|
||||
bool_modify_flag=1
|
||||
fi
|
||||
|
||||
#check if mtu value has been changed or not
|
||||
new_mtu=${array_nic_mtu[0]}
|
||||
if [ "$new_mtu" != "$str_default_token" ]; then
|
||||
old_mtu=`ip addr show dev $str_nic_name | grep mtu | awk '{print $5}'`
|
||||
#echo "old=$old_mtu, new=$new_mtu"
|
||||
if [ "$new_mtu" != "$old_mtu" ]; then
|
||||
bool_restart_flag=1
|
||||
bool_modify_flag=1
|
||||
fi
|
||||
fi
|
||||
#check if there are extra param values have been set or not
|
||||
#if set, always restart the the nic
|
||||
if [ ${#array_nic_params[@]} -gt 0 ]; then
|
||||
bool_restart_flag=1
|
||||
bool_modify_flag=1
|
||||
fi
|
||||
|
||||
if [ $bool_restart_flag = 0 ];then
|
||||
#add the new defined ip
|
||||
@ -843,7 +978,11 @@ else
|
||||
str_subnet=${array_nic_subnet[$num_index]}
|
||||
str_netmask=${array_nic_netmask[$num_index]}
|
||||
str_gateway=${array_nic_gateway[$num_index]}
|
||||
str_mtu=${array_nic_mtu[$num_index]}
|
||||
if [ $num_index -lt ${#array_nic_params[@]} ]; then
|
||||
str_extra_params=${array_nic_params[$num_index]}
|
||||
else
|
||||
str_extra_params=$str_default_token
|
||||
fi
|
||||
|
||||
# make sure each parameter has a value
|
||||
if [[ -z "$str_gateway" ]]; then
|
||||
@ -857,10 +996,10 @@ else
|
||||
|
||||
|
||||
if [ `echo $str_ip | grep -E '^([0-9]{1,3}\.){3}[0-9]{1,3}$'` ];then
|
||||
configipv4 $str_nic_name $str_ip $str_subnet $str_netmask $num_ipv4_index $str_mtu
|
||||
configipv4 $str_nic_name $str_ip $str_subnet $str_netmask $num_ipv4_index "$str_extra_params"
|
||||
num_ipv4_index=$((num_ipv4_index+1))
|
||||
elif [ `echo $str_ip | grep -E ":"` ];then
|
||||
configipv6 $str_nic_name $str_ip $str_subnet $str_netmask $num_ipv6_index $num_ipv4_index $str_gateway $str_mtu
|
||||
configipv6 $str_nic_name $str_ip $str_subnet $str_netmask $num_ipv6_index $num_ipv4_index $str_gateway "$str_extra_params"
|
||||
num_ipv6_index=$((num_ipv6_index+1))
|
||||
else
|
||||
num_index=$((num_index+1))
|
||||
|
@ -61,14 +61,15 @@ convert_netmask_to_cidr() {
|
||||
echo $cidrnum
|
||||
}
|
||||
|
||||
|
||||
# The extra parameter are specified in the nics.nicextraparams.
|
||||
# It has the following format:
|
||||
# eth2!MTU=65520 CONNECTED_MODE=yes,eth3!MTU=1500
|
||||
# This function gets the values for the given nic,
|
||||
# It stores each parameter values in a separate array.
|
||||
# This function parse the NICEXTRAPARAMS into an array.
|
||||
# Each arry element contains all the extra params for an ip
|
||||
# For example:
|
||||
# NICEXTRAPARAMS="eth0!MTU=1500 sonething=x|MTU=1460,ib0!MTU=65520 CONNECTED_MODE=yes".
|
||||
# After calling this function with eth0:
|
||||
# array_extra_param[0]="MTU=1500 sonething=x"
|
||||
# array_extra_param[1]="MTU=1460"
|
||||
function get_nic_extra_params() {
|
||||
nic_temp=$1
|
||||
nic=$1
|
||||
if [ ! "$NICEXTRAPARAMS" ];then
|
||||
return
|
||||
fi
|
||||
@ -76,6 +77,7 @@ function get_nic_extra_params() {
|
||||
IFS=$','
|
||||
array_conf_temp=($NICEXTRAPARAMS)
|
||||
IFS=$old_ifs
|
||||
#echo "NICEXTRA=$NICEXTRAPARAMS"
|
||||
|
||||
i=0
|
||||
while [ $i -lt ${#array_conf_temp[@]} ]
|
||||
@ -88,49 +90,49 @@ function get_nic_extra_params() {
|
||||
D=":"
|
||||
fi
|
||||
key=`echo "$token" | cut -d"$D" -f 1`
|
||||
if [ "$key" == "$nic_temp" ]; then
|
||||
#echo "key=$key nic=$nic"
|
||||
if [ "$key" == "$nic" ]; then
|
||||
str_temp_value=`echo "$token" | cut -d"$D" -f 2`
|
||||
#echo "token=$token, str_temp_value=$str_temp_value"
|
||||
old_ifs=$IFS
|
||||
IFS=$'|'
|
||||
nic_params_temp=($str_temp_value)
|
||||
array_nic_params=($str_temp_value)
|
||||
IFS=$old_ifs
|
||||
j=0
|
||||
while [ $j -lt ${#nic_params_temp[@]} ]
|
||||
do
|
||||
#token1="${nic_params_temp[$j]}"
|
||||
#echo "token1=$token1"
|
||||
old_ifs=$IFS
|
||||
IFS=$' '
|
||||
params_temp=(${nic_params_temp[$j]})
|
||||
IFS=$old_ifs
|
||||
k=0
|
||||
while [ $k -lt ${#params_temp[@]} ]
|
||||
do
|
||||
token2="${params_temp[$k]}"
|
||||
key=`echo "$token2" | cut -d'=' -f 1`
|
||||
value=`echo "$token2" | cut -d'=' -f 2`
|
||||
#echo "key=$key, value=$value"
|
||||
if [ "$key" = "mtu" ] || [ "$key" = "MTU" ]; then
|
||||
array_nic_mtu[$j]=$value
|
||||
elif [ "$key" = "connected_mode" ] || [ "$key" = "CONNECTED_MODE" ]; then
|
||||
array_nic_connected[$j]=$value
|
||||
fi
|
||||
k=$((k+1))
|
||||
done
|
||||
if [[ -z "${array_nic_mtu[$j]}" ]]; then
|
||||
array_nic_mtu[$j]=$str_default_token
|
||||
fi
|
||||
if [[ -z "${array_nic_connected[$j]}" ]]; then
|
||||
array_nic_connected[$j]=$str_default_token
|
||||
fi
|
||||
j=$((j+1))
|
||||
done
|
||||
return
|
||||
fi
|
||||
i=$((i+1))
|
||||
done
|
||||
}
|
||||
|
||||
# This functions parse the extra parameters for an ip address of a nic
|
||||
# Input is like this:
|
||||
# MTU=65520 something=yes
|
||||
# After the function is called:
|
||||
# array_extra_param_names[0]="MTU"
|
||||
# array_extra_param_values[0]="65520"
|
||||
# array_extra_param_names[1]="something"
|
||||
# array_extra_param_values[0]="yes"
|
||||
#
|
||||
function parse_nic_extra_params() {
|
||||
str_extra=$1
|
||||
|
||||
unset array_extra_param_names
|
||||
unset array_extra_param_values
|
||||
|
||||
old_ifs=$IFS
|
||||
IFS=$' '
|
||||
params_temp=($str_extra)
|
||||
IFS=$old_ifs
|
||||
k=0
|
||||
while [ $k -lt ${#params_temp[@]} ]
|
||||
do
|
||||
token2="${params_temp[$k]}"
|
||||
array_extra_param_names[$k]=`echo "$token2" | cut -d'=' -f 1`
|
||||
array_extra_param_values[$k]=`echo "$token2" | cut -d'=' -f 2`
|
||||
k=$((k+1))
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
#if $NIC_IBNICS is not defined, all ib nics' configuration files will be deleted.
|
||||
if [ -z "$NIC_IBNICS" ]; then
|
||||
@ -291,10 +293,9 @@ else
|
||||
fi
|
||||
|
||||
|
||||
declare -a array_nic_mtu
|
||||
declare -a array_nic_connected
|
||||
# This token is used for the value of an attributes that has not been assigned any value.
|
||||
str_default_token="default"
|
||||
declare -a array_nic_params
|
||||
declare -a array_extra_param_names
|
||||
declare -a array_extra_param_values
|
||||
|
||||
goodnics=""
|
||||
for nic in `echo "$NIC_IBNICS" | tr "," "\n"`
|
||||
@ -331,9 +332,17 @@ do
|
||||
continue
|
||||
fi
|
||||
|
||||
array_nic_mtu=()
|
||||
array_nic_connected=()
|
||||
unset array_nic_params
|
||||
unset array_extra_param_names
|
||||
unset array_extra_param_values
|
||||
get_nic_extra_params $nic
|
||||
j=0
|
||||
while [ $j -lt ${#array_nic_params[@]} ]
|
||||
do
|
||||
token1="${array_nic_params[$j]}"
|
||||
echo "array_nic_params $j=$token1"
|
||||
j=$((j+1))
|
||||
done
|
||||
|
||||
ipindex=0
|
||||
for nicip in `echo $nicips | tr "|" "\n"`
|
||||
@ -407,8 +416,10 @@ do
|
||||
gateway=''
|
||||
fi
|
||||
|
||||
str_mtu=${array_nic_mtu[$ipindex-1]}
|
||||
str_connect_mode=${array_nic_connected[$ipindex-1]}
|
||||
if [ ${#array_nic_params[@]} -gt 0 ]; then
|
||||
str_extra_params=${array_nic_params[$ipindex-1]}
|
||||
parse_nic_extra_params "$str_extra_params"
|
||||
fi
|
||||
|
||||
if [ $PLTFRM == "Linux" ]
|
||||
then
|
||||
@ -459,12 +470,17 @@ IPADDR=$nicip" > $dir/ifcfg-$nic
|
||||
echo "default $gateway - -" >> /etc/sysconfig/network/routes
|
||||
fi
|
||||
fi
|
||||
if [ -n "$str_mtu" -a "$str_mtu" != "$str_default_token" ]; then
|
||||
echo "MTU=${str_mtu}" >> $dir/ifcfg-$nic
|
||||
fi
|
||||
if [ -n "$str_connect_mode" -a "$str_connect_mode" != "$str_default_token" ]; then
|
||||
echo "CONNECTED_MODE=${str_connect_mode}" >> $dir/ifcfg-$nic
|
||||
fi
|
||||
|
||||
#add extra params
|
||||
i=0
|
||||
while [ $i -lt ${#array_extra_param_names[@]} ]
|
||||
do
|
||||
name="${array_extra_param_names[$i]}"
|
||||
value="${array_extra_param_values[$i]}"
|
||||
echo " $i: name=$name value=$value"
|
||||
echo "${name}=${value}" >> $dir/ifcfg-$nic
|
||||
i=$((i+1))
|
||||
done
|
||||
else # not the first ip address
|
||||
echo "LABEL_$ipindex=$ipindex
|
||||
IPADDR_$ipindex=$nicip" >> $dir/ifcfg-$nic
|
||||
@ -482,6 +498,16 @@ IPADDR_$ipindex=$nicip" >> $dir/ifcfg-$nic
|
||||
echo "default $gateway - -" >> /etc/sysconfig/network/routes
|
||||
fi
|
||||
fi
|
||||
#add extra params
|
||||
i=0
|
||||
while [ $i -lt ${#array_extra_param_names[@]} ]
|
||||
do
|
||||
name="${array_extra_param_names[$i]}"
|
||||
value="${array_extra_param_values[$i]}"
|
||||
echo " $i: name=$name value=$value"
|
||||
echo "${name}=${value}" >> $dir/ifcfg-$nic
|
||||
i=$((i+1))
|
||||
done
|
||||
fi # end if [ $ipindex -eq 1 ]
|
||||
elif [ $OS_name == 'redhat' ]
|
||||
then
|
||||
@ -512,12 +538,18 @@ IPADDR=$nicip" > $dir/ifcfg-$nic
|
||||
if [ -n "$gateway" ]; then
|
||||
echo "GATEWAY=$gateway" >> $dir/ifcfg-$nic
|
||||
fi
|
||||
if [ -n "$str_mtu" -a "$str_mtu" != "$str_default_token" ]; then
|
||||
echo "MTU=${str_mtu}" >> $dir/ifcfg-$nic
|
||||
fi
|
||||
if [ -n "$str_connect_mode" -a "$str_connect_mode" != "$str_default_token" ]; then
|
||||
echo "CONNECTED_MODE=${str_connect_mode}" >> $dir/ifcfg-$nic
|
||||
fi
|
||||
|
||||
|
||||
#add extra params
|
||||
i=0
|
||||
while [ $i -lt ${#array_extra_param_names[@]} ]
|
||||
do
|
||||
name="${array_extra_param_names[$i]}"
|
||||
value="${array_extra_param_values[$i]}"
|
||||
echo " $i: name=$name value=$value"
|
||||
echo "${name}=${value}" >> $dir/ifcfg-$nic
|
||||
i=$((i+1))
|
||||
done
|
||||
else # not the first ip address
|
||||
# ipv6
|
||||
if echo $nicip | grep : 2>&1 1>/dev/null
|
||||
@ -553,12 +585,18 @@ IPADDR=$nicip" > $dir/ifcfg-$nic:$ipindex
|
||||
if [ -n "$gateway" ]; then
|
||||
echo "GATEWAY=$gateway" >> $dir/ifcfg-$nic:$ipindex
|
||||
fi
|
||||
if [ -n "$str_mtu" -a "$str_mtu" != "$str_default_token" ]; then
|
||||
echo "MTU=${str_mtu}" >> $dir/ifcfg-$nic:$ipindex
|
||||
fi
|
||||
if [ -n "$str_connect_mode" -a "$str_connect_mode" != "$str_default_token" ]; then
|
||||
echo "CONNECTED_MODE=${str_connect_mode}" >> $dir/ifcfg-$nic:$ipindex
|
||||
fi
|
||||
|
||||
#add extra params
|
||||
i=0
|
||||
while [ $i -lt ${#array_extra_param_names[@]} ]
|
||||
do
|
||||
name="${array_extra_param_names[$i]}"
|
||||
value="${array_extra_param_values[$i]}"
|
||||
echo " $i: name=$name value=$value"
|
||||
echo "${name}=${value}" >> $dir/ifcfg-$nic:$ipindex
|
||||
i=$((i+1))
|
||||
done
|
||||
|
||||
# need to run ifup eth1:1 for RedHat
|
||||
goodnics="$goodnics,$nic:$ipindex"
|
||||
fi
|
||||
@ -613,13 +651,17 @@ netmask $netmask" >> /etc/network/interfaces
|
||||
#fi
|
||||
fi
|
||||
|
||||
if [ -n "$str_mtu" -a "$str_mtu" != "$str_default_token" ]; then
|
||||
echo "mtu ${str_mtu}" >> /etc/network/interfaces
|
||||
fi
|
||||
if [ -n "$str_connect_mode" -a "$str_connect_mode" != "$str_default_token" ]; then
|
||||
echo "connected_mode ${str_connect_mode}" >> /etc/network/interfaces
|
||||
fi
|
||||
fi
|
||||
#add extra params
|
||||
i=0
|
||||
while [ $i -lt ${#array_extra_param_names[@]} ]
|
||||
do
|
||||
name="${array_extra_param_names[$i]}"
|
||||
value="${array_extra_param_values[$i]}"
|
||||
echo " $i: name=$name value=$value"
|
||||
echo "${name} ${value}" >> /etc/network/interfaces
|
||||
i=$((i+1))
|
||||
done
|
||||
fi
|
||||
else
|
||||
echo "Unsupported operating system"
|
||||
logger -p local4.err -t xcat "Unsupported operating system"
|
||||
|
Loading…
Reference in New Issue
Block a user