From 86b87c92669daca4c69f412de2cc42c255368c4f Mon Sep 17 00:00:00 2001 From: Gurucharan Shetty Date: Thu, 3 May 2012 19:23:16 -0700 Subject: [PATCH] debian: Add network integration scripts. 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 --- debian/automake.mk | 2 + debian/ifupdown.sh | 87 ++++++++++++++++++ debian/openvswitch-switch.README.Debian | 117 ++++++++++++++++++++++++ debian/openvswitch-switch.install | 1 + debian/openvswitch-switch.links | 2 + debian/rules | 1 + 6 files changed, 210 insertions(+) create mode 100755 debian/ifupdown.sh create mode 100644 debian/openvswitch-switch.links diff --git a/debian/automake.mk b/debian/automake.mk index 4425750d..046b7c43 100644 --- a/debian/automake.mk +++ b/debian/automake.mk @@ -43,6 +43,7 @@ EXTRA_DIST += \ debian/openvswitch-switch.postinst \ debian/openvswitch-switch.postrm \ debian/openvswitch-switch.template \ + debian/openvswitch-switch.links \ debian/openvswitch-test.dirs \ debian/openvswitch-test.install \ debian/openvswitch-test.manpages \ @@ -53,6 +54,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 00000000..ea36a0dc --- /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 ef92d3ee..85804514 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 , 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 , Fri, 04 May 2012 12:58:19 -0700 diff --git a/debian/openvswitch-switch.install b/debian/openvswitch-switch.install index 557429b4..4d7a15b1 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.links b/debian/openvswitch-switch.links new file mode 100644 index 00000000..0d6d1e09 --- /dev/null +++ b/debian/openvswitch-switch.links @@ -0,0 +1,2 @@ +usr/share/openvswitch/scripts/ifupdown.sh etc/network/if-pre-up.d/openvswitch +usr/share/openvswitch/scripts/ifupdown.sh etc/network/if-post-down.d/openvswitch diff --git a/debian/rules b/debian/rules index 4a0e8b58..51a2e51e 100755 --- a/debian/rules +++ b/debian/rules @@ -111,6 +111,7 @@ install-arch: build-arch $(MAKE) -C _debian DESTDIR=$(CURDIR)/debian/tmp install cp debian/openvswitch-switch.template debian/openvswitch-switch/usr/share/openvswitch/switch/default.template dh_install -s + dh_link -s # Must not depend on anything. This is to be called by # binary-arch/binary-indep -- 2.30.2