import os
import subprocess
-cfg_mod="/usr/bin/ovs-cfg-mod"
-vswitchd_cfg_filename="/etc/ovs-vswitchd.conf"
+vsctl="/usr/bin/ovs-vsctl"
cacert_filename="/etc/ovs-vswitchd.cacert"
# Delete the CA certificate, so that we go back to boot-strapping mode
return "No change to configuration"
def vswitchCurrentController():
- controller = vswitchCfgQuery("mgmt.controller")
+ controller = vswitchCfgQuery("get-controller")
if controller == "":
return controller
if len(controller) < 4 or controller[0:4] != "ssl:":
return controller[4:]
def removeControllerCfg():
- vswitchCfgMod(["--del-match", "mgmt.controller=*",
- "--del-match", "ssl.bootstrap-ca-cert=*",
- "--del-match", "ssl.ca-cert=*",
- "--del-match", "ssl.private-key=*",
- "--del-match", "ssl.certificate=*"])
+ vswitchCfgMod(["--", "del-controller",
+ "--", "del-ssl"])
def setControllerCfg(controller):
- vswitchCfgMod(["--del-match", "mgmt.controller=*",
- "--del-match", "ssl.bootstrap-ca-cert=*",
- "--del-match", "ssl.ca-cert=*",
- "--del-match", "ssl.private-key=*",
- "--del-match", "ssl.certificate=*",
- "-a", "mgmt.controller=ssl:" + controller,
- "-a", "ssl.bootstrap-ca-cert=true",
- "-a", "ssl.ca-cert=/etc/ovs-vswitchd.cacert",
- "-a", "ssl.private-key=/etc/xensource/xapi-ssl.pem",
- "-a", "ssl.certificate=/etc/xensource/xapi-ssl.pem"])
+ vswitchCfgMod(["--", "del-controller",
+ "--", "del-ssl",
+ "--", "--bootstrap", "set-ssl",
+ "/etc/xensource/xapi-ssl.pem",
+ "/etc/xensource/xapi-ssl.pem",
+ "/etc/ovs-vswitchd.cacert",
+ "--", "set-controller", "ssl:" + controller])
-def vswitchCfgQuery(key):
- cmd = [cfg_mod, "--config-file=" + vswitchd_cfg_filename, "-q", key]
+def vswitchCfgQuery(action):
+ cmd = [vsctl, "-vANY:console:emer", action]
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()
if len(output) == 0 or output[0] == None:
output = ""
return output
def vswitchCfgMod(action_args):
- cmd = [cfg_mod, "-vANY:console:emer",
- "--config-file=" + vswitchd_cfg_filename] + action_args
+ cmd = [vsctl, "-vANY:console:emer"] + action_args
exitcode = subprocess.call(cmd)
if exitcode != 0:
raise XenAPIPlugin.Failure("VSWITCH_CONFIG_MOD_FAILURE",
[ str(exitcode) , str(action_args) ])
- vswitchReload()
-def vswitchReload():
- exitcode = subprocess.call(["/sbin/service", "vswitch", "reload"])
- if exitcode != 0:
- raise XenAPIPlugin.Failure("VSWITCH_CFG_RELOAD_FAILURE", [ str(exitcode) ])
-
-
if __name__ == "__main__":
XenAPIPlugin.dispatch({"update": update})
import socket
import subprocess
-cfg_mod="/usr/bin/ovs-cfg-mod"
-vswitchd_cfg_filename="/etc/ovs-vswitchd.conf"
+vsctl="/usr/bin/ovs-vsctl"
if __name__ == "__main__":
raise Exception("This script is a plugin for xsconsole and cannot run independently")
class VSwitchConfig:
@staticmethod
- def Get(key):
+ def Get(action):
try:
- output = ShellPipe([cfg_mod, "-vANY:console:emer", "-F",
- vswitchd_cfg_filename, "-q", key]).Stdout()
+ output = ShellPipe([vsctl, "-vANY:console:emer", action]).Stdout()
except StandardError, e:
XSLogError("config retrieval error: " + str(e))
return "<unknown>"
if dbController == "":
dbController = Lang("<None>")
inPane.AddStatusField(Lang("Controller (config)", 20), dbController)
- controller = VSwitchConfig.Get("mgmt.controller")
+ controller = VSwitchConfig.Get("get-controller")
if controller == "":
controller = Lang("<None>")
elif controller[0:4] == "ssl:":