debian, rhel, xenserver: Ability to collect ovs-ctl logs.
[sliver-openvswitch.git] / xenserver / opt_xensource_libexec_InterfaceReconfigureBridge.py
index 0fa9322..a93e438 100644 (file)
@@ -15,7 +15,7 @@ from InterfaceReconfigure import *
 import sys
 import time
 
-sysfs_bonding_masters = "/sys/class/net/bonding_masters"
+sysfs_bonding_masters = root_prefix() + "/sys/class/net/bonding_masters"
 
 def open_pif_ifcfg(pif):
     pifrec = db().get_pif_record(pif)
@@ -23,7 +23,7 @@ def open_pif_ifcfg(pif):
     interface = pif_netdev_name(pif)
     log("Configuring %s (%s)" % (interface, pifrec['MAC']))
 
-    f = ConfigurationFile("/etc/sysconfig/network-scripts/ifcfg-%s" % interface)
+    f = ConfigurationFile("%s/etc/sysconfig/network-scripts/ifcfg-%s" % (root_prefix(), interface))
 
     f.write("# DO NOT EDIT: This file (%s) was autogenerated by %s\n" % \
             (os.path.basename(f.path()), os.path.basename(sys.argv[0])))
@@ -69,7 +69,7 @@ def load_bonding_driver():
         log("Failed to load bonding driver: %s" % e)
 
 def bonding_driver_loaded():
-    lines = open("/proc/modules").read().split("\n")
+    lines = open(root_prefix() + "/proc/modules").read().split("\n")
     modules = [line.split(" ")[0] for line in lines]
     return "bonding" in modules
 
@@ -135,34 +135,6 @@ def destroy_bond_device(pif):
 
     __destroy_bond_device(name)
 
-#
-# Bridges
-#
-
-def pif_is_bridged(pif):
-    pifrec = db().get_pif_record(pif)
-    nwrec = db().get_network_record(pifrec['network'])
-
-    if nwrec['bridge']:
-        # TODO: sanity check that nwrec['bridgeless'] != 'true'
-        return True
-    else:
-        # TODO: sanity check that nwrec['bridgeless'] == 'true'
-        return False
-
-def pif_bridge_name(pif):
-    """Return the bridge name of a pif.
-
-    PIF must be a bridged PIF."""
-    pifrec = db().get_pif_record(pif)
-
-    nwrec = db().get_network_record(pifrec['network'])
-
-    if nwrec['bridge']:
-        return nwrec['bridge']
-    else:
-        raise Error("PIF %(uuid)s does not have a bridge name" % pifrec)
-
 #
 # Bring Interface up/down.
 #
@@ -254,7 +226,7 @@ def bring_down_interface(pif, destroy=False):
 def interface_is_up(pif):
     try:
         interface = pif_netdev_name(pif)
-        state = open("/sys/class/net/%s/operstate" % interface).read().strip()
+        state = open("%s/sys/class/net/%s/operstate" % (root_prefix(), interface)).read().strip()
         return state == "up"
     except:
         return False # interface prolly doesn't exist
@@ -295,18 +267,21 @@ def _configure_physical_interface(pif):
 
     pifrec = db().get_pif_record(pif)
 
+    log("Configuring physical interface %s" % pifrec['device'])
+
     f = open_pif_ifcfg(pif)
 
     f.write("TYPE=Ethernet\n")
     f.write("HWADDR=%(MAC)s\n" % pifrec)
 
-    settings,offload = ethtool_settings(pifrec['other_config'])
+    settings,offload = ethtool_settings(pifrec['other_config'],
+                                        PIF_OTHERCONFIG_DEFAULTS)
     if len(settings):
         f.write("ETHTOOL_OPTS=\"%s\"\n" % str.join(" ", settings))
     if len(offload):
         f.write("ETHTOOL_OFFLOAD_OPTS=\"%s\"\n" % str.join(" ", offload))
 
-    mtu = mtu_setting(pifrec['other_config'])
+    mtu = mtu_setting(pifrec['network'], "PIF", pifrec['other_config'])
     if mtu:
         f.write("MTU=%s\n" % mtu)
 
@@ -322,7 +297,7 @@ def pif_get_bond_slaves_sorted(pif):
     # which they were attached.  The first slave attached must be the last detached since
     # the bond is using its MAC address.
     try:
-        attached_slaves = open("/sys/class/net/%s/bonding/slaves" % pifrec['device']).readline().split()
+        attached_slaves = open("%s/sys/class/net/%s/bonding/slaves" % (root_prefix(), pifrec['device'])).readline().split()
         for slave in attached_slaves:
             pifs = [p for p in db().get_pifs_by_device(slave) if not pif_is_vlan(p)]
             slave_pif = pifs[0]
@@ -364,7 +339,7 @@ def _configure_bond_interface(pif):
     if len(offload):
         f.write("ETHTOOL_OFFLOAD_OPTS=\"%s\"\n" % str.join(" ", offload))
 
-    mtu = mtu_setting(pifrec['other_config'])
+    mtu = mtu_setting(pifrec['network'], "Bond-PIF", pifrec['other_config'])
     if mtu:
         f.write("MTU=%s\n" % mtu)
 
@@ -375,6 +350,7 @@ def _configure_bond_interface(pif):
         "downdelay": "200",
         "updelay": "31000",
         "use_carrier": "1",
+        "hashing-algorithm": "src_mac",
         }
 
     # override defaults with values from other-config whose keys being with "bond-"
@@ -414,7 +390,7 @@ def _configure_vlan_interface(pif):
     if len(offload):
         f.write("ETHTOOL_OFFLOAD_OPTS=\"%s\"\n" % str.join(" ", offload))
 
-    mtu = mtu_setting(pifrec['other_config'])
+    mtu = mtu_setting(pifrec['network'], "VLAN-PIF", pifrec['other_config'])
     if mtu:
         f.write("MTU=%s\n" % mtu)
 
@@ -449,6 +425,9 @@ def _configure_pif(pif):
 
 class DatapathBridge(Datapath):
     def __init__(self, pif):
+        if pif_is_tunnel(pif):
+            raise Error("Tunnel PIFs are not supported in Bridge mode")
+
         Datapath.__init__(self, pif)
         log("Configured for Bridge datapath")