[ovs-discuss] RFC: RedHat net-scripts for Open vSwitch

Alexey I. Froloff raorn at altlinux.org
Thu Oct 13 10:35:24 UTC 2011


Hi!  It's me again, writing some scripts.

I've been using openvswitch on RHEL for a while.  I don't like
rc.local stuff, so I created ifup/ifdown scripts for initscripts
package for configuring interface in RedHat-way.

Before submitting patch to openvswitch, I'd like to test it more
throughly.  If you're brave enough, you can join.

Put two attached files to /etc/sysconfig/network-scripts/, make
it excutable.  Next, create some ifcfg-* scrips:

Standalone bridge:

==> ifcfg-ovsbridge0 <==
DEVICE=ovsbridge0
ONBOOT=yes
DEVICETYPE=ovs
TYPE=OVSBridge
BOOTPROTO=static
IPADDR=A.B.C.D
NETMASK=X.Y.Z.0
HOTPLUG=no


Adding physical eth0 to ovsbridge0 described above:

==> ifcfg-eth0 <==
DEVICE=eth0
ONBOOT=yes
DEVICETYPE=ovs
TYPE=OVSPort
OVS_BRIDGE=internet
BOOTPROTO=none
HOTPLUG=no


Tagged VLAN interface on top of ovsbridge0:

==> ifcfg-vlan100 <==
DEVICE=vlan100
ONBOOT=yes
DEVICETYPE=ovs
TYPE=OVSIntPort
BOOTPROTO=static
IPADDR=A.B.C.D
NETMASK=X.Y.Z.0
OVS_BRIDGE=ovsbridge0
OVS_OPTIONS="tag=100"
OVS_EXTRA="set Interface $DEVICE external-ids:iface-id=$(hostname -s)-$DEVICE-vif"
HOTPLUG=no


Bonding:

==> ifcfg-bond0 <==
DEVICE=bond0
ONBOOT=yes
DEVICETYPE=ovs
TYPE=OVSBond
OVS_BRIDGE=ovsbridge0
BOOTPROTO=none
BOND_IFACES="gige-1b-0 gige-1b-1 gige-21-0 gige-21-1"
OVS_OPTIONS="bond_mode=balance-tcp lacp=active"
HOTPLUG=no

==> ifcfg-gige-* <==
DEVICE=gige-*
ONBOOT=yes
HOTPLUG=no


I believe, this covers all use-cases.  Tested on RHEL 6.1, but
should work on RHEL 5.x.

General rules:

DEVICETYPE must be ovs.  OVS_BRIDGE contains bridge name for
OVSPort, OVSIntPort and OVSBond types.  OVS_OPTIONS contains
column[:key]=value options (see ovs-vsctl(8), add-port command
descriprion).  OVS_EXTRA may contain additional ovs-vsctl
commands, separated by "--" (double dash).  For OVSBond interface
type, BOND_IFACES contains names of all physical interfaces that
should be bonded together.


-- 
Regards,    --
Sir Raorn.   --- http://thousandsofhate.blogspot.com/
-------------- next part --------------
#!/bin/bash

. /etc/init.d/functions

cd /etc/sysconfig/network-scripts
. ./network-functions

[ -f ../network ] && . ../network

CONFIG=${1}

need_config ${CONFIG}

source_config

OTHERSCRIPT="/etc/sysconfig/network-scripts/ifup-${REAL_DEVICETYPE}"

if [ ! -x ${OTHERSCRIPT} ]; then
	OTHERSCRIPT="/etc/sysconfig/network-scripts/ifup-eth"
fi

case "$TYPE" in
	OVSBridge)
		ovs-vsctl -- --may-exist add-br "$DEVICE" $OVS_OPTIONS ${OVS_EXTRA+-- $OVS_EXTRA}
		${OTHERSCRIPT} ${CONFIG} ${2}
		;;
	OVSPort)
		/sbin/ifup "$OVS_BRIDGE"
		${OTHERSCRIPT} ${CONFIG} ${2}
		ovs-vsctl -- --may-exist add-port "$OVS_BRIDGE" "$DEVICE" $OVS_OPTIONS ${OVS_EXTRA+-- $OVS_EXTRA}
		;;
	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}
		${OTHERSCRIPT} ${CONFIG} ${2}
		;;
	OVSBond)
		/sbin/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}
		${OTHERSCRIPT} ${CONFIG} ${2}
		;;
	*)
		echo $"Invalid OVS interface type $TYPE"
		exit 1
		;;
esac
-------------- next part --------------
#!/bin/bash

. /etc/init.d/functions

cd /etc/sysconfig/network-scripts
. ./network-functions

[ -f ../network ] && . ../network

CONFIG=${1}

source_config

. /etc/sysconfig/network

OTHERSCRIPT="/etc/sysconfig/network-scripts/ifdown-${REAL_DEVICETYPE}"

if [ ! -x ${OTHERSCRIPT} ]; then
    OTHERSCRIPT="/etc/sysconfig/network-scripts/ifdown-eth"
fi

case "$TYPE" in
	OVSBridge)
		${OTHERSCRIPT} ${CONFIG} $2
		retval=$?
		ovs-vsctl -- --if-exists del-br "$DEVICE"
		;;
	OVSPort|OVSIntPort|OVSBond)
		${OTHERSCRIPT} ${CONFIG} $2
		retval=$?
		ovs-vsctl -- --if-exists del-port "$OVS_BRIDGE" "$DEVICE"
		;;
	*)
		echo $"Invalid OVS interface type $TYPE"
		exit 1
		;;
esac

exit $retval
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://openvswitch.org/pipermail/ovs-discuss/attachments/20111013/cea154f8/attachment.sig>


More information about the discuss mailing list