Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use 'nmcli con modify' for nicextraparams on RHEL9 #7444

Merged
merged 9 commits into from
Jun 24, 2024
Merged
26 changes: 17 additions & 9 deletions xCAT/postscripts/configeth
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,15 @@ function configipv4(){
do
name="${array_extra_param_names[$i]}"
value="${array_extra_param_values[$i]}"
grep -i "${name}" $str_conf_file
if [ $? -eq 0 ];then
sed -i "s/.*${name}.*/${name}=${value}/i" $str_conf_file
if [[ "$OSVER" =~ (rhels9|alma9|rocky9) ]]; then
nmcli con modify $con_name $name $value
else
echo "${name}=${value}" >> $str_conf_file
grep -i "${name}" $str_conf_file
if [ $? -eq 0 ];then
sed -i "s/.*${name}.*/${name}=${value}/i" $str_conf_file
else
echo "${name}=${value}" >> $str_conf_file
fi
fi
i=$((i+1))
done
Expand Down Expand Up @@ -780,12 +784,16 @@ elif [ "$1" = "-s" ];then
do
name="${array_extra_param_names[$i]}"
value="${array_extra_param_values[$i]}"
echo "$i: name=$name value=$value"
grep -i "${name}" $str_conf_file
if [ $? -eq 0 ];then
sed -i "s/.*${name}.*/${name}=${value}/i" $str_conf_file
if [[ "$OSVER" =~ (rhels9|alma9|rocky9) ]]; then
nmcli con modify $con_name $name $value
else
echo "${name}=${value}" >> $str_conf_file
echo "$i: name=$name value=$value"
grep -i "${name}" $str_conf_file
if [ $? -eq 0 ];then
sed -i "s/.*${name}.*/${name}=${value}/i" $str_conf_file
else
echo "${name}=${value}" >> $str_conf_file
fi
fi
i=$((i+1))
done
Expand Down
172 changes: 95 additions & 77 deletions xCAT/postscripts/configib
Original file line number Diff line number Diff line change
Expand Up @@ -433,21 +433,25 @@ IPADDR=$nicip" > $dir/ifcfg-$nic
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"
grep -i "${name}" $dir/ifcfg-$nic
if [ $? -eq 0 ];then
sed -i "s/.*${name}.*/${name}=${value}/i" >> $dir/ifcfg-$nic
else
echo "${name}=${value}" >> $dir/ifcfg-$nic
fi
i=$((i+1))
done
else # not the first ip address
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 [[ "$OSVER" =~ (rhels9|alma9|rocky9) ]]; then
nmcli con modify $con_name $name $value
else
grep -i "${name}" $dir/ifcfg-$nic
if [ $? -eq 0 ];then
sed -i "s/.*${name}.*/${name}=${value}/i" >> $dir/ifcfg-$nic
else
echo "${name}=${value}" >> $dir/ifcfg-$nic
fi
fi
i=$((i+1))
done
else # not the first ip address
echo "LABEL_$ipindex=$ipindex
IPADDR_$ipindex=$nicip" >> $dir/ifcfg-$nic
# ipv6
Expand All @@ -465,20 +469,24 @@ IPADDR_$ipindex=$nicip" >> $dir/ifcfg-$nic
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"
grep -i "${name}" $dir/ifcfg-$nic
if [ $? -eq 0 ];then
sed -i "s/.*${name}.*/${name}=${value}/i" >> $dir/ifcfg-$nic
else
echo "${name}=${value}" >> $dir/ifcfg-$nic
fi
i=$((i+1))
done
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 [[ "$OSVER" =~ (rhels9|alma9|rocky9) ]]; then
nmcli con modify $con_name $name $value
else
grep -i "${name}" $dir/ifcfg-$nic
if [ $? -eq 0 ];then
sed -i "s/.*${name}.*/${name}=${value}/i" >> $dir/ifcfg-$nic
else
echo "${name}=${value}" >> $dir/ifcfg-$nic
fi
fi
i=$((i+1))
done
fi # end if [ $ipindex -eq 1 ]
elif [ $OS_name == 'redhat' ]
then
Expand Down Expand Up @@ -521,21 +529,25 @@ IPADDR=$nicip" > $dir/ifcfg-$nic
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"
grep -i "${name}" $dir/ifcfg-$nic
if [ $? -eq 0 ];then
sed -i "s/.*${name}.*/${name}=${value}/i" >> $dir/ifcfg-$nic
else
echo "${name}=${value}" >> $dir/ifcfg-$nic
fi
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 [[ "$OSVER" =~ (rhels9|alma9|rocky9) ]]; then
nmcli con modify $con_name $name $value
else
grep -i "${name}" $dir/ifcfg-$nic
if [ $? -eq 0 ];then
sed -i "s/.*${name}.*/${name}=${value}/i" >> $dir/ifcfg-$nic
else
echo "${name}=${value}" >> $dir/ifcfg-$nic
fi
fi
i=$((i+1))
done
else # not the first ip address
# ipv6
if echo $nicip | grep : 2>&1 1>/dev/null
Expand Down Expand Up @@ -586,21 +598,25 @@ IPADDR$ipindex=$nicip"
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"
grep -i "${name}" $cfgfile
if [ $? -eq 0 ];then
sed -i "s/.*${name}.*/${name}=${value}/i" >> $cfgfile
else
echo "${name}=${value}" >> $cfgfile
fi
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 [[ "$OSVER" =~ (rhels9|alma9|rocky9) ]]; then
nmcli con modify $con_name $name $value
else
grep -i "${name}" $cfgfile
if [ $? -eq 0 ]; then
sed -i "s/.*${name}.*/${name}=${value}/i" >> $cfgfile
else
echo "${name}=${value}" >> $cfgfile
fi
fi
i=$((i+1))
done

# need to run ifup eth1:1 for RedHat
if [ $nmcli_used -eq 0 ]; then
Expand Down Expand Up @@ -657,24 +673,24 @@ netmask $netmask" >> /etc/network/interfaces
# echo "gateway $gateway" >> /etc/network/interfaces
#fi
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"
grep -i "${name}" /etc/network/interfaces
if [ $? -eq 0 ];then
sed -i "s/.*${name}.*/${name} ${value}/i" >> /etc/network/interfaces
else
echo "${name} ${value}" >> /etc/network/interfaces
fi
i=$((i+1))
done
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"
grep -i "${name}" /etc/network/interfaces
if [ $? -eq 0 ];then
sed -i "s/.*${name}.*/${name} ${value}/i" >> /etc/network/interfaces
else
echo "${name} ${value}" >> /etc/network/interfaces
fi
i=$((i+1))
done

else
else
echo "Unsupported operating system"
logger -p local4.err -t $log_label "Unsupported operating system"
fi
Expand Down Expand Up @@ -772,7 +788,9 @@ then
done
else
if [ $nmcli_used -eq 1 ]; then
nmcli con reload $dir/ifcfg-$nic
if ! [[ "$OSVER" =~ (rhels9|alma9|rocky9) ]]; then
nmcli con reload $dir/ifcfg-$nic
fi
nmcli con up $nic 2>&1
else
ifup $nic > /dev/null 2>&1
Expand Down
38 changes: 26 additions & 12 deletions xCAT/postscripts/nicutils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1808,36 +1808,50 @@ 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

if ! [[ $OSVER =~ (rhels9|alma9|rocky9) ]]; then
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
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
grep $name $str_conf_file >/dev/null 2>/dev/null
if [ $? -eq 0 ]; then
replacevalue="$name=$value"
sed -i "s/^$name=.*/$replacevalue/" $str_conf_file
# For RHEL 9, use nmcli directly, otherwise use ifcfg scheme.
if [[ "$OSVER" =~ (rhels9|alma9|rocky9) ]]; then
nmcli con modify "$con_name" "$name" "$value"
rc+=$?
else
echo "$name="$value"" >> $str_conf_file
grep $name $str_conf_file >/dev/null 2>/dev/null
if [ $? -eq 0 ]; then
replacevalue="$name=$value"
sed -i "s/^$name=.*/$replacevalue/" $str_conf_file
else
echo "$name="$value"" >> $str_conf_file
fi
fi
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

if [[ $OSVER != (rhels9|alma9|rocky9) ]]; then
$nmcli con reload $str_conf_file
fi
return $rc
}

Expand Down