diff --git a/xCAT/postscripts/configbond b/xCAT/postscripts/configbond index b709b1268..af08b64d2 100755 --- a/xCAT/postscripts/configbond +++ b/xCAT/postscripts/configbond @@ -33,6 +33,79 @@ # NETWORKS_LINE1=netname=10_0_0_0-255_255_255_0||net=10.0.0.0||mask=255.255.255.0||mgtifname=eth1||gateway=||dhcpserver=||tftpserver=10.0.0.10||nameservers=||ntpservers=||logservers=||dynamicrange=||staticrange=||staticrangeincrement=||nodehostname=||ddnsdomain=||vlanid=||domain=||disable=||comments= # NETWORKS_LINE2=netname=10_0_2_0-255_255_255_0||net=10.0.2.0||mask=255.255.255.0||mgtifname=eth0||gateway=10.0.2.2||dhcpserver=||tftpserver=10.0.2.15||nameservers=||ntpservers=||logservers=||dynamicrange=||staticrange=||staticrangeincrement=||nodehostname=||ddnsdomain=||vlanid=||domain=||disable=||comments= +# 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 + return + fi + old_ifs=$IFS + IFS=$',' + array_conf_temp=($NICEXTRAPARAMS) + IFS=$old_ifs + #echo "NICEXTRA=$NICEXTRAPARAMS" + + i=0 + while [ $i -lt ${#array_conf_temp[@]} ] + do + token="${array_conf_temp[$i]}" + D= + if echo "$token" | grep "!"; then + D="!" + else + 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=$'|' + array_nic_params=($str_temp_value) + IFS=$old_ifs + 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[1]="yes" +# +function parse_nic_extra_params() { + str_extra=$1 + + unset array_extra_param_names + unset array_extra_param_values + + echo $str_extra + + 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 +} # load library for network caculation if [ "$(uname -s|tr 'A-Z' 'a-z')" = "linux" ];then @@ -55,6 +128,10 @@ function showmsg() { echo $msg } +declare -a array_nic_params +declare -a array_extra_param_names +declare -a array_extra_param_values + # Check OS version and get the directory of network configuration file str_bond_name='' str_os_type=`uname | tr 'A-Z' 'a-z'` @@ -146,6 +223,14 @@ else done fi +get_nic_extra_params $str_bond_name + +if [ ${#array_nic_params[@]} -gt 0 ]; then + str_extra_params=${array_nic_params[0]} + parse_nic_extra_params "$str_extra_params" +fi + + # remove the left part from |. that means only keeping the first ip in the interface if there are alias ip str_bond_ip=${str_bond_ip%%|*} @@ -196,8 +281,60 @@ NETMASK=${str_bond_mask} ONBOOT=yes USERCTL=no BONDING_OPTS="${array_bond_opts[*]}" +NM_CONTROLLED=no EOF + + #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_master_file + i=$((i+1)) + done + + if [[ ${str_bond_name} == [a-zA-Z0-9]*.[0-9]* ]]; then + echo "VLAN=yes" >> $str_master_file + + str_parent_device=`echo ${str_bond_name} | sed -e 's/\([a-zA-Z0-9]*\)\.[0-9]*/\1/g'` + str_parent_file=`echo ${str_cfg_dir}/ifcfg-${str_bond_name} | sed -e 's/\([a-zA-Z0-9]*\)\.[0-9]*/\1/g'` + + if [[ ! -e ${str_parent_file} ]] ; then + +get_nic_extra_params $str_parent_device +if [ ${#array_nic_params[@]} -gt 0 ]; then + str_extra_params=${array_nic_params[0]} + parse_nic_extra_params "$str_extra_params" +fi + + cat > $str_parent_file <> $str_parent_file + i=$((i+1)) + done + + fi + + str_bond_name_old=${str_bond_name} + str_bond_name=${str_parent_device} + fi + # Create the slave files for slave in ${array_bond_slaves[*]}; do str_slave_file="${str_cfg_dir}/ifcfg-${slave}" @@ -208,6 +345,7 @@ SLAVE=yes BOOTPROTO=none ONBOOT=yes USERCTL=no +NM_CONTROLLED=no EOF done @@ -224,6 +362,17 @@ USERCONTROL=no BONDING_MODULE_OPTS="${array_bond_opts[*]}" EOF + #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_master_file + i=$((i+1)) + done + # Create the slave entries and files num_index=0 for slave in ${array_bond_slaves[*]}; do @@ -246,6 +395,7 @@ for slave in ${str_bond_name} ${array_bond_slaves[*]}; do done # Bring up bond device +[[ -n ${str_bond_name_old} ]] && $(ifup ${str_bond_name_old} &>/dev/null) $(ifup ${str_bond_name} &>/dev/null) if [ $? -ne 0 ]; then