mirror of
https://github.com/xcat2/xcat-core.git
synced 2025-05-30 09:36:41 +00:00
add common functions for confignetwork using nmcli
This commit is contained in:
parent
bbe29109ec
commit
31ae6e4be9
@ -614,6 +614,17 @@ errorcode=0
|
||||
#nictypes should support capital letters, for example, Ethernet and ethernet
|
||||
utolcmd="sed -e y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/"
|
||||
|
||||
#back up all network interface configure files
|
||||
nwdirbak=$nwdir".xcatbak"
|
||||
ls $nwdirbak > /dev/null 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
log_info "back up $nwdir to $newdirbak"
|
||||
cp -rf $nwdir $nwdirbak > /dev/null 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
log_warn "back up $nwdir to $newdirbak failed."
|
||||
fi
|
||||
fi
|
||||
|
||||
#get for installnic
|
||||
installnic=''
|
||||
installnic=`get_installnic`
|
||||
|
@ -746,13 +746,32 @@ function check_brctl() {
|
||||
###############################################################################
|
||||
#
|
||||
# check and set device managed
|
||||
# input: ifname
|
||||
# input: network interface
|
||||
# output: 0 managed
|
||||
# 1 umanaged
|
||||
#
|
||||
###############################################################################
|
||||
function check_and_set_device_managed() {
|
||||
ifname=$1
|
||||
tname=$1
|
||||
rc=1
|
||||
$nmcli device show $tname >/dev/null 2>/dev/null
|
||||
if [ $? -ne 0 ]; then
|
||||
log_error "Device $tname not found"
|
||||
else
|
||||
$nmcli -g GENERAL.STATE device show $tname|grep unmanaged >/dev/null 2>/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
log_info "$nmcli device set $tname managed yes"
|
||||
$nmcli device set $tname managed yes
|
||||
if [ $? -eq 0 ]; then
|
||||
rc=0
|
||||
else
|
||||
log_error "nmcli fail to set device $tname managed"
|
||||
fi
|
||||
else
|
||||
rc=0
|
||||
fi
|
||||
fi
|
||||
return $rc
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
@ -1602,6 +1621,59 @@ function check_NetworkManager_or_network_service() {
|
||||
return 2
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# get nmcli connection name
|
||||
# input: network connetion
|
||||
# return: 0 connection exists
|
||||
# 1 connection does not exist
|
||||
#
|
||||
##############################################################################
|
||||
function get_nmcli_connection_name {
|
||||
|
||||
str_con_name=$1
|
||||
# the device str_if_name active connectin
|
||||
nmcli -g NAME connection show |grep -w $str_con_name >/dev/null 2>/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# get first ipv4 addr from nicips
|
||||
# input: nics.nicips for one nic
|
||||
# return 0, output: ipv4 addr
|
||||
# return 1, output error: "IP: $IP not available" or "$IP: IP format error"
|
||||
#
|
||||
###############################################################################
|
||||
function get_first_valid_ipv4_addr {
|
||||
|
||||
str_ips=$1
|
||||
res=1
|
||||
if [ -n "$str_ips" ]; then
|
||||
IP=$(echo "$str_ips"|awk -F"|" '{print $1}')
|
||||
if [[ $IP =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
|
||||
FIELD1=$(echo $IP|cut -d. -f1)
|
||||
FIELD2=$(echo $IP|cut -d. -f2)
|
||||
FIELD3=$(echo $IP|cut -d. -f3)
|
||||
FIELD4=$(echo $IP|cut -d. -f4)
|
||||
if [ $FIELD1 -le 255 -a $FIELD2 -le 255 -a $FIELD3 -le 255 -a $FIELD4 -le 255 ]; then
|
||||
echo "$IP"
|
||||
res=0
|
||||
else
|
||||
log_error "IP: $IP not available"
|
||||
fi
|
||||
else
|
||||
log_error "$IP: IP format error"
|
||||
fi
|
||||
fi
|
||||
return $res
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
#
|
||||
# create vlan using nmcli
|
||||
|
@ -463,9 +463,9 @@ function stopservice {
|
||||
elif [ -n "$svcd" ];then
|
||||
cmd="service $svcd stop"
|
||||
fi
|
||||
|
||||
echo $cmd
|
||||
|
||||
if [ -n "$cmd" ]; then
|
||||
echo $cmd
|
||||
fi
|
||||
if [ -z "$cmd" ];then
|
||||
return 127
|
||||
fi
|
||||
@ -477,7 +477,6 @@ function stopservice {
|
||||
retmsg=`$cmd 2>&1`
|
||||
retval=$?
|
||||
[ "$retval" = "0" ] && (echo "$retmsg" | grep -i "Running in chroot,\s*ignoring request.*" >/dev/null 2>&1) && retval=1
|
||||
|
||||
return $retval
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user