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():
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
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),
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)
'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]