From 7c7afa3abfba185f5f5c9a9bd797eaaf2af7d8cd Mon Sep 17 00:00:00 2001 From: ertaozh Date: Fri, 19 Jun 2015 03:18:37 -0400 Subject: [PATCH] add more checks for xHRM for creating bridge --- xCAT-server/share/xcat/scripts/xHRM | 32 ++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/xCAT-server/share/xcat/scripts/xHRM b/xCAT-server/share/xcat/scripts/xHRM index 088f396de..5f8f25dbf 100755 --- a/xCAT-server/share/xcat/scripts/xHRM +++ b/xCAT-server/share/xcat/scripts/xHRM @@ -1,4 +1,8 @@ #!/bin/bash +if [ "$(uname -s|tr 'A-Z' 'a-z')" = "linux" ];then + str_dir_name=`dirname $0` + . $str_dir_name/xcatlib.sh +fi #written in bash for fewest prerequisites function get_def_interface { #gethostbyname on `hostname` would be helpful, but since we @@ -147,6 +151,13 @@ elif [ "bridgeprereq" = "$1" ]; then fi BNAME=$NETDESC fi + + # To check whether the brctl have been installed + if ! which brctl > /dev/null; then + echo "No bridge-utils installed, pls install it first" + exit 1 + fi + if brctl showstp "$BNAME" > /dev/null; then echo "$BNAME" exit 0 @@ -158,6 +169,15 @@ elif [ "bridgeprereq" = "$1" ]; then if [ -z "$PORTS" ]; then #This has been checked many times before in theory, check again just in case exit 1 fi + + #TO check whether the NIC had been attached to another bridge + bridgename=`brctl show |grep $PORTS` + if [ ! -z "$bridgename" ]; then + echo "Device $PORTS is already a member of another bridge" + exit 1 + fi + + #For now, we only support bridge name==network name. This precludes #the config of the same vlan number on multiple fabrics, but #will cover that flexibility later if demanded (with 4k vlan ids, @@ -299,7 +319,17 @@ EOF echo " netmask 255.255.255.0" >> $nwdir/$BNAME fi else - echo "iface $BNAME inet dhcp" >> $nwdir/$BNAME + my_subnet=`ip addr show dev $BNAME scope global|grep inet|grep -v dynamic|sed -e 's/inet.//'| awk '{print $1}'` + if [ ! -z "$my_subnet" ]; then + bridge_ip=`echo "$my_subnet"|cut -d\/ -f 1` + bridge_mask=`echo "$my_subnet"|cut -d\/ -f 2` + bridge_mask=`v4prefix2mask $bridge_mask` + echo "iface $BNAME inet static" >> $nwdir/$BNAME + echo " address $bridge_ip" >> $nwdir/$BNAME + echo " netmask $bridge_mask" >> $nwdir/$BNAME + else + echo "iface $BNAME inet dhcp" >> $nwdir/$BNAME + fi fi echo " bridge_ports $PORTS" >> $nwdir/$BNAME echo " bridge_stp off" >> $nwdir/$BNAME