commit 57fb6fcbfd11c7be1ccc0bc4c02a459f2a45967e
Author: Guido Trotter <ultrotter@google.com>
Date:   Wed Jun 20 15:03:37 2012 +0100

    Very very very basic openvswitch support
    
    This is a "better than nothing" support, just for kvm and just joining
    the machine to the opevswitch bridge with the right command.
    
    Signed-off-by: Guido Trotter <ultrotter@google.com>
    Reviewed-by: Iustin Pop <iustin@google.com>
    Reviewed-by: René Nussbaumer <rn@google.com>

diff --git a/doc/install.rst b/doc/install.rst
index 8abbfb5..c6a62d9 100644
--- a/doc/install.rst
+++ b/doc/install.rst
@@ -421,12 +421,12 @@ Configuring the network
 
 **Mandatory** on all nodes.
 
-You can run Ganeti either in "bridged mode" or in "routed mode". In
-bridged mode, the default, the instances network interfaces will be
-attached to a software bridge running in dom0. Xen by default creates
-such a bridge at startup, but your distribution might have a different
-way to do things, and you'll definitely need to manually set it up under
-KVM.
+You can run Ganeti either in "bridged mode", "routed mode" or
+"openvswitch mode". In bridged mode, the default, the instances network
+interfaces will be attached to a software bridge running in dom0. Xen by
+default creates such a bridge at startup, but your distribution might
+have a different way to do things, and you'll definitely need to
+manually set it up under KVM.
 
 Beware that the default name Ganeti uses is ``xen-br0`` (which was used
 in Xen 2.0) while Xen 3.0 uses ``xenbr0`` by default. See the
@@ -449,6 +449,10 @@ outside of ganeti. The vif scripts will only add /32 routes to your
 instances, through their interface, in the table you specified (under
 KVM, and in the main table under Xen).
 
+Also for "openvswitch mode" under Xen a custom network script is needed.
+Under KVM everything should work, but you'll need to configure your
+switches outside of Ganeti (as for bridges).
+
 .. admonition:: Bridging issues with certain kernels
 
     Some kernel versions (e.g. 2.6.32) have an issue where the bridge
diff --git a/htools/Ganeti/Types.hs b/htools/Ganeti/Types.hs
index a654b92..e24edaf 100644
--- a/htools/Ganeti/Types.hs
+++ b/htools/Ganeti/Types.hs
@@ -366,6 +366,7 @@ $(THH.makeJSONInstance ''NetworkType)
 $(THH.declareSADT "NICMode"
   [ ("NMBridged", 'C.nicModeBridged)
   , ("NMRouted",  'C.nicModeRouted)
+  , ("NMOvs",     'C.nicModeOvs)
   ])
 $(THH.makeJSONInstance ''NICMode)
 
diff --git a/lib/cmdlib.py b/lib/cmdlib.py
index 9348273..ae39560 100644
--- a/lib/cmdlib.py
+++ b/lib/cmdlib.py
@@ -13053,6 +13053,10 @@ class LUInstanceSetParams(LogicalUnit):
         raise errors.OpPrereqError("Cannot set the NIC IP address to None"
                                    " on a routed NIC", errors.ECODE_INVAL)
 
+    elif new_mode == constants.NIC_MODE_OVS:
+      # TODO: check OVS link
+      self.LogInfo("OVS links are currently not checked for correctness")
+
     if constants.INIC_MAC in params:
       mac = params[constants.INIC_MAC]
       if mac is None:
diff --git a/lib/constants.py b/lib/constants.py
index de13c9d..cedb125 100644
--- a/lib/constants.py
+++ b/lib/constants.py
@@ -1068,9 +1068,10 @@ NIC_LINK = "link"
 
 NIC_MODE_BRIDGED = "bridged"
 NIC_MODE_ROUTED = "routed"
+NIC_MODE_OVS = "openvswitch"
 NIC_IP_POOL = "pool"
 
-NIC_VALID_MODES = frozenset([NIC_MODE_BRIDGED, NIC_MODE_ROUTED])
+NIC_VALID_MODES = frozenset([NIC_MODE_BRIDGED, NIC_MODE_ROUTED, NIC_MODE_OVS])
 
 RESERVE_ACTION = "reserve"
 RELEASE_ACTION = "release"
diff --git a/man/ganeti-os-interface.rst b/man/ganeti-os-interface.rst
index b1f4a17..7c9bef1 100644
--- a/man/ganeti-os-interface.rst
+++ b/man/ganeti-os-interface.rst
@@ -101,17 +101,17 @@ NIC_%N_IP
     instance.
 
 NIC_%N_MODE
-    The NIC mode, either routed or bridged
+    The NIC mode, routed, bridged or openvswitch
 
 NIC_%N_BRIDGE
     The bridge to which this NIC will be attached. This variable is
     defined only when the NIC is in bridged mode.
 
 NIC_%N_LINK
-    If the NIC is in bridged mode, this is the same as
-    ``NIC_%N_BRIDGE``.  If it is in routed mode, the routing table
-    which will be used by the hypervisor to insert the appropriate
-    routes.
+    In bridged or openvswitch mode, this is the interface to which the
+    NIC will be attached (same as ``NIC_%N_BRIDGE`` for bridged). In
+    routed mode it is the routing table which will be used by the
+    hypervisor to insert the appropriate routes.
 
 NIC_%N_FRONTEND_TYPE
     (Optional) If applicable, the type of the exported NIC to the
diff --git a/man/gnt-backup.rst b/man/gnt-backup.rst
index da56299..51b6e2d 100644
--- a/man/gnt-backup.rst
+++ b/man/gnt-backup.rst
@@ -121,15 +121,15 @@ ip
     the node expects the instance to use)
 
 mode
-    specifies the connection mode for this nic: ``routed`` or
-    ``bridged``.
+    specifies the connection mode for this nic: ``routed``,
+    ``bridged`` or ``openvswitch``
 
 link
-    in bridged mode specifies the bridge to attach this NIC to, in
-    routed mode it's intended to differentiate between different
-    routing tables/instance groups (but the meaning is dependent on
-    the network script in use, see **gnt-cluster**(8) for more
-    details)
+    in bridged and openvswitch mode specifies the interface to attach
+    this NIC to, in routed mode it's intended to differentiate between
+    different routing tables/instance groups (but the meaning is
+    dependent on the network script in use, see **gnt-cluster**(8) for
+    more details)
 
 Of these ``mode`` and ``link`` are nic parameters, and inherit their
 default at cluster level.
diff --git a/man/gnt-cluster.rst b/man/gnt-cluster.rst
index ee17ed3..d15e288 100644
--- a/man/gnt-cluster.rst
+++ b/man/gnt-cluster.rst
@@ -363,14 +363,16 @@ parameters for the cluster. The parameter format is a comma-separated
 list of key=value pairs with the following supported keys:
 
 mode
-    The default nic mode, 'routed' or 'bridged'.
+    The default nic mode, 'routed', 'bridged' or 'openvswitch'.
 
 link
-    In bridged mode the default NIC bridge. In routed mode it
-    represents an hypervisor-vif-script dependent value to allow
-    different instance groups. For example under the KVM default
-    network script it is interpreted as a routing table number or
-    name.
+    In bridged or openvswitch mode the default interface where to attach
+    NICs. In routed mode it represents an hypervisor-vif-script
+    dependent value to allow different instance groups. For example
+    under the KVM default network script it is interpreted as a routing
+    table number or name. Openvswitch support is also hypervisor
+    dependent and currently works for the default KVM network script.
+    Under Xen a custom network script must be provided.
 
 The ``-D (--disk-parameters)`` option allows you to set the default disk
 template parameters at cluster level. The format used for this option is
diff --git a/man/gnt-instance.rst b/man/gnt-instance.rst
index db858cd..e269a95 100644
--- a/man/gnt-instance.rst
+++ b/man/gnt-instance.rst
@@ -103,13 +103,16 @@ ip
     the node expects the instance to use)
 
 mode
-    specifies the connection mode for this nic: routed or bridged.
+    specifies the connection mode for this nic: routed, bridged or
+    openvswitch.
 
 link
-    in bridged mode specifies the bridge to attach this NIC to, in
-    routed mode it's intended to differentiate between different
-    routing tables/instance groups (but the meaning is dependent on
-    the network script, see gnt-cluster(8) for more details)
+    in bridged or openvswitch mode specifies the interface to attach
+    this NIC to, in routed mode it's intended to differentiate between
+    different routing tables/instance groups (but the meaning is
+    dependent on the network script, see gnt-cluster(8) for more
+    details). Note that openvswitch support is also hypervisor
+    dependent.
 
 
 Of these "mode" and "link" are nic parameters, and inherit their
diff --git a/tools/kvm-ifup.in b/tools/kvm-ifup.in
index 339e132..e506d73 100644
--- a/tools/kvm-ifup.in
+++ b/tools/kvm-ifup.in
@@ -47,6 +47,10 @@ if [ "$MODE" = "bridged" ]; then
 
   # Connect the interface to the bridge
   brctl addif $BRIDGE $INTERFACE
+
+elif [ "$MODE" = "openvswitch" ]; then
+  ovs-vsctl add-port ${LINK} $INTERFACE
+
 else
   ip link set $INTERFACE up
 
@@ -65,6 +69,7 @@ else
     ip route replace $IP proto static dev $INTERFACE
   fi
 
+  # Allow routing and arp proxying, or ndp proxying (IPv6)
   if [ -d "/proc/sys/net/ipv4/conf/$INTERFACE" ]; then
     echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/proxy_arp
     echo 1 > /proc/sys/net/ipv4/conf/$INTERFACE/forwarding
