mirror of
https://github.com/openvswitch/ovs
synced 2025-10-25 15:07:05 +00:00
xenserver: Use ovs-vsctl for controller configuration in xsconsole
This commit is contained in:
@@ -26,8 +26,7 @@ import XenAPI
|
||||
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
|
||||
@@ -63,7 +62,7 @@ def update(session, args):
|
||||
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:":
|
||||
@@ -72,26 +71,20 @@ def vswitchCurrentController():
|
||||
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 = ""
|
||||
@@ -100,19 +93,11 @@ def vswitchCfgQuery(key):
|
||||
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})
|
||||
|
||||
@@ -13,8 +13,7 @@ import os
|
||||
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")
|
||||
@@ -78,10 +77,9 @@ class VSwitchService:
|
||||
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>"
|
||||
@@ -285,7 +283,7 @@ class XSFeatureVSwitch:
|
||||
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:":
|
||||
|
||||
Reference in New Issue
Block a user