mirror of
				https://github.com/xcat2/xcat-core.git
				synced 2025-10-30 02:42:41 +00:00 
			
		
		
		
	refine configeth using nmcli
This commit is contained in:
		| @@ -190,7 +190,7 @@ check:rc==0 | ||||
| cmd:xdsh $$CN "rm -rf /tmp/backupnet/" | ||||
| cmd:xdsh $$CN "mkdir -p /tmp/backupnet/" | ||||
| check:rc==0 | ||||
| cmd:if grep SUSE /etc/*release;then xdsh $$CN "cp -f /etc/sysconfig/network/ifcfg-* /tmp/backupnet/"; elif grep -E "Red Hat|CentOS" /etc/*release;then xdsh $$CN "cp -f /etc/sysconfig/network-scripts/ifcfg-* /tmp/backupnet/"; elif grep Ubuntu /etc/*release;then xdsh $$CN "cp -f /etc/network/interfaces.d/* /tmp/backupnet/";else echo "Sorry,this is not supported os"; fi | ||||
| cmd:if grep SUSE /etc/*release;then xdsh $$CN "cp -f /etc/sysconfig/network/ifcfg-* /tmp/backupnet/"; elif grep -E "Red Hat|CentOS" /etc/*release;then xdsh $$CN "cp -rf /etc/sysconfig/network-scripts /tmp/backupnet/"; elif grep Ubuntu /etc/*release;then xdsh $$CN "cp -f /etc/network/interfaces.d/* /tmp/backupnet/";else echo "Sorry,this is not supported os"; fi | ||||
| check:rc==0 | ||||
| cmd:mkdef -t network -o 11_1_0_0-255_255_0_0 net=11.1.0.0 mask=255.255.0.0 mgtifname=$$SECONDNIC mtu=1496 | ||||
| check:rc==0 | ||||
| @@ -208,7 +208,8 @@ cmd:if grep SUSE /etc/*release;then xdsh $$CN "rm -rf /etc/sysconfig/network/ifc | ||||
| check:rc==0 | ||||
| cmd:if [ -e /tmp/CN.standa ]; then rmdef $$CN; cat /tmp/CN.standa | mkdef -z; rm -rf /tmp/CN.standa; fi | ||||
| check:rc==0 | ||||
| cmd:if grep SUSE /etc/*release;then xdsh $$CN "cp -f /tmp/backupnet/* /etc/sysconfig/network/"; elif grep -E "Red Hat|CentOS" /etc/*release;then xdsh $$CN "cp -f /tmp/backupnet/* /etc/sysconfig/network-scripts/"; elif grep Ubuntu /etc/*release;then xdsh $$CN "cp -f /tmp/backupnet/* /etc/network/interfaces.d/";else echo "Sorry,this is not supported os"; fi | ||||
| cmd:if grep SUSE /etc/*release;then xdsh $$CN "cp -f /tmp/backupnet/* /etc/sysconfig/network/"; elif grep -E "Red Hat|CentOS" /etc/*release;then xdsh $$CN "cp -rf /tmp/backupnet/network-scripts /etc/sysconfig/"; elif grep Ubuntu /etc/*release;then xdsh $$CN "cp -f /tmp/backupnet/* /etc/network/interfaces.d/";else echo "Sorry,this is not supported os"; fi | ||||
| cmd:xdsh $$CN "systemctl status NetworkManager >/dev/null 2>/dev/null && which nmcli >/dev/null 2>/dev/null && nmcli con reload" | ||||
| cmd:xdsh $$CN "rm -rf /tmp/backupnet/" | ||||
| end | ||||
|  | ||||
| @@ -975,7 +976,7 @@ cmd:lsdef $$CN -z && lsdef -l $$CN -z >/tmp/CN.stanza | ||||
| check:rc==0 | ||||
| cmd:xdsh $$CN "mkdir -p /tmp/backupnet" | ||||
| check:rc==0 | ||||
| cmd:if grep SUSE /etc/*release;then xdsh $$CN "cp -f /etc/sysconfig/network/ifcfg-* /tmp/backupnet/"; elif grep -E "Red Hat|CentOS" /etc/*release;then xdsh $$CN "cp -f /etc/sysconfig/network-scripts/ifcfg-* /tmp/backupnet/"; elif grep Ubuntu /etc/*release;then xdsh $$CN "cp -f /etc/network/interfaces.d/* /tmp/backupnet/;cp -f /etc/network/interfaces /tmp";else echo "Sorry,this is not supported os"; fi | ||||
| cmd:if grep SUSE /etc/*release;then xdsh $$CN "cp -f /etc/sysconfig/network/ifcfg-* /tmp/backupnet/"; elif grep -E "Red Hat|CentOS" /etc/*release;then xdsh $$CN "cp -rf /etc/sysconfig/network-scripts /tmp/backupnet/"; elif grep Ubuntu /etc/*release;then xdsh $$CN "cp -f /etc/network/interfaces.d/* /tmp/backupnet/;cp -f /etc/network/interfaces /tmp";else echo "Sorry,this is not supported os"; fi | ||||
| check:rc==0 | ||||
| cmd:xdsh $$CN "ps -A --format pid,comm | awk '/dhclient/ { print \$1 }' | xargs -r -n 1 kill" | ||||
| cmd:xdsh $$CN "ps -A --format pid,comm | awk '/dhclient/ { print \$1 }' | xargs -r -n 1 kill -KILL" | ||||
| @@ -987,7 +988,8 @@ cmd:xdsh $$CN date | ||||
| check:rc==0 | ||||
| # Clean up | ||||
| cmd:test -e /tmp/CN.stanza && rmdef $$CN && mkdef -z </tmp/CN.stanza; rm -rf /tmp/CN.stanza | ||||
| cmd:if grep SUSE /etc/*release;then xdsh $$CN "cp -f /tmp/backupnet/* /etc/sysconfig/network/"; elif grep -E "Red Hat|CentOS" /etc/*release;then xdsh $$CN "cp -f /tmp/backupnet/* /etc/sysconfig/network-scripts/"; elif grep Ubuntu /etc/*release;then xdsh $$CN "cp -f /tmp/backupnet/* /etc/network/interfaces.d/;cp -f /tmp/interfaces /etc/network/";else echo "Sorry,this is not supported os"; fi | ||||
| cmd:if grep SUSE /etc/*release;then xdsh $$CN "cp -f /tmp/backupnet/* /etc/sysconfig/network/"; elif grep -E "Red Hat|CentOS" /etc/*release;then xdsh $$CN "rm -rf /etc/sysconfig/network-scripts;cp -rf /tmp/backupnet/network-scripts /etc/sysconfig/"; elif grep Ubuntu /etc/*release;then xdsh $$CN "cp -f /tmp/backupnet/* /etc/network/interfaces.d/;cp -f /tmp/interfaces /etc/network/";else echo "Sorry,this is not supported os"; fi | ||||
| cmd:xdsh $$CN "rm -rf /tmp/backupnet/ /tmp/interfaces" | ||||
| cmd:xdsh $$CN "if [ -f /etc/init.d/network ] ; then /etc/init.d/network restart ; elif [ -f /etc/init.d/networking ] ; then /etc/init.d/networking restart ; fi" | ||||
| cmd:xdsh $$CN "systemctl status NetworkManager >/dev/null 2>/dev/null && which nmcli >/dev/null 2>/dev/null && nmcli con reload" | ||||
| end | ||||
|   | ||||
| @@ -32,6 +32,9 @@ checkservicestatus NetworkManager > /dev/null | ||||
| if [ $? -eq 0 ]; then | ||||
|     networkmanager_active=1 | ||||
| fi | ||||
| str_conf_file="" | ||||
| str_conf_file_xcatbak="" | ||||
| tmp_con_name="" | ||||
| function configipv4(){ | ||||
|     str_if_name=$1 | ||||
|     str_v4ip=$2 | ||||
| @@ -126,19 +129,19 @@ function configipv4(){ | ||||
|     else | ||||
|         str_prefix=$(v4mask2prefix $str_v4mask) | ||||
|         # Write the info to the ifcfg file for redhat | ||||
|         con_name="" | ||||
|         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 | ||||
|             con_name=$(nmcli dev show ${str_if_name}|grep GENERAL.CONNECTION|awk -F: '{print $2}'|sed 's/^[ \t]*//g') | ||||
|             if [ "$con_name" = "--" ] || [ ! -f "$str_conf_file" ]; 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} | ||||
|             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} | ||||
|         else | ||||
|             echo "DEVICE=${str_if_name}" > $str_conf_file | ||||
|             echo "BOOTPROTO=none" >> $str_conf_file | ||||
| @@ -148,7 +151,11 @@ function configipv4(){ | ||||
|             echo "ONBOOT=yes" >> $str_conf_file | ||||
|         fi | ||||
|         if [ "$str_nic_mtu" != "$str_default_token" ]; then | ||||
|             echo "MTU=${str_nic_mtu}" >> $str_conf_file | ||||
|             if [ $networkmanager_active -eq 1 ]; then | ||||
| 		nmcli con modify $con_name mtu $str_nic_mtu | ||||
|             else | ||||
|                 echo "MTU=${str_nic_mtu}" >> $str_conf_file | ||||
| 	    fi | ||||
|         fi | ||||
|  | ||||
|         if [[ ${str_if_name} == [a-zA-Z0-9]*.[0-9]* ]]; then | ||||
| @@ -432,7 +439,7 @@ if [ "$1" = "-r" ];then | ||||
|             if [ "$str_os_type" = "debian" ];then | ||||
|                 ifdown --force $str_nic_name | ||||
|             else | ||||
|                 ifdown $str_nic_name | ||||
|                 ip link set dev $str_nic_name  down | ||||
|             fi | ||||
|         fi | ||||
|  | ||||
| @@ -620,16 +627,16 @@ elif [ "$1" = "-s" ];then | ||||
|         echo $NODE > /etc/HOSTNAME | ||||
|     else | ||||
|         #write ifcfg-* file for redhat | ||||
|         con_name="" | ||||
|         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 1 ]; then | ||||
|             con_name=$(nmcli dev show ${str_inst_nic}|grep GENERAL.CONNECTION|awk -F: '{print $2}'|sed 's/^[ \t]*//g') | ||||
|             if [ "$con_name" == "--" ] || [ ! -f "$str_conf_file" ]; 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 ${str_inst_nic}" ipv4.method manual ipv4.addresses ${str_inst_ip}/${str_inst_prefix} | ||||
|             is_nmcli_connection_exist "$con_name" | ||||
|             if [ $? -eq 0 ]; then | ||||
|                 tmp_con_name=${str_inst_nic}"-tmp" | ||||
|                 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} | ||||
|         else | ||||
|             echo "DEVICE=${str_inst_nic}" > $str_conf_file | ||||
|             echo "IPADDR=${str_inst_ip}" >> $str_conf_file | ||||
| @@ -639,7 +646,11 @@ elif [ "$1" = "-s" ];then | ||||
|             echo "HWADDR=${str_inst_mac}" >> $str_conf_file | ||||
|         fi | ||||
|         if [ -n "${str_inst_mtu}" ];then | ||||
|             echo "MTU=${str_inst_mtu}" >> $str_conf_file | ||||
| 	    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 | ||||
|         if [ -n "$str_inst_gateway" ];then | ||||
|             grep -i "GATEWAY" /etc/sysconfig/network | ||||
| @@ -678,15 +689,26 @@ elif [ "$1" = "-s" ];then | ||||
|         if [ "$str_os_type" = "debian" ];then | ||||
|             ifdown --force $str_inst_nic | ||||
|         else | ||||
|             ifdown $str_inst_nic | ||||
|             ip link set dev $str_inst_nic down | ||||
|         fi | ||||
| 	if [ $networkmanager_active -eq 1 ]; then | ||||
|             nmcli con up $con_name | ||||
| 	    wait_for_ifstate $str_inst_nic UP 10 5 | ||||
| 	else | ||||
|             ip link set dev $str_inst_nic up | ||||
|         fi | ||||
|         ifup $str_inst_nic | ||||
|     fi | ||||
|     if [ $? -ne 0 ]; then | ||||
|         log_error "ifup $str_inst_nic failed." | ||||
|         log_error "bring $str_inst_nic up failed." | ||||
|         error_code=1 | ||||
|     fi | ||||
|  | ||||
|     if [ $networkmanager_active -eq 1 ] && [ -n "$tmp_con_name" ]; then | ||||
|     	if [ $error_code -eq 1 ]; then | ||||
|             nmcli con modify $tmp_con_name connection.id $con_name | ||||
|         else | ||||
|             nmcli con delete $tmp_con_name | ||||
|         fi | ||||
|     fi | ||||
|     exit $error_code | ||||
| fi | ||||
|  | ||||
| @@ -1005,7 +1027,7 @@ else | ||||
|                     ifdown --force $str_nic_name > /dev/null | ||||
|                 else | ||||
|                     if [ $reboot_nic_bool -eq 1 ]; then | ||||
|                         ifdown $str_nic_name > /dev/null | ||||
|                         ip link set dev $str_nic_name down > /dev/null 2>/dev/null | ||||
|                     fi | ||||
|                 fi | ||||
|             fi | ||||
| @@ -1085,14 +1107,25 @@ else | ||||
|         else | ||||
|             if [ $reboot_nic_bool -eq 1 ]; then | ||||
|                 echo "bring up ip" | ||||
|                 ifup $str_nic_name | ||||
| 		if [ $networkmanager_active -eq 1 ]; then | ||||
|                     nmcli con up $con_name | ||||
| 		    wait_for_ifstate $str_nic_name UP 10 10 | ||||
| 		else | ||||
|                     ip link set dev $con_name up | ||||
| 		fi | ||||
|                 if [ $? -ne 0 ]; then | ||||
|                     log_error "ifup $str_nic_name failed." | ||||
|                     log_error "bring $con_name up failed." | ||||
|                     error_code=1 | ||||
|                 fi | ||||
|             fi | ||||
|         fi | ||||
|     fi | ||||
| fi | ||||
|  | ||||
| if [ $networkmanager_active -eq 1 ] && [ -n "$tmp_con_name" ]; then | ||||
|     if [ $error_code -eq 1 ]; then | ||||
|         nmcli con modify $tmp_con_name connection.id $con_name | ||||
|     else | ||||
|         nmcli con delete $tmp_con_name | ||||
|     fi | ||||
| fi | ||||
| exit $error_code | ||||
|   | ||||
| @@ -63,13 +63,16 @@ function get_nic_cfg_file_content { | ||||
|     elif [ $is_debian -eq 1 ]; then | ||||
|          cfg_file="$nwdir/${cfg_dev}" | ||||
|     fi | ||||
|  | ||||
|     if [ -f $cfg_file ]; then | ||||
|         echo "['${cfg_file}']" >&2 | ||||
|         cat ${cfg_file}| $sed -e 's/^/ >> /g' | log_lines info | ||||
|     if [ "$networkmanager_active" = "1" ]; then | ||||
|         $ip address show dev ${cfg_dev}| $sed -e 's/^/[Ethernet] >> /g' | log_lines info | ||||
|     else | ||||
|         log_error "Can not find $cfg_file." | ||||
|         errorcode=1 | ||||
|         if [ -f $cfg_file ]; then | ||||
|             echo "['${cfg_file}']" >&2 | ||||
|             cat ${cfg_file}| $sed -e 's/^/ >> /g' | log_lines info | ||||
|         else | ||||
|             log_error "Can not find $cfg_file." | ||||
|             errorcode=1 | ||||
|         fi | ||||
|     fi | ||||
| } | ||||
|  | ||||
| @@ -641,6 +644,17 @@ if [ $? -ne 0 ]; then | ||||
|     fi | ||||
| fi | ||||
|  | ||||
| #check if using NetworkManager or  network service | ||||
| networkmanager_active=2 | ||||
| check_NetworkManager_or_network_service | ||||
| if [ $? -eq 0 ]; then | ||||
|     networkmanager_active=0 | ||||
| elif [ $? -eq 1 ]; then | ||||
|     networkmanager_active=1 | ||||
| else | ||||
|     exit 1 | ||||
| fi | ||||
|  | ||||
| #get for installnic | ||||
| installnic='' | ||||
| installnic=`get_installnic` | ||||
| @@ -662,17 +676,6 @@ if [ $boot_install_nic -eq 1 ];then | ||||
|     fi | ||||
| fi | ||||
|  | ||||
| #check if using NetworkManager or  network service | ||||
| networkmanager_active=2 | ||||
| check_NetworkManager_or_network_service | ||||
| if [ $? -eq 0 ]; then | ||||
|     networkmanager_active=0 | ||||
| elif [ $? -eq 1 ]; then | ||||
|     networkmanager_active=1 | ||||
| else | ||||
|     exit 1 | ||||
| fi | ||||
|  | ||||
| #replace | with "@", for example, eth1|eth2  ---->   eth1@eth2 | ||||
| nicdevice=`echo "$NICDEVICES" | sed 's/|/@/g'` | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user