diff --git a/xCAT/postscripts/configeth b/xCAT/postscripts/configeth index 80e2e5d56..98807699e 100755 --- a/xCAT/postscripts/configeth +++ b/xCAT/postscripts/configeth @@ -31,6 +31,12 @@ networkmanager_active=0 checkservicestatus NetworkManager > /dev/null if [ $? -eq 0 ]; then networkmanager_active=1 +else + #In RH8 postscripts stage, NetworkManager is active but nmcli cannot modify NIC configure file + ps -ef|grep -v grep|grep NetworkManager >/dev/null 2>/dev/null + if [ $? -eq 0 ]; then + networkmanager_active=2 + fi fi str_conf_file="" str_conf_file_xcatbak="" @@ -40,7 +46,7 @@ function configipv4(){ str_v4ip=$2 str_v4net=$3 str_v4mask=$4 - num_v4num=$5 + num_v4num=$5 #If NIC has multiple IPs, the ordinal number of IP is num_v4num str_extra_params=$6 str_nic_mtu=$7 @@ -131,18 +137,45 @@ function configipv4(){ # Write the info to the ifcfg file for redhat con_name="xcat-"${str_if_name} str_conf_file="" - if [ $num_v4num -ne 0 ]; then - str_if_name=${str_if_name}:${num_v4num} - fi - str_conf_file="/etc/sysconfig/network-scripts/ifcfg-${str_if_name}" if [ $networkmanager_active -eq 1 ]; then - is_nmcli_connection_exist $con_name - if [ $? -eq 0 ]; then - tmp_con_name=$con_name"-tmp" - nmcli con modify $con_name connection.id $tmp_con_name + if [ $num_v4num -eq 0 ]; then + is_nmcli_connection_exist $con_name + if [ $? -eq 0 ]; then + tmp_con_name=$con_name"-tmp" + nmcli con modify $con_name connection.id $tmp_con_name + fi + nmcli con add type ethernet con-name $con_name ifname ${str_if_name} ipv4.method manual ipv4.addresses ${str_v4ip}/${str_prefix} connection.autoconnect-priority 9 + else + nmcli con modify $con_name +ipv4.addresses ${str_v4ip}/${str_prefix} fi - nmcli con add type ethernet con-name $con_name ifname ${str_if_name} ipv4.method manual ipv4.addresses ${str_v4ip}/${str_prefix} connection.autoconnect-priority 9 + str_conf_file="/etc/sysconfig/network-scripts/ifcfg-xcat-${str_if_name}" + str_conf_file_1="/etc/sysconfig/network-scripts/ifcfg-xcat-${str_if_name}-1" + if [ -f $str_conf_file_1 ]; then + grep -x "NAME=$con_name" $str_conf_file_1 >/dev/null 2>/dev/null + if [ $? -eq 0 ]; then + str_conf_file=$str_conf_file_1 + fi + fi + elif [ $networkmanager_active -eq 2 ]; then + str_conf_file="/etc/sysconfig/network-scripts/ifcfg-xcat-${str_if_name}" + if [ $num_v4num -eq 0 ]; then + echo "DEVICE=${str_if_name}" > $str_conf_file + echo "BOOTPROTO=none" >> $str_conf_file + echo "IPADDR=${str_v4ip}" >> $str_conf_file + echo "NETMASK=${str_v4mask}" >> $str_conf_file + echo "NAME=xcat-${str_if_name}" >> $str_conf_file + echo "ONBOOT=yes" >> $str_conf_file + echo "AUTOCONNECT_PRIORITY=9" >> $str_conf_file + else + echo "IPADDR$num_v4num=${str_v4ip}" >> $str_conf_file + echo "NETMASK$num_v4num=${str_v4mask}" >> $str_conf_file + fi else + #If using network service, the NIC alias device format is : like eth0:1 + if [ $num_v4num -ne 0 ]; then + str_if_name=${str_if_name}:${num_v4num} + fi + str_conf_file="/etc/sysconfig/network-scripts/ifcfg-${str_if_name}" echo "DEVICE=${str_if_name}" > $str_conf_file echo "BOOTPROTO=none" >> $str_conf_file echo "NM_CONTROLLED=no" >> $str_conf_file @@ -152,26 +185,23 @@ function configipv4(){ fi if [ "$str_nic_mtu" != "$str_default_token" ]; then if [ $networkmanager_active -eq 1 ]; then - nmcli con modify $con_name mtu $str_nic_mtu + nmcli con modify $con_name mtu $str_nic_mtu else echo "MTU=${str_nic_mtu}" >> $str_conf_file - fi + fi fi - if [[ ${str_if_name} == [a-zA-Z0-9]*.[0-9]* ]]; then echo "VLAN=yes" >> $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 + #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 "${name}=${value}" >> $str_conf_file + i=$((i+1)) + done fi } @@ -341,7 +371,7 @@ function add_ip_temporary(){ else str_label='' ip addr show dev $str_temp_name | grep inet | grep "global" | grep -v ':' | grep "${str_temp_name}" - if [ $? -eq 0 ];then + if [ $? -eq 0 ] && [ $networkmanager_active -eq 0 ]; then for num_i in {1..1000} do ip addr show dev $str_temp_name | grep inet | grep "global" | grep ":${num_i}" @@ -630,6 +660,9 @@ elif [ "$1" = "-s" ];then con_name="xcat-install-"${str_inst_nic} str_inst_prefix=$(v4mask2prefix ${str_inst_mask}) str_conf_file="/etc/sysconfig/network-scripts/ifcfg-${str_inst_nic}" + if [ $networkmanager_active -eq 2 ]; then + str_conf_file="/etc/sysconfig/network-scripts/ifcfg-xcat-install-${str_inst_nic}" + fi if [ $networkmanager_active -eq 1 ]; then is_nmcli_connection_exist "$con_name" if [ $? -eq 0 ]; then @@ -637,20 +670,31 @@ elif [ "$1" = "-s" ];then nmcli con modify $con_name connection.id $tmp_con_name fi nmcli con add type ethernet con-name $con_name ifname ${str_inst_nic} ipv4.method manual ipv4.addresses ${str_inst_ip}/${str_inst_prefix} connection.autoconnect-priority 9 + str_conf_file_1="/etc/sysconfig/network-scripts/ifcfg-xcat-${str_if_name}-1" + if [ -f $str_conf_file_1 ]; then + grep $con_name $str_conf_file_1 >/dev/null 2>/dev/null + if [ $? -eq 0 ]; then + $str_conf_file=$str_conf_file_1 + fi + fi else echo "DEVICE=${str_inst_nic}" > $str_conf_file echo "IPADDR=${str_inst_ip}" >> $str_conf_file echo "NETMASK=${str_inst_mask}" >> $str_conf_file echo "BOOTPROTO=none" >> $str_conf_file echo "ONBOOT=yes" >> $str_conf_file + echo "NAME=xcat-install-${str_inst_nic}" >> $str_conf_file echo "HWADDR=${str_inst_mac}" >> $str_conf_file fi + if [ $networkmanager_active -eq 2 ]; then + echo "AUTOCONNECT_PRIORITY=9" >> $str_conf_file + fi if [ -n "${str_inst_mtu}" ];then - if [ $networkmanager_active -eq 1 ]; then - nmcli con modify $con_name mtu ${str_inst_mtu} + if [ $networkmanager_active -eq 1 ]; then + nmcli con modify $con_name mtu ${str_inst_mtu} else echo "MTU=${str_inst_mtu}" >> $str_conf_file - fi + fi fi if [ -n "$str_inst_gateway" ];then grep -i "GATEWAY" /etc/sysconfig/network @@ -660,17 +704,16 @@ 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 + #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 @@ -692,9 +735,10 @@ elif [ "$1" = "-s" ];then else ip link set dev $str_inst_nic down fi - if [ $networkmanager_active -eq 1 ]; then + if [ $networkmanager_active -eq 1 ]; then + nmcli con reload nmcli con up $con_name - else + else ifup $str_inst_nic fi if [ $? -ne 0 ]; then @@ -1111,11 +1155,12 @@ else if [ $reboot_nic_bool -eq 1 ]; then if_state=0 echo "bring up ip" - if [ $networkmanager_active -eq 1 ]; then + if [ $networkmanager_active -eq 1 ]; then + nmcli con reload nmcli con up $con_name - else + else ifup $str_nic_name - fi + fi if [ $? -ne 0 ]; then if_state=$(wait_for_ifstate $str_nic_name UP 20 5) fi diff --git a/xCAT/postscripts/confignetwork b/xCAT/postscripts/confignetwork index 40f4d4ace..232d9890d 100755 --- a/xCAT/postscripts/confignetwork +++ b/xCAT/postscripts/confignetwork @@ -63,7 +63,9 @@ function get_nic_cfg_file_content { elif [ $is_debian -eq 1 ]; then cfg_file="$nwdir/${cfg_dev}" fi - if [ "$networkmanager_active" = "1" ]; then + #TODO:this is networkmanager_active=2 + ps -ef|grep -v grep|grep NetworkManager >/dev/null 2>/dev/null + if [ $? -eq 0 ]; then $ip address show dev ${cfg_dev}| $sed -e 's/^/[Ethernet] >> /g' | log_lines info else if [ -f $cfg_file ]; then @@ -568,7 +570,9 @@ function configure_nicdevice { else create_bridge_interface ifname=$nic_dev _brtype=$nic_dev_type _port=$base_nic_dev _pretype=$base_nic_type fi - elif [ "$networkmanager_active" = "1" ]; then + elif [ "$networkmanager_active" = "2" ]; then + create_bridge_interface ifname=$nic_dev _brtype=$nic_dev_type _port=$base_nic_dev _pretype=$base_nic_type + else create_bridge_interface_nmcli ifname=$nic_dev _brtype=$nic_dev_type _port=$base_nic_dev _pretype=$base_nic_type _ipaddr=$ipaddrs fi if [ $? -ne 0 ]; then @@ -585,9 +589,9 @@ function configure_nicdevice { vlanname=`echo "$nic_dev" | $sed -e 's/^\(.*\)vla\?n\?\([0-9]\+\)$/\1/'` fi ipaddrs=$(find_nic_ips $nic_dev) - if [ "$networkmanager_active" = "0" ]; then + if [ "$networkmanager_active" != "1" ]; then create_vlan_interface ifname=$vlanname vlanid=$vlanid - elif [ "$networkmanager_active" = "1" ]; then + else create_vlan_interface_nmcli ifname=$vlanname vlanid=$vlanid ipaddrs=$ipaddrs next_nic=$is_mid_device fi if [ $? -ne 0 ]; then @@ -596,9 +600,9 @@ function configure_nicdevice { fi #configure bond elif [ x"$nic_dev_type" = "xbond" ]; then - if [ "$networkmanager_active" = "0" ]; then + if [ "$networkmanager_active" != "1" ]; then create_bond_interface ifname=$nic_dev slave_ports=$base_nic_for_bond slave_type=$base_nic_type - elif [ "$networkmanager_active" = "1" ]; then + else create_bond_interface_nmcli bondname=$nic_dev slave_ports=$base_nic_for_bond slave_type=$base_nic_type _ipaddr=$ipaddrs next_nic=$is_mid_device fi if [ $? -ne 0 ]; then @@ -655,13 +659,15 @@ if [ $boot_install_nic -eq 1 ];then fi #check if using NetworkManager or network service -networkmanager_active=2 +networkmanager_active=3 check_NetworkManager_or_network_service is_active=$? if [ $is_active -eq 0 ]; then networkmanager_active=0 elif [ $is_active -eq 1 ]; then networkmanager_active=1 +elif [ $is_active -eq 2 ]; then + networkmanager_active=2 else exit 1 fi diff --git a/xCAT/postscripts/nicutils.sh b/xCAT/postscripts/nicutils.sh index 22f499f92..86acd954f 100755 --- a/xCAT/postscripts/nicutils.sh +++ b/xCAT/postscripts/nicutils.sh @@ -1691,6 +1691,7 @@ function create_vlan_interface_nmcli { local _netmask="" local _mtu="" local next_nic="" + rc=0 # in case it's on top of bond, we need to migrate ip from its # member vlan ports. # parser input arguments @@ -1750,9 +1751,14 @@ function create_vlan_interface_nmcli { tmp_con_name=$con_name"-tmp" $nmcli con modify $con_name connection.id $tmp_con_name fi - + #create VLAN connetion $nmcli con add type vlan con-name $con_name dev $ifname id $(( 10#$vlanid )) $_ipaddrs $_mtu connection.autoconnect-priority 9 log_info "create NetworkManager connection for $ifname.$vlanid" + + #add extra params + add_extra_params_nmcli $ifname.$vlanid $con_name + [ $? -ne 0 ] && rc=1 + if [ -z "$next_nic" ]; then $nmcli con up $con_name is_connection_activate_intime $con_name @@ -1770,7 +1776,48 @@ function create_vlan_interface_nmcli { $nmcli con delete $tmp_con_name fi $ip address show dev $ifname.$vlanid | $sed -e 's/^/[vlan] >> /g' | log_lines info - return 0 + return $rc +} +############################################################################### +# +# add extra params for nmcli connection +# +# input : $1 nic device +# $2 nmcli connection name +# return : 1 error +# 0 successful +# +############################################################################### +function add_extra_params_nmcli { + + nicdev=$1 + con_name=$2 + rc=0 + str_conf_file="/etc/sysconfig/network-scripts/ifcfg-${con_name}" + str_conf_file_1="/etc/sysconfig/network-scripts/ifcfg-${con_name}-1" + if [ -f $str_conf_file_1 ]; then + grep -x "NAME=$con_name" $str_conf_file_1 >/dev/null 2>/dev/null + if [ $? -eq 0 ]; then + str_conf_file=$str_conf_file_1 + fi + fi + #query extra params + query_extra_params $nicdev + i=0 + while [ $i -lt ${#array_extra_param_names[@]} ] + do + name="${array_extra_param_names[$i]}" + value="${array_extra_param_values[$i]}" + if [ -n "$name" -a -n "$value" ]; then + echo "$name=$value" >> $str_conf_file + else + log_error "invalid extra params $name $value, please check nics.nicextraparams" + rc=1 + fi + i=$((i+1)) + done + $nmcli con reload $str_conf_file + return $rc } ############################################################################### @@ -1951,10 +1998,13 @@ function create_bridge_interface_nmcli { $nmcli con mod $xcat_con_name ipv4.method manual ipv4.addresses $ipv4_addr/$str_prefix; fi + # add extra params + add_extra_params_nmcli $ifname $xcat_con_name + [ $? -ne 0 ] && rc=1 # bring up interface formally log_info "$nmcli con up $xcat_con_name" $nmcli con up $xcat_con_name - rc=$? + [ $? -ne 0 ] && rc=1 log_info "$nmcli con up $xcat_slave_con" $nmcli con up $xcat_slave_con # If bridge interface is active, delete tmp old connection @@ -1983,7 +2033,7 @@ function create_bridge_interface_nmcli { $nmcli con delete $tmp_slave_con_name fi wait_for_ifstate $ifname UP 20 40 - rc=$? + [ $? -ne 0 ] && rc=1 $ip address show dev $ifname| $sed -e 's/^/[bridge] >> /g' | log_lines info fi @@ -2176,8 +2226,12 @@ function create_bond_interface_nmcli { break fi done - # bring up interface formally + invalid_extra_params=0 if [ $rc -ne 1 ]; then + # add extra params + add_extra_params_nmcli $bondname $xcat_con_name + [ $? -ne 0 ] && invalid_extra_params=1 + # bring up interface formally log_info "$nmcli con up $xcat_con_name" $nmcli con up $xcat_con_name if [ -z "$next_nic" ]; then @@ -2194,8 +2248,6 @@ function create_bond_interface_nmcli { $ip address show dev $bondname| $sed -e 's/^/[bond] >> /g' | log_lines info fi fi - else - rc=0 fi fi @@ -2231,6 +2283,7 @@ function create_bond_interface_nmcli { delete_bond_slaves_con "$tmp_slave_con_names" fi fi + [ $invalid_extra_params -eq 1 ] && rc=$invalid_extra_params return $rc } ######################################################################