From feef25ccc0f0dd88336cb6bac7e545a9dc42d6df Mon Sep 17 00:00:00 2001 From: bybai Date: Wed, 3 Apr 2019 03:04:20 -0400 Subject: [PATCH 1/8] confignetwork extra params support using nmcli --- xCAT/postscripts/configeth | 48 ++++++++++++++++----------- xCAT/postscripts/nicutils.sh | 64 ++++++++++++++++++++++++++++++++---- 2 files changed, 85 insertions(+), 27 deletions(-) diff --git a/xCAT/postscripts/configeth b/xCAT/postscripts/configeth index 80e2e5d56..c545ea2bf 100755 --- a/xCAT/postscripts/configeth +++ b/xCAT/postscripts/configeth @@ -162,16 +162,20 @@ function configipv4(){ 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 "$i: name=$name value=$value" + if [ $networkmanager_active -eq 1 ]; then + nmcli con modify $con_name $name $value + else + echo "${name}=${value}" >> $str_conf_file + fi + i=$((i+1)) + done fi } @@ -661,16 +665,20 @@ elif [ "$1" = "-s" ];then 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" + if [ $networkmanager_active -eq 1 ]; then + nmcli con modify $con_name $name $value + else + echo "${name}=${value}" >> $str_conf_file + fi + i=$((i+1)) + done hostname $NODE if [ -f "/etc/hostname" ]; then diff --git a/xCAT/postscripts/nicutils.sh b/xCAT/postscripts/nicutils.sh index 22f499f92..b67ca637d 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,45 @@ 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 + #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 + cmd="$nmcli con modify $con_name $name $value" + log_info $cmd + $cmd + if [ $? -ne 0 ]; then + log_error "add extra params $name $value for $con_name failed" + rc=1 + fi + else + log_error "invalid extra params $name $value, please check nics.nicextraparams" + rc=1 + fi + i=$((i+1)) + done + return $rc } ############################################################################### @@ -1951,10 +1995,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 +2030,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 +2223,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 +2245,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 +2280,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 } ###################################################################### From d068bbc1f3e119e5572f8e10c5623940cd69954e Mon Sep 17 00:00:00 2001 From: bybai Date: Thu, 4 Apr 2019 04:58:32 -0400 Subject: [PATCH 2/8] configure multiple ipv4 address for ethernet NIC using nmcli --- xCAT/postscripts/configeth | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/xCAT/postscripts/configeth b/xCAT/postscripts/configeth index c545ea2bf..7f5704299 100755 --- a/xCAT/postscripts/configeth +++ b/xCAT/postscripts/configeth @@ -131,17 +131,21 @@ 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 + if [ $num_v4num -ne 0 ] && [ $networkmanager_active -eq 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 else echo "DEVICE=${str_if_name}" > $str_conf_file echo "BOOTPROTO=none" >> $str_conf_file @@ -345,7 +349,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}" From 89bc1a780a754a07261eaf721a92144fd49579fe Mon Sep 17 00:00:00 2001 From: bybai Date: Wed, 10 Apr 2019 01:57:19 -0400 Subject: [PATCH 3/8] let configeth work in postscripts RH8 nmcli --- xCAT/postscripts/configeth | 69 ++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 17 deletions(-) diff --git a/xCAT/postscripts/configeth b/xCAT/postscripts/configeth index 7f5704299..c19775684 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="" @@ -135,6 +141,9 @@ function configipv4(){ str_if_name=${str_if_name}:${num_v4num} fi str_conf_file="/etc/sysconfig/network-scripts/ifcfg-${str_if_name}" + if [ $networkmanager_active -ne 0 ]; then + str_conf_file="/etc/sysconfig/network-scripts/ifcfg-xcat-${str_if_name}" + fi if [ $networkmanager_active -eq 1 ]; then if [ $num_v4num -eq 0 ]; then is_nmcli_connection_exist $con_name @@ -146,6 +155,19 @@ function configipv4(){ else nmcli con modify $con_name +ipv4.addresses ${str_v4ip}/${str_prefix} fi + elif [ $networkmanager_active -eq 2 ]; then + 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 echo "DEVICE=${str_if_name}" > $str_conf_file echo "BOOTPROTO=none" >> $str_conf_file @@ -156,10 +178,10 @@ 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 @@ -174,10 +196,12 @@ function configipv4(){ value="${array_extra_param_values[$i]}" echo "$i: name=$name value=$value" if [ $networkmanager_active -eq 1 ]; then - nmcli con modify $con_name $name $value - else - echo "${name}=${value}" >> $str_conf_file + str_conf_file_1="/etc/sysconfig/network-scripts/ifcfg-xcat-${str_if_name}-1" + if [ -e $str_conf_file_1 ]; then + echo "${name}=${value}" >> $str_conf_file_1 + fi fi + echo "${name}=${value}" >> $str_conf_file i=$((i+1)) done fi @@ -638,6 +662,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 @@ -651,14 +678,18 @@ elif [ "$1" = "-s" ];then 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 @@ -669,7 +700,7 @@ elif [ "$1" = "-s" ];then fi fi - #add extra params + #add extra params i=0 while [ $i -lt ${#array_extra_param_names[@]} ] do @@ -677,10 +708,12 @@ elif [ "$1" = "-s" ];then value="${array_extra_param_values[$i]}" echo "$i: name=$name value=$value" if [ $networkmanager_active -eq 1 ]; then - nmcli con modify $con_name $name $value - else - echo "${name}=${value}" >> $str_conf_file - fi + str_conf_file_1="/etc/sysconfig/network-scripts/ifcfg-xcat-install-${str_if_name}-1" + if [ -e $str_conf_file_1 ]; then + echo "${name}=${value}" >> $str_conf_file_1 + fi + fi + echo "${name}=${value}" >> $str_conf_file i=$((i+1)) done @@ -704,7 +737,8 @@ 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 ifup $str_inst_nic @@ -1123,11 +1157,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 From 11e45fd741a762901fe30bbe0c9a2c47f4505ad8 Mon Sep 17 00:00:00 2001 From: bybai Date: Wed, 10 Apr 2019 04:36:46 -0400 Subject: [PATCH 4/8] unify nicextraparams interface for RH8 and RH7 --- xCAT/postscripts/configeth | 40 ++++++++++++++++++---------------- xCAT/postscripts/confignetwork | 3 ++- xCAT/postscripts/nicutils.sh | 17 +++++++++------ 3 files changed, 33 insertions(+), 27 deletions(-) diff --git a/xCAT/postscripts/configeth b/xCAT/postscripts/configeth index c19775684..6b116c27b 100755 --- a/xCAT/postscripts/configeth +++ b/xCAT/postscripts/configeth @@ -183,27 +183,27 @@ function configipv4(){ echo "MTU=${str_nic_mtu}" >> $str_conf_file fi fi - + if [ $networkmanager_active -eq 1 ]; then + 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 + 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" - if [ $networkmanager_active -eq 1 ]; then - str_conf_file_1="/etc/sysconfig/network-scripts/ifcfg-xcat-${str_if_name}-1" - if [ -e $str_conf_file_1 ]; then - echo "${name}=${value}" >> $str_conf_file_1 - fi - fi - echo "${name}=${value}" >> $str_conf_file + echo "${name}=${value}" >> $str_conf_file i=$((i+1)) - done + done fi } @@ -699,7 +699,15 @@ elif [ "$1" = "-s" ];then echo "GATEWAY=${str_inst_gateway}" >> /etc/sysconfig/network fi fi - + if [ $networkmanager_active -eq 1 ]; then + 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 + fi #add extra params i=0 while [ $i -lt ${#array_extra_param_names[@]} ] @@ -707,12 +715,6 @@ elif [ "$1" = "-s" ];then name="${array_extra_param_names[$i]}" value="${array_extra_param_values[$i]}" echo "$i: name=$name value=$value" - if [ $networkmanager_active -eq 1 ]; then - str_conf_file_1="/etc/sysconfig/network-scripts/ifcfg-xcat-install-${str_if_name}-1" - if [ -e $str_conf_file_1 ]; then - echo "${name}=${value}" >> $str_conf_file_1 - fi - fi echo "${name}=${value}" >> $str_conf_file i=$((i+1)) done @@ -740,7 +742,7 @@ elif [ "$1" = "-s" ];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 diff --git a/xCAT/postscripts/confignetwork b/xCAT/postscripts/confignetwork index 40f4d4ace..89f06d305 100755 --- a/xCAT/postscripts/confignetwork +++ b/xCAT/postscripts/confignetwork @@ -63,7 +63,8 @@ function get_nic_cfg_file_content { elif [ $is_debian -eq 1 ]; then cfg_file="$nwdir/${cfg_dev}" fi - if [ "$networkmanager_active" = "1" ]; then + 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 diff --git a/xCAT/postscripts/nicutils.sh b/xCAT/postscripts/nicutils.sh index b67ca637d..86acd954f 100755 --- a/xCAT/postscripts/nicutils.sh +++ b/xCAT/postscripts/nicutils.sh @@ -1793,6 +1793,14 @@ 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 @@ -1801,19 +1809,14 @@ function add_extra_params_nmcli { name="${array_extra_param_names[$i]}" value="${array_extra_param_values[$i]}" if [ -n "$name" -a -n "$value" ]; then - cmd="$nmcli con modify $con_name $name $value" - log_info $cmd - $cmd - if [ $? -ne 0 ]; then - log_error "add extra params $name $value for $con_name failed" - rc=1 - fi + 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 } From 45631ac21794458387f6c2d9e2c2370392d49e11 Mon Sep 17 00:00:00 2001 From: bybai Date: Wed, 10 Apr 2019 06:06:40 -0400 Subject: [PATCH 5/8] create bridge on RH8 in postscripts --- xCAT/postscripts/confignetwork | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/xCAT/postscripts/confignetwork b/xCAT/postscripts/confignetwork index 89f06d305..5916b00af 100755 --- a/xCAT/postscripts/confignetwork +++ b/xCAT/postscripts/confignetwork @@ -563,8 +563,10 @@ function configure_nicdevice { #openvswitch bridge type is bridge_ovs elif [ x"$nic_dev_type" = "xbridge_ovs" -o x"$nic_dev_type" = "xbridge" ]; then if [ "$networkmanager_active" = "0" ]; then + ps -ef|grep -v grep|grep NetworkManager >/dev/null 2>/dev/null + nmcli_used=$? check_brctl $nic_dev_type - if [ $? -ne 0 ]; then + if [ $? -ne 0 ] && [ $nmcli_used -ne 0 ]; then errorcode=1 else create_bridge_interface ifname=$nic_dev _brtype=$nic_dev_type _port=$base_nic_dev _pretype=$base_nic_type From 68925429a3dbb87b6be0edba51e49db97f9eef35 Mon Sep 17 00:00:00 2001 From: bybai Date: Thu, 11 Apr 2019 04:37:50 -0400 Subject: [PATCH 6/8] polished networkmanager_active logic --- xCAT/postscripts/configeth | 48 ++++++++++++++++------------------ xCAT/postscripts/confignetwork | 31 +++++++++++++--------- 2 files changed, 41 insertions(+), 38 deletions(-) diff --git a/xCAT/postscripts/configeth b/xCAT/postscripts/configeth index 6b116c27b..6e540fe4e 100755 --- a/xCAT/postscripts/configeth +++ b/xCAT/postscripts/configeth @@ -46,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 @@ -137,13 +137,6 @@ 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 ] && [ $networkmanager_active -eq 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 -ne 0 ]; then - str_conf_file="/etc/sysconfig/network-scripts/ifcfg-xcat-${str_if_name}" - fi if [ $networkmanager_active -eq 1 ]; then if [ $num_v4num -eq 0 ]; then is_nmcli_connection_exist $con_name @@ -155,7 +148,16 @@ function configipv4(){ else nmcli con modify $con_name +ipv4.addresses ${str_v4ip}/${str_prefix} fi + 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 @@ -169,6 +171,11 @@ function configipv4(){ echo "NETMASK$num_v4num=${str_v4mask}" >> $str_conf_file fi else + str_conf_file="/etc/sysconfig/network-scripts/ifcfg-${str_if_name}" + #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 echo "DEVICE=${str_if_name}" > $str_conf_file echo "BOOTPROTO=none" >> $str_conf_file echo "NM_CONTROLLED=no" >> $str_conf_file @@ -183,15 +190,6 @@ function configipv4(){ echo "MTU=${str_nic_mtu}" >> $str_conf_file fi fi - if [ $networkmanager_active -eq 1 ]; then - 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 - fi if [[ ${str_if_name} == [a-zA-Z0-9]*.[0-9]* ]]; then echo "VLAN=yes" >> $str_conf_file fi @@ -672,6 +670,13 @@ 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 @@ -698,15 +703,6 @@ elif [ "$1" = "-s" ];then else echo "GATEWAY=${str_inst_gateway}" >> /etc/sysconfig/network fi - fi - if [ $networkmanager_active -eq 1 ]; then - 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 fi #add extra params i=0 diff --git a/xCAT/postscripts/confignetwork b/xCAT/postscripts/confignetwork index 5916b00af..1389836cb 100755 --- a/xCAT/postscripts/confignetwork +++ b/xCAT/postscripts/confignetwork @@ -63,6 +63,7 @@ function get_nic_cfg_file_content { elif [ $is_debian -eq 1 ]; then cfg_file="$nwdir/${cfg_dev}" fi + #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 @@ -562,16 +563,20 @@ function configure_nicdevice { #linux bridge type is bridge #openvswitch bridge type is bridge_ovs elif [ x"$nic_dev_type" = "xbridge_ovs" -o x"$nic_dev_type" = "xbridge" ]; then - if [ "$networkmanager_active" = "0" ]; then - ps -ef|grep -v grep|grep NetworkManager >/dev/null 2>/dev/null - nmcli_used=$? - check_brctl $nic_dev_type - if [ $? -ne 0 ] && [ $nmcli_used -ne 0 ]; then - errorcode=1 + ps -ef|grep -v grep|grep NetworkManager >/dev/null 2>/dev/null + nmcli_used=$? + if [ "$networkmanager_active" != "1" ]; then + if [ "$networkmanager_active" = "0" ]; then + check_brctl $nic_dev_type + if [ $? -ne 0 ]; then + errorcode=1 + else + create_bridge_interface ifname=$nic_dev _brtype=$nic_dev_type _port=$base_nic_dev _pretype=$base_nic_type + if 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 + 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 @@ -588,9 +593,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 @@ -599,9 +604,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 @@ -658,13 +663,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 From 8e343110c7fc0da692b83532277a40aecc3ad17c Mon Sep 17 00:00:00 2001 From: bybai Date: Fri, 12 Apr 2019 02:29:23 -0400 Subject: [PATCH 7/8] polishe --- xCAT/postscripts/configeth | 2 +- xCAT/postscripts/confignetwork | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/xCAT/postscripts/configeth b/xCAT/postscripts/configeth index 6e540fe4e..98807699e 100755 --- a/xCAT/postscripts/configeth +++ b/xCAT/postscripts/configeth @@ -171,11 +171,11 @@ function configipv4(){ echo "NETMASK$num_v4num=${str_v4mask}" >> $str_conf_file fi else - str_conf_file="/etc/sysconfig/network-scripts/ifcfg-${str_if_name}" #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 diff --git a/xCAT/postscripts/confignetwork b/xCAT/postscripts/confignetwork index 1389836cb..9f96a4bda 100755 --- a/xCAT/postscripts/confignetwork +++ b/xCAT/postscripts/confignetwork @@ -563,8 +563,6 @@ function configure_nicdevice { #linux bridge type is bridge #openvswitch bridge type is bridge_ovs elif [ x"$nic_dev_type" = "xbridge_ovs" -o x"$nic_dev_type" = "xbridge" ]; then - ps -ef|grep -v grep|grep NetworkManager >/dev/null 2>/dev/null - nmcli_used=$? if [ "$networkmanager_active" != "1" ]; then if [ "$networkmanager_active" = "0" ]; then check_brctl $nic_dev_type @@ -572,7 +570,7 @@ function configure_nicdevice { errorcode=1 else create_bridge_interface ifname=$nic_dev _brtype=$nic_dev_type _port=$base_nic_dev _pretype=$base_nic_type - if + fi else create_bridge_interface ifname=$nic_dev _brtype=$nic_dev_type _port=$base_nic_dev _pretype=$base_nic_type fi From d92f45a906868d4be0f9cbfb7b64668ed8f31b87 Mon Sep 17 00:00:00 2001 From: bybai Date: Fri, 12 Apr 2019 03:04:10 -0400 Subject: [PATCH 8/8] polished --- xCAT/postscripts/confignetwork | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/xCAT/postscripts/confignetwork b/xCAT/postscripts/confignetwork index 9f96a4bda..232d9890d 100755 --- a/xCAT/postscripts/confignetwork +++ b/xCAT/postscripts/confignetwork @@ -563,17 +563,15 @@ function configure_nicdevice { #linux bridge type is bridge #openvswitch bridge type is bridge_ovs elif [ x"$nic_dev_type" = "xbridge_ovs" -o x"$nic_dev_type" = "xbridge" ]; then - if [ "$networkmanager_active" != "1" ]; then - if [ "$networkmanager_active" = "0" ]; then - check_brctl $nic_dev_type - if [ $? -ne 0 ]; then - errorcode=1 - else - create_bridge_interface ifname=$nic_dev _brtype=$nic_dev_type _port=$base_nic_dev _pretype=$base_nic_type - fi + if [ "$networkmanager_active" = "0" ]; then + check_brctl $nic_dev_type + if [ $? -ne 0 ]; then + errorcode=1 else create_bridge_interface ifname=$nic_dev _brtype=$nic_dev_type _port=$base_nic_dev _pretype=$base_nic_type fi + 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