X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=rhel%2Fetc_sysconfig_network-scripts_ifup-ovs;h=8904c59b909fed25fd96a7e6e157f9b3a53f82f1;hb=85606e05b691be7c2f2d4bcf0e91170b71ec8fbb;hp=7074c072ed3fb49a7cad7060680cad026210a867;hpb=0fb426263e7834f7403eefd860cf5d36d43f8c45;p=sliver-openvswitch.git diff --git a/rhel/etc_sysconfig_network-scripts_ifup-ovs b/rhel/etc_sysconfig_network-scripts_ifup-ovs index 7074c072e..8904c59b9 100755 --- a/rhel/etc_sysconfig_network-scripts_ifup-ovs +++ b/rhel/etc_sysconfig_network-scripts_ifup-ovs @@ -22,6 +22,7 @@ cd /etc/sysconfig/network-scripts [ -f ../network ] && . ../network CONFIG=${1} +TIMEOUT=10 need_config ${CONFIG} @@ -33,28 +34,88 @@ if [ ! -x ${OTHERSCRIPT} ]; then OTHERSCRIPT="/etc/sysconfig/network-scripts/ifup-eth" fi +check_recursion () +{ + [ -n "${UPPEDSTACK}" ] && for _r in ${UPPEDSTACK}; do + [ "$_r" = "$1" ] && return 1 + done + + return 0 +} + +ifup_ovs_bridge () +{ + if ovs-vsctl br-exists "${OVS_BRIDGE}"; then :; else + /sbin/ifup "${OVS_BRIDGE}" + fi +} + +if [ -z "${UPPEDSTACK}" ]; then + UPPEDSTACK="${DEVICE}" +fi + +[ -n "${OVSREQUIRES}" ] && for _i in ${OVSREQUIRES}; do + if ( check_recursion "$_i" ); then + UPPEDSTACK="${UPPEDSTACK} $_i" /sbin/ifup "$_i" + fi +done + +[ -f /var/lock/subsys/openvswitch ] || /sbin/service openvswitch start + case "$TYPE" in OVSBridge) - ovs-vsctl -- --may-exist add-br "$DEVICE" $OVS_OPTIONS ${OVS_EXTRA+-- $OVS_EXTRA} - ${OTHERSCRIPT} ${CONFIG} ${2} + # If bridge already exists and is up, it has been configured through + # other cases like OVSPort, OVSIntPort and OVSBond. If it is down or + # it does not exist, create it. It is possible for a bridge to exist + # because it remained in the OVSDB for some reason, but it won't be up. + if check_device_down "${DEVICE}"; then + ovs-vsctl -t ${TIMEOUT} -- --may-exist add-br "$DEVICE" $OVS_OPTIONS \ + ${OVS_EXTRA+-- $OVS_EXTRA} \ + ${STP+-- set bridge "$DEVICE" stp_enable="${STP}"} + else + OVSBRIDGECONFIGURED="yes" + fi + + # When dhcp is enabled, the assumption is that there will be a port to + # attach (otherwise, we can't reach out for dhcp). So, we do not + # configure the bridge through rhel's ifup infrastructure unless + # it is being configured after the port has been configured. + # The "OVSINTF" is set only after the port is configured. + if [ "${OVSBOOTPROTO}" = "dhcp" ] && [ -n "${OVSINTF}" ]; then + case " ${OVSDHCPINTERFACES} " in + *" ${OVSINTF} "*) + BOOTPROTO=dhcp ${OTHERSCRIPT} ${CONFIG} + ;; + esac + fi + + # When dhcp is not enabled, it is possible that someone may want + # a standalone bridge (i.e it may not have any ports). Configure it. + if [ "${OVSBOOTPROTO}" != "dhcp" ] && [ -z "${OVSINTF}" ] && \ + [ "${OVSBRIDGECONFIGURED}" != "yes" ]; then + ${OTHERSCRIPT} ${CONFIG} + fi + exit 0 ;; OVSPort) - /sbin/ifup "$OVS_BRIDGE" + ifup_ovs_bridge ${OTHERSCRIPT} ${CONFIG} ${2} - ovs-vsctl -- --may-exist add-port "$OVS_BRIDGE" "$DEVICE" $OVS_OPTIONS ${OVS_EXTRA+-- $OVS_EXTRA} + ovs-vsctl -t ${TIMEOUT} -- --may-exist add-port "$OVS_BRIDGE" "$DEVICE" $OVS_OPTIONS ${OVS_EXTRA+-- $OVS_EXTRA} + OVSINTF=${DEVICE} /sbin/ifup "$OVS_BRIDGE" ;; OVSIntPort) - /sbin/ifup "$OVS_BRIDGE" - ovs-vsctl -- --may-exist add-port "$OVS_BRIDGE" "$DEVICE" $OVS_OPTIONS -- set Interface "$DEVICE" type=internal ${OVS_EXTRA+-- $OVS_EXTRA} + ifup_ovs_bridge + ovs-vsctl -t ${TIMEOUT} -- --may-exist add-port "$OVS_BRIDGE" "$DEVICE" $OVS_OPTIONS -- set Interface "$DEVICE" type=internal ${OVS_EXTRA+-- $OVS_EXTRA} ${OTHERSCRIPT} ${CONFIG} ${2} ;; OVSBond) - /sbin/ifup "$OVS_BRIDGE" + ifup_ovs_bridge for _iface in $BOND_IFACES; do /sbin/ifup ${_iface} done - ovs-vsctl -- --fake-iface add-bond "$OVS_BRIDGE" "$DEVICE" ${BOND_IFACES} $OVS_OPTIONS ${OVS_EXTRA+-- $OVS_EXTRA} + ovs-vsctl -t ${TIMEOUT} -- --fake-iface add-bond "$OVS_BRIDGE" "$DEVICE" ${BOND_IFACES} $OVS_OPTIONS ${OVS_EXTRA+-- $OVS_EXTRA} ${OTHERSCRIPT} ${CONFIG} ${2} + OVSINTF=${DEVICE} /sbin/ifup "$OVS_BRIDGE" ;; *) echo $"Invalid OVS interface type $TYPE"