xenserver: Support fail_mode override at network level.
authorEthan Jackson <ethan@nicira.com>
Thu, 27 Jan 2011 01:20:41 +0000 (17:20 -0800)
committerEthan Jackson <ethan@nicira.com>
Thu, 27 Jan 2011 02:17:37 +0000 (18:17 -0800)
This patch allows the Pool object's vswitch-controller-fail-mode
setting to be overridden on by Network object.

Signed-off-by: Ethan Jackson <ethan@nicira.com>
xenserver/etc_xapi.d_plugins_openvswitch-cfg-update
xenserver/opt_xensource_libexec_InterfaceReconfigure.py
xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py

index b5921f1942e3afc26d6e2aff33867056e347fe72..5189d0436c333a5f90b6f46e6c65b2811aff7676 100755 (executable)
@@ -84,12 +84,18 @@ def update(session, args):
         ret_str += "Successfully set controller to %s.  " % controller
 
     try:
-        fail_mode = pool["other_config"]["vswitch-controller-fail-mode"]
+        pool_fail_mode = pool["other_config"]["vswitch-controller-fail-mode"]
     except KeyError, e:
-        fail_mode = None
+        pool_fail_mode = None
 
-    if fail_mode != 'secure':
-        fail_mode = 'standalone'
+    bton = {}
+
+    for n in session.xenapi.network.get_all():
+        rec = session.xenapi.network.get_record(n)
+        try:
+            bton[rec['bridge']] = rec
+        except KeyError:
+            pass
 
     fail_mode_changed = False
     for bridge in vswitchCfgQuery(['list-br']).split():
@@ -97,13 +103,24 @@ def update(session, args):
         bridge_fail_mode = vswitchCfgQuery(["get", "Bridge",
             bridge, "fail_mode"]).strip('[]"')
 
+        try:
+            fail_mode = bton[bridge]["other_config"]["vswitch-controller-fail-mode"]
+        except KeyError, e:
+            fail_mode = None
+
+        if fail_mode not in ['secure', 'standalone']:
+            fail_mode = pool_fail_mode
+
+        if fail_mode != 'secure':
+            fail_mode = 'standalone'
+
         if bridge_fail_mode != fail_mode:
             vswitchCfgMod(['--', 'set', 'Bridge', bridge,
                 "fail_mode=%s" % fail_mode])
             fail_mode_changed = True
 
     if fail_mode_changed:
-        ret_str += "Set fail_mode to %s.  " % fail_mode
+        ret_str += "Updated fail_mode.  "
 
     if ret_str != '':
         return ret_str
index 3030e0f4b99370bbdb5a63ea5b9e4c2a638f5d61..e99ae5834a62f2e1922a8d1ce71fff08407836f2 100644 (file)
@@ -331,7 +331,7 @@ _BOND_ATTRS = { 'uuid': (_str_to_xml,_str_from_xml),
                           lambda n: _strlist_from_xml(n, 'slaves', 'slave')),
               }
 
-_NETWORK_OTHERCONFIG_ATTRS = [ 'mtu', 'static-routes' ] + _ETHTOOL_OTHERCONFIG_ATTRS
+_NETWORK_OTHERCONFIG_ATTRS = [ 'mtu', 'static-routes', 'vswitch-controller-fail-mode' ] + _ETHTOOL_OTHERCONFIG_ATTRS
 
 _NETWORK_ATTRS = { 'uuid': (_str_to_xml,_str_from_xml),
                    'bridge': (_str_to_xml,_str_from_xml),
@@ -604,10 +604,21 @@ class DatabaseCache(object):
                    filter(lambda (ref,rec): rec['device'] == device,
                           self.__pifs.items()))
 
+    def get_networks_with_bridge(self, bridge):
+        return map(lambda (ref,rec): ref,
+                  filter(lambda (ref,rec): rec['bridge'] == bridge,
+                         self.__networks.items()))
+
+    def get_network_by_bridge(self, bridge):
+        #Assumes one network has bridge.
+        try:
+            return self.get_networks_with_bridge(bridge)[0]
+        except KeyError:
+            return None
+
     def get_pif_by_bridge(self, bridge):
-        networks = map(lambda (ref,rec): ref,
-                       filter(lambda (ref,rec): rec['bridge'] == bridge,
-                              self.__networks.items()))
+        networks = self.get_networks_with_bridge(bridge)
+
         if len(networks) == 0:
             raise Error("No matching network \"%s\"" % bridge)
 
index 22201ae27007059f7270b5321877890a7346b5b2..9e069f306be5051cd429e712c24f4e2c35589597 100644 (file)
@@ -332,14 +332,21 @@ def configure_datapath(pif):
                    'other-config:hwaddr=%s' % vsctl_escape(db().get_pif_record(pif)['MAC'])]
 
     pool = db().get_pool_record()
+    network = db().get_network_by_bridge(bridge)
+    fail_mode = None
+    valid_fail_modes = ['standalone', 'secure']
 
-    if pool:
+    if network:
+        network_rec = db().get_network_record(network)
+        fail_mode = network_rec['other_config'].get('vswitch-controller-fail-mode')
+
+    if (fail_mode not in valid_fail_modes) and pool:
         fail_mode = pool['other_config'].get('vswitch-controller-fail-mode')
-    else:
+
+    if fail_mode not in valid_fail_modes:
         fail_mode = 'standalone'
 
-    if fail_mode in ['standalone', 'secure']:
-        vsctl_argv += ['--', 'set', 'Bridge', bridge, 'fail_mode=%s' % fail_mode]
+    vsctl_argv += ['--', 'set', 'Bridge', bridge, 'fail_mode=%s' % fail_mode]
 
     vsctl_argv += set_br_external_ids(pif)
     vsctl_argv += ['## done configuring datapath %s' % bridge]