debian: Add network integration scripts.
authorGurucharan Shetty <gshetty@nicira.com>
Fri, 4 May 2012 02:23:16 +0000 (19:23 -0700)
committerGurucharan Shetty <gshetty@nicira.com>
Sat, 5 May 2012 00:11:02 +0000 (17:11 -0700)
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 <gshetty@nicira.com>
debian/automake.mk
debian/ifupdown.sh [new file with mode: 0755]
debian/openvswitch-switch.README.Debian
debian/openvswitch-switch.install
debian/openvswitch-switch.links [new file with mode: 0644]
debian/rules

index 4425750d2af1ad0ceb6921e2745ce72448507923..046b7c434e6681bfdb1fea558248f362a06272a7 100644 (file)
@@ -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 (executable)
index 0000000..ea36a0d
--- /dev/null
@@ -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
index ef92d3eef5176e4c31a9defaa31f878ec7546527..8580451450752ff8a56a20a813cb196ad3794feb 100644 (file)
@@ -14,3 +14,120 @@ README.Debian for openvswitch-switch
   switch implementation.
 
  -- Ben Pfaff <blp@nicira.com>, 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 <gshetty@nicira.com>, Fri, 04 May 2012 12:58:19 -0700
index 557429b45c7f01c0a61f9820c7fc372deb00783d..4d7a15b17fe337464ea804548147d92499d59d4a 100644 (file)
@@ -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 (file)
index 0000000..0d6d1e0
--- /dev/null
@@ -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
index 4a0e8b583749168e288f2586a9af8907cd3c4103..51a2e51e0aea5608491392220bd2e02418b14714 100755 (executable)
@@ -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