From 78e32fadd66bdb35197eb7e2ce9bc0be9dc3ef56 Mon Sep 17 00:00:00 2001 From: bybai Date: Wed, 23 Jan 2019 03:55:25 -0500 Subject: [PATCH 1/3] configeth support redhat8 --- xCAT/postscripts/configeth | 71 +++++++++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 21 deletions(-) diff --git a/xCAT/postscripts/configeth b/xCAT/postscripts/configeth index 0dfe77213..e15a3ff8f 100755 --- a/xCAT/postscripts/configeth +++ b/xCAT/postscripts/configeth @@ -23,6 +23,15 @@ if [ -z "$UPDATENODE" ] || [ $UPDATENODE -ne 1 ] ; then reboot_nic_bool=0 fi fi +######################################################################## +# networkmanager_active=0: use network.service +# networkmanager_active=1: use NetworkManager +######################################################################## +networkmanager_active=0 +checkservicestatus NetworkManager > /dev/null +if [ $? -eq 0 ]; then + networkmanager_active=1 +fi function configipv4(){ str_if_name=$1 str_v4ip=$2 @@ -115,22 +124,30 @@ function configipv4(){ echo " vlan-raw-device ${parent_device}" >> $str_conf_file fi else + str_prefix=$(v4mask2prefix $str_v4mask) # Write the info to the ifcfg file for redhat + con_name="" str_conf_file="" - if [ $num_v4num -eq 0 ];then - str_conf_file="/etc/sysconfig/network-scripts/ifcfg-${str_if_name}" - echo "DEVICE=${str_if_name}" > $str_conf_file - else - str_conf_file="/etc/sysconfig/network-scripts/ifcfg-${str_if_name}:${num_v4num}" - echo "DEVICE=${str_if_name}:${num_v4num}" > $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 + nmcli con show | grep ${str_if_name} + if [ $? -ne 0 ] ; then + nmcli con add type ethernet con-name ${str_if_name} ifname ${str_if_name} ipv4.method manual ipv4.addresses ${str_v4ip}/${str_prefix} + else + con_name=$(nmcli dev show ${str_if_name}|grep CONNECTION|awk -F: '{print $2}'|sed 's/^ *//') + nmcli con mod "${con_name}" ipv4.method manual ipv4.addresses ${str_v4ip}/${str_prefix} + fi + else + echo "DEVICE=${str_if_name}" > $str_conf_file + echo "BOOTPROTO=static" >> $str_conf_file + echo "NM_CONTROLLED=no" >> $str_conf_file + echo "IPADDR=${str_v4ip}" >> $str_conf_file + echo "NETMASK=${str_v4mask}" >> $str_conf_file + echo "ONBOOT=yes" >> $str_conf_file fi - - - echo "BOOTPROTO=static" >> $str_conf_file - echo "NM_CONTROLLED=no" >> $str_conf_file - echo "IPADDR=${str_v4ip}" >> $str_conf_file - echo "NETMASK=${str_v4mask}" >> $str_conf_file - echo "ONBOOT=yes" >> $str_conf_file if [ "$str_nic_mtu" != "$str_default_token" ]; then echo "MTU=${str_nic_mtu}" >> $str_conf_file fi @@ -519,7 +536,7 @@ elif [ "$1" = "-s" ];then log_info "configeth on $NODE: config install nic, can not find information from dhcp lease file, return." exit 1 fi - + str_inst_net=$(v4calcnet $str_inst_ip $str_inst_mask) num_index=1 while [ $num_index -le $NETWORKS_LINES ];do @@ -604,13 +621,26 @@ elif [ "$1" = "-s" ];then hostname $NODE echo $NODE > /etc/HOSTNAME else + #write ifcfg-* file for redhat + con_name="" + str_inst_prefix=$(v4mask2prefix ${str_inst_mask}) str_conf_file="/etc/sysconfig/network-scripts/ifcfg-${str_inst_nic}" - 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=static" >> $str_conf_file - echo "ONBOOT=yes" >> $str_conf_file - echo "HWADDR=${str_inst_mac}" >> $str_conf_file + if [ $networkmanager_active -eq 1 ]; then + nmcli con show | grep ${str_inst_nic} + if [ $? -ne 0 ] ; then + nmcli con add type ethernet con-name ${str_inst_nic} ifname ${str_inst_nic} ipv4.method manual ipv4.addresses ${str_inst_ip}/${str_inst_prefix} + else + con_name=$(nmcli dev show ${str_inst_nic}|grep CONNECTION|awk -F: '{print $2}'|sed 's/^ *//') + nmcli con mod "System ens3" ipv4.method manual ipv4.addresses ${str_inst_ip}/${str_inst_prefix} + 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=static" >> $str_conf_file + echo "ONBOOT=yes" >> $str_conf_file + echo "HWADDR=${str_inst_mac}" >> $str_conf_file + fi if [ -n "${str_inst_mtu}" ];then echo "MTU=${str_inst_mtu}" >> $str_conf_file fi @@ -893,7 +923,6 @@ else bool_modify_flag=0 str_nic_status='down' str_his_file=${str_cfg_dir}xcat_history_important - str_history=`ip addr show dev $str_nic_name | grep inet | grep -iv dynamic | grep -iv link | grep $str_nic_name | awk '{print $2}'` old_ifs=$IFS IFS=$'\n' From db9bee6b1a9a98522a34ba9a6f21716d5e394894 Mon Sep 17 00:00:00 2001 From: bybai Date: Wed, 23 Jan 2019 05:40:18 -0500 Subject: [PATCH 2/3] polished --- xCAT/postscripts/configeth | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/xCAT/postscripts/configeth b/xCAT/postscripts/configeth index e15a3ff8f..151d9766f 100755 --- a/xCAT/postscripts/configeth +++ b/xCAT/postscripts/configeth @@ -133,11 +133,10 @@ function configipv4(){ fi str_conf_file="/etc/sysconfig/network-scripts/ifcfg-${str_if_name}" if [ $networkmanager_active -eq 1 ]; then - nmcli con show | grep ${str_if_name} - if [ $? -ne 0 ] ; then + con_name=$(nmcli dev show ${str_if_name}|grep CONNECTION|awk -F: '{print $2}'|sed 's/^[ \t]*$//g') + if [ "$con_name" == "--" ] ; then nmcli con add type ethernet con-name ${str_if_name} ifname ${str_if_name} ipv4.method manual ipv4.addresses ${str_v4ip}/${str_prefix} else - con_name=$(nmcli dev show ${str_if_name}|grep CONNECTION|awk -F: '{print $2}'|sed 's/^ *//') nmcli con mod "${con_name}" ipv4.method manual ipv4.addresses ${str_v4ip}/${str_prefix} fi else @@ -536,7 +535,6 @@ elif [ "$1" = "-s" ];then log_info "configeth on $NODE: config install nic, can not find information from dhcp lease file, return." exit 1 fi - str_inst_net=$(v4calcnet $str_inst_ip $str_inst_mask) num_index=1 while [ $num_index -le $NETWORKS_LINES ];do @@ -626,18 +624,17 @@ elif [ "$1" = "-s" ];then str_inst_prefix=$(v4mask2prefix ${str_inst_mask}) str_conf_file="/etc/sysconfig/network-scripts/ifcfg-${str_inst_nic}" if [ $networkmanager_active -eq 1 ]; then - nmcli con show | grep ${str_inst_nic} - if [ $? -ne 0 ] ; then + con_name=$(nmcli dev show ${str_if_name}|grep CONNECTION|awk -F: '{print $2}'|sed 's/^[ \t]*$//g') + if [ "$con_name" == "--" ] ; then nmcli con add type ethernet con-name ${str_inst_nic} ifname ${str_inst_nic} ipv4.method manual ipv4.addresses ${str_inst_ip}/${str_inst_prefix} else - con_name=$(nmcli dev show ${str_inst_nic}|grep CONNECTION|awk -F: '{print $2}'|sed 's/^ *//') nmcli con mod "System ens3" ipv4.method manual ipv4.addresses ${str_inst_ip}/${str_inst_prefix} 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=static" >> $str_conf_file + echo "BOOTPROTO=none" >> $str_conf_file echo "ONBOOT=yes" >> $str_conf_file echo "HWADDR=${str_inst_mac}" >> $str_conf_file fi From 048847abd2e7e5be37033081bf235b9c04edbc0b Mon Sep 17 00:00:00 2001 From: bybai Date: Wed, 23 Jan 2019 05:47:38 -0500 Subject: [PATCH 3/3] polished --- xCAT/postscripts/configeth | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xCAT/postscripts/configeth b/xCAT/postscripts/configeth index 151d9766f..9133ea09a 100755 --- a/xCAT/postscripts/configeth +++ b/xCAT/postscripts/configeth @@ -141,7 +141,7 @@ function configipv4(){ fi else echo "DEVICE=${str_if_name}" > $str_conf_file - echo "BOOTPROTO=static" >> $str_conf_file + echo "BOOTPROTO=none" >> $str_conf_file echo "NM_CONTROLLED=no" >> $str_conf_file echo "IPADDR=${str_v4ip}" >> $str_conf_file echo "NETMASK=${str_v4mask}" >> $str_conf_file