From 2dd26837037ee6b9ff3d8fbdb1eb64b203ad7b02 Mon Sep 17 00:00:00 2001 From: Ethan Jackson Date: Wed, 26 Jan 2011 17:20:41 -0800 Subject: [PATCH] xenserver: Support fail_mode override at network level. This patch allows the Pool object's vswitch-controller-fail-mode setting to be overridden on by Network object. Signed-off-by: Ethan Jackson --- .../etc_xapi.d_plugins_openvswitch-cfg-update | 27 +++++++++++++++---- ..._xensource_libexec_InterfaceReconfigure.py | 19 ++++++++++--- ...rce_libexec_InterfaceReconfigureVswitch.py | 15 ++++++++--- 3 files changed, 48 insertions(+), 13 deletions(-) diff --git a/xenserver/etc_xapi.d_plugins_openvswitch-cfg-update b/xenserver/etc_xapi.d_plugins_openvswitch-cfg-update index b5921f19..5189d043 100755 --- a/xenserver/etc_xapi.d_plugins_openvswitch-cfg-update +++ b/xenserver/etc_xapi.d_plugins_openvswitch-cfg-update @@ -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 diff --git a/xenserver/opt_xensource_libexec_InterfaceReconfigure.py b/xenserver/opt_xensource_libexec_InterfaceReconfigure.py index 3030e0f4..e99ae583 100644 --- a/xenserver/opt_xensource_libexec_InterfaceReconfigure.py +++ b/xenserver/opt_xensource_libexec_InterfaceReconfigure.py @@ -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) diff --git a/xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py b/xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py index 22201ae2..9e069f30 100644 --- a/xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py +++ b/xenserver/opt_xensource_libexec_InterfaceReconfigureVswitch.py @@ -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] -- 2.30.2