Skip to content

Commit

Permalink
Use 'nmcli con modify' for nicextraparams on RHEL9
Browse files Browse the repository at this point in the history
  • Loading branch information
alexrichert committed May 28, 2024
1 parent 167d029 commit c96e0e3
Showing 1 changed file with 26 additions and 12 deletions.
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* ]]; 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 ]]; then
nmcli con modify "$con_name" "$name" "$value"
return $?
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* ]]; then
$nmcli con reload $str_conf_file
fi
return $rc
}

Expand Down

0 comments on commit c96e0e3

Please sign in to comment.