2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-05-22 03:32:04 +00:00

Merge pull request #5973 from bybai/cfgeth_rh8

configeth support redhat8
This commit is contained in:
Gᴏɴɢ Jie 2019-01-23 18:49:42 +08:00 committed by GitHub
commit 9ae3acb3b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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,29 @@ 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
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
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=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
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 +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
@ -604,13 +619,25 @@ 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
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
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=none" >> $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 +920,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'