Add scripts that will allow Open vSwitch bridges and ports to be configured through /etc/network/interfaces. This patch follows a very similar style as OVS network integration for rhel.
Signed-off-by: Gurucharan Shetty <[email protected]> --- debian/automake.mk | 1 + debian/ifupdown.sh | 87 +++++++++++++++++++++++ debian/openvswitch-switch.README.Debian | 117 +++++++++++++++++++++++++++++++ debian/openvswitch-switch.install | 1 + debian/openvswitch-switch.postinst | 5 ++ debian/openvswitch-switch.postrm | 2 + 6 files changed, 213 insertions(+), 0 deletions(-) create mode 100755 debian/ifupdown.sh diff --git a/debian/automake.mk b/debian/automake.mk index 4425750..0dca489 100644 --- a/debian/automake.mk +++ b/debian/automake.mk @@ -53,6 +53,7 @@ EXTRA_DIST += \ debian/python-openvswitch.install \ debian/rules \ debian/rules.modules \ + debian/ifupdown.sh \ debian/source/format check-debian-changelog-version: diff --git a/debian/ifupdown.sh b/debian/ifupdown.sh new file mode 100755 index 0000000..ea36a0d --- /dev/null +++ b/debian/ifupdown.sh @@ -0,0 +1,87 @@ +#! /bin/sh + +# Copyright (c) 2012 Nicira, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Have a look at /usr/share/doc/openvswitch-switch/README.Debian +# for more information about configuring the /etc/network/interfaces. + +if [ -z "${IF_OVS_TYPE}" ]; then + exit 0 +fi + +ovs_vsctl() { + ovs-vsctl --no-wait --timeout=5 "$@" +} + +if (ovs_vsctl --version) > /dev/null 2>&1; then :; else + exit 0 +fi + +if [ "${MODE}" = "start" ]; then + eval OVS_EXTRA=\"${IF_OVS_EXTRA}\" + + case "${IF_OVS_TYPE}" in + OVSBridge) + ovs_vsctl -- --may-exist add-br "${IFACE}" ${IF_OVS_OPTIONS}\ + ${OVS_EXTRA+-- $OVS_EXTRA} + + if [ ! -z "${IF_OVS_PORTS}" ]; then + ifup --allow="${IFACE}" ${IF_OVS_PORTS} + fi + ;; + OVSPort) + ovs_vsctl -- --may-exist add-port "${IF_OVS_BRIDGE}"\ + "${IFACE}" ${IF_OVS_OPTIONS} \ + ${OVS_EXTRA+-- $OVS_EXTRA} + + ifconfig "${IFACE}" up + ;; + OVSIntPort) + ovs_vsctl -- --may-exist add-port "${IF_OVS_BRIDGE}"\ + "${IFACE}" ${IF_OVS_OPTIONS} -- set Interface "${IFACE}"\ + type=internal ${OVS_EXTRA+-- $OVS_EXTRA} + + ifconfig "${IFACE}" up + ;; + OVSBond) + ovs_vsctl -- --fake-iface add-bond "${IF_OVS_BRIDGE}"\ + "${IFACE}" ${IF_OVS_BONDS} ${IF_OVS_OPTIONS} \ + ${OVS_EXTRA+-- $OVS_EXTRA} + + ifconfig "${IFACE}" up + ;; + *) + exit 0 + ;; + esac +elif [ "${MODE}" = "stop" ]; then + case "${IF_OVS_TYPE}" in + OVSBridge) + if [ ! -z "${IF_OVS_PORTS}" ]; then + ifdown --allow="${IFACE}" ${IF_OVS_PORTS} + fi + + ovs_vsctl -- --if-exists del-br "${IFACE}" + ;; + OVSPort|OVSIntPort|OVSBond) + ovs_vsctl -- --if-exists del-port "${IF_OVS_BRIDGE}" "${IFACE}" + ;; + *) + exit 0 + ;; + esac +fi + +exit 0 diff --git a/debian/openvswitch-switch.README.Debian b/debian/openvswitch-switch.README.Debian index ef92d3e..8580451 100644 --- a/debian/openvswitch-switch.README.Debian +++ b/debian/openvswitch-switch.README.Debian @@ -14,3 +14,120 @@ README.Debian for openvswitch-switch switch implementation. -- Ben Pfaff <[email protected]>, Mon, 30 Aug 2010 09:51:19 -0700 + +Debian network scripts integration +---------------------------------- +This package lets a user to optionally configure Open vSwitch bridges +and ports from /etc/network/interfaces. Please refer to the interfaces(5) +manpage for more details regarding /etc/network/interfaces. + +The stanzas that configure the OVS bridges should begin with "allow-ovs" +followed by name of the bridge. Here is an example. +allow-ovs br0 + +The stanzas that configure the OVS ports should begin with +"allow-${bridge-name}" followed by name of the port. Here is an example. +allow-br0 eth0 + +The following OVS specific "command" options are supported: + + - ovs_type: This can either be OVSBridge, OVSPort, OVSIntPort or OVSBond + depending on whether you configure a bridge, port, an internal port or + a bond. This is a required option. + + - ovs_ports: This option specifies all the ports that belong to a bridge. + + - ovs_bridge: This options specifies a bridge to which a port belongs. + This is a required option for a port. + + - ovs_bonds: This option specifies the list of physical interfaces to be + bonded together. + + - ovs_options: This option lets you add extra arguments to a ovs-vsctl + command. See examples. + + - ovs_extra: This option lets you run additional ovs-vsctl commands, + separated by "--" (double dash). Variables can be part of the "ovs_extra" + option. You can provide all the standard environmental variables + described in the interfaces(5) man page. You can also pass shell + commands. + +More implementation specific details can be seen in the examples. + +Examples: +-------- +ex 1: A standalone bridge. + +allow-ovs br0 +iface br0 inet static + address 192.168.1.1 + netmask 255.255.255.0 + ovs_type OVSBridge + +ex 2: A bridge with one port. + +allow-ovs br0 +iface br0 inet dhcp + ovs_type OVSBridge + ovs_ports eth0 + +allow-br0 eth0 +iface eth0 inet manual + ovs_bridge br0 + ovs_type OVSPort + +ex 3: A bridge with multiple physical ports. + +allow-ovs br0 +iface br0 inet dhcp + ovs_type OVSBridge + ovs_ports eth0 eth1 + +allow-br0 eth0 +iface eth0 inet manual + ovs_bridge br0 + ovs_type OVSPort + +allow-br0 eth1 +iface eth1 inet manual + ovs_bridge br0 + ovs_type OVSPort + +ex 4: A bridge with an OVS internal port. + +allow-ovs br1 +iface br1 inet static + address 192.168.1.1 + netmask 255.255.255.0 + ovs_type OVSBridge + ovs_ports vlan100 + +allow-br1 vlan100 +iface vlan100 inet manual + ovs_bridge br1 + ovs_type OVSIntPort + ovs_options tag=100 + ovs_extra set interface ${IFACE} external-ids:iface-id=$(hostname -s) + +ex 5: Bonding. + +allow-ovs br2 +iface br2 inet static + address 192.170.1.1 + netmask 255.255.255.0 + ovs_type OVSBridge + ovs_ports bond0 + +allow-br2 bond0 +iface bond0 inet manual + ovs_bridge br2 + ovs_type OVSBond + ovs_bonds eth2 eth3 + ovs_options bond_mode=balance-tcp lacp=active + +ex 6: Create and destroy bridges. + +ifup --allow=ovs $list_of_bridges +ifdown --allow=ovs $list_of_bridges + +-- Gurucharan Shetty <[email protected]>, Fri, 04 May 2012 12:58:19 -0700 diff --git a/debian/openvswitch-switch.install b/debian/openvswitch-switch.install index 557429b..4d7a15b 100644 --- a/debian/openvswitch-switch.install +++ b/debian/openvswitch-switch.install @@ -11,3 +11,4 @@ usr/share/openvswitch/scripts/ovs-ctl usr/share/openvswitch/scripts/ovs-lib usr/share/openvswitch/scripts/ovs-save usr/share/openvswitch/vswitch.ovsschema +debian/ifupdown.sh usr/share/openvswitch/scripts diff --git a/debian/openvswitch-switch.postinst b/debian/openvswitch-switch.postinst index 7b9d7bc..22ce434 100755 --- a/debian/openvswitch-switch.postinst +++ b/debian/openvswitch-switch.postinst @@ -33,6 +33,11 @@ case "$1" in fi done fi + + ln -s /usr/share/openvswitch/scripts/ifupdown.sh \ + /etc/network/if-pre-up.d/openvswitch || true + ln -s /usr/share/openvswitch/scripts/ifupdown.sh \ + /etc/network/if-post-down.d/openvswitch || true ;; abort-upgrade|abort-remove|abort-deconfigure) diff --git a/debian/openvswitch-switch.postrm b/debian/openvswitch-switch.postrm index baf37c8..ab963e2 100755 --- a/debian/openvswitch-switch.postrm +++ b/debian/openvswitch-switch.postrm @@ -26,6 +26,8 @@ case "$1" in rm -f /etc/default/openvswitch-switch rm -f /var/log/openvswitch/ovs-vswitchd.log* || true rm -f /var/log/openvswitch/ovsdb-server.log* || true + rm -f /etc/network/if-pre-up.d/openvswitch || true + rm -f /etc/network/if-post-down.d/openvswitch || true ;; remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear) -- 1.7.2.5 _______________________________________________ dev mailing list [email protected] http://openvswitch.org/mailman/listinfo/dev
