2
0
mirror of https://github.com/xcat2/xcat-core.git synced 2025-08-10 05:20:14 +00:00

confignetwork refine using nmcli

This commit is contained in:
bybai
2019-03-08 04:12:45 -05:00
parent 7ca49589dd
commit 72760749a2
2 changed files with 112 additions and 26 deletions

View File

@@ -559,7 +559,11 @@ function configure_nicdevice {
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 [ "$networkmanager_active" = "0" ]; then
create_bridge_interface ifname=$nic_dev _brtype=$nic_dev_type _port=$base_nic_dev _pretype=$base_nic_type
elif [ "$networkmanager_active" = "1" ]; then
create_bridge_interface_nmcli ifname=$nic_dev _brtype=$nic_dev_type _port=$base_nic_dev _pretype=$base_nic_type
fi
fi
#configure vlan
elif [ x"$nic_dev_type" = "xvlan" ]; then
@@ -570,11 +574,18 @@ function configure_nicdevice {
vlanid=`echo "$nic_dev" | $sed -e 's/^\(.*\)vla\?n\?\([0-9]\+\)$/\2/'`
vlanname=`echo "$nic_dev" | $sed -e 's/^\(.*\)vla\?n\?\([0-9]\+\)$/\1/'`
fi
create_vlan_interface ifname=$vlanname vlanid=$vlanid
if [ "$networkmanager_active" = "0" ]; then
create_vlan_interface ifname=$vlanname vlanid=$vlanid
elif [ "$networkmanager_active" = "1" ]; then
create_vlan_interface_nmcli ifname=$vlanname vlanid=$vlanid
fi
#configure bond
elif [ x"$nic_dev_type" = "xbond" ]; then
create_bond_interface ifname=$nic_dev slave_ports=$base_nic_for_bond slave_type=$base_nic_type
if [ "$networkmanager_active" = "0" ]; then
create_bond_interface ifname=$nic_dev slave_ports=$base_nic_for_bond slave_type=$base_nic_type
elif [ "$networkmanager_active" = "1" ]; then
create_bond_interface_nmcli ifname=$nic_dev slave_ports=$base_nic_for_bond slave_type=$base_nic_type
fi
elif [ x"$nic_dev_type" = "xinfiniband" ] || [ x"$nic_dev_type" = "xOmnipath" ]; then
log_info "Call configib for IB nics: $nic_dev, ports: $num_iba_ports"
log_info "NIC_IBNICS=$nic_dev NIC_IBAPORTS=$num_iba_ports configib"
@@ -593,26 +604,6 @@ function configure_nicdevice {
return $errorcode
}
############################################################################
#
# disable NetworkManager and start network
#
###########################################################################
function enable_network_service {
checkservicestatus NetworkManager > /dev/null
if [ $? -eq 0 ]; then
log_info "NetworkManager is active. start to stop it ..."
stopservice NetworkManager | log_lines info
disableservice NetworkManager
enableservice network
startservice network
else
log_info "NetworkManager is inactive."
fi
}
############################################################################
#
# Main process
@@ -644,6 +635,17 @@ 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'`
@@ -695,8 +697,6 @@ if [ -n "$valid_sorted_nicdevice_list" ]; then
log_info "All valid nics and device list:"
echo "$valid_sorted_nicdevice_list" |log_lines info
fi
#enable network service
enable_network_service
#config nics and ifcfg files
configure_nicdevice "$valid_sorted_nicdevice_list"

View File

@@ -743,6 +743,17 @@ function check_brctl() {
fi
}
###############################################################################
#
# check and set device managed
# input: ifname
# output: 0 managed
# 1 umanaged
#
###############################################################################
function check_and_set_device_managed() {
ifname=$1
}
###############################################################################
#
@@ -1548,3 +1559,78 @@ function decode_arguments {
return $rc
}
###############################################################################
#
# check NetworkManager
# output: 2 error
# 1 using NetworkManager
# 0 using network
#
##############################################################################
function check_NetworkManager_or_network_service() {
#check NetworkManager is active
checkservicestatus NetworkManager > /dev/null 2>/dev/null
if [ $? -eq 0 ]; then
log_info "NetworkManager is active"
#check nmcli is installed
type $nmcli >/dev/null 2>/dev/null
if [ $? -ne 0 ]; then
log_error "There is no nmcli"
fi
stopservice network
stopservice networking
return 1
else
checkservicestatus network > /dev/null 2>/dev/null
if [ $? -eq 0 ]; then
log_info "network service is active"
return 0
fi
checkservicestatus networking > /dev/null 2>/dev/null
if [ $? -eq 0 ]; then
log_info "networking service is active"
return 0
fi
log_error "NetworkManager, network.service and networking service are not active"
return 2
fi
}
###############################################################################
#
# create vlan using nmcli
#
# input : ifname=<ifname> slave_ports=<ports> xcatnet=<xcatnetwork> _ipaddr=<ip> _netmask=<netmask> _mtu=<mtu> _bridge=<bridge_name> vlanid=<vlanid>
# return : 0 success
#
###############################################################################
function create_vlan_interface_nmcli {
log_info "create_vlan_interface_nmcli $@"
}
###############################################################################
#
# create bridge
#
# input : ifname=<ifname> xcatnet=<xcat_network> _ipaddr=<ip> _netmask=<netmask> _port=<port> _pretype=<nic_type> _brtype=<bridge|bridge_ovs> _mtu=<mtu> _bridge=<bridge_name>
#
###############################################################################
function create_bridge_interface_nmcli {
log_info "create_bridge_interface_nmcli $@"
}
#############################################################################################################################
#
# create bond or bond->vlan interface
# https://www.kernel.org/doc/Documentation/networking/bonding.txt
# https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Networking_Guide/sec-Using_Channel_Bonding.html
#
# input : ifname=<nic> xcatnet=<xcatnetwork> _ipaddr=<ip> _netmask=<netmask> _bonding_opts=<bonding_opts> _mtu=<mtu> slave_ports=<port1,port2>
#
############################################################################################################################
function create_bond_interface_nmcli {
log_info "create_bond_interface $@"
}