# ovs-vswitchd configuration that are managed in the xapi database when
# integrated with Citrix management tools.
-# Copyright (C) 2009, 2010 Nicira Networks, Inc.
+# Copyright (C) 2009, 2010, 2011 Nicira Networks, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
pass
def update(session, args):
+ # Refresh bridge network UUIDs in case this host joined or left a pool.
+ script = "/opt/xensource/libexec/interface-reconfigure"
+ try:
+ retval = subprocess.call([script, "rewrite"])
+ if retval != 0:
+ syslog.syslog("%s exited with status %d" % (script, retval))
+ except OSError, e:
+ syslog.syslog("%s: failed to execute (%s)" % (script, e.strerror))
+
pools = session.xenapi.pool.get_all()
# We assume there is only ever one pool...
if len(pools) == 0:
controller = pool["other_config"]["vSwitchController"]
except KeyError, e:
controller = ""
+ ret_str = ""
currentController = vswitchCurrentController()
if controller == "" and currentController != "":
delete_cacert()
except:
pass
removeControllerCfg()
- return "Successfully removed controller config"
+ ret_str += "Successfully removed controller config. "
elif controller != currentController:
delete_cacert()
try:
except:
pass
setControllerCfg(controller)
- return "Successfully set controller to " + controller
+ ret_str += "Successfully set controller to %s. " % controller
+
+ try:
+ fail_mode = pool["other_config"]["vswitch-controller-fail-mode"]
+ except KeyError, e:
+ fail_mode = None
+
+ if fail_mode != 'secure':
+ fail_mode = 'standalone'
+
+ fail_mode_changed = False
+ for (p, rec) in session.xenapi.PIF.get_all_records().items():
+ try:
+ network = session.xenapi.network.get_record(rec['network'])
+ bridge = network['bridge']
+ except Exception, e:
+ syslog.syslog("%s: failed to get bridge name (%s)" %
+ (script, str(e)))
+ continue
+
+ bridge_fail_mode = vswitchCfgQuery(["get", "Bridge",
+ bridge, "fail_mode"]).strip('[]"')
+
+ 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
+
+ if ret_str != '':
+ return ret_str
else:
return "No change to configuration"
'managers="ssl:' + controller + ':6632"'])
def vswitchCfgQuery(action_args):
- cmd = [vsctl, "-vANY:console:emer"] + action_args
+ cmd = [vsctl, "--timeout=5", "-vANY:console:emer"] + action_args
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()
if len(output) == 0 or output[0] == None:
output = ""
return output
def vswitchCfgMod(action_args):
- cmd = [vsctl, "-vANY:console:emer"] + action_args
+ cmd = [vsctl, "--timeout=5", "-vANY:console:emer"] + action_args
exitcode = subprocess.call(cmd)
if exitcode != 0:
raise XenAPIPlugin.Failure("VSWITCH_CONFIG_MOD_FAILURE",
[ str(exitcode) , str(action_args) ])
def emergency_reset(session, args):
- cmd = [vsctl, "emer-reset"]
+ cmd = [vsctl, "--timeout=5", "emer-reset"]
exitcode = subprocess.call(cmd)
if exitcode != 0:
raise XenAPIPlugin.Failure("VSWITCH_EMER_RESET_FAILURE",