X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=xenserver%2Fetc_xapi.d_plugins_vswitch-cfg-update;h=1ae767fd00bb34b03503821529179db3f9fe4e4d;hb=1723e50ed23af9c66c06e2f899ec6eedce20de80;hp=536a2f32d6e5b04d3bcc1a45cf3644e1180675fd;hpb=eaa3c7e88b315d1d018b702ed3b9bea768a966c5;p=openvswitch diff --git a/xenserver/etc_xapi.d_plugins_vswitch-cfg-update b/xenserver/etc_xapi.d_plugins_vswitch-cfg-update index 536a2f32..1ae767fd 100755 --- a/xenserver/etc_xapi.d_plugins_vswitch-cfg-update +++ b/xenserver/etc_xapi.d_plugins_vswitch-cfg-update @@ -21,17 +21,12 @@ # TBD: - error handling needs to be improved. Currently this can leave # TBD: the system in a bad state if anything goes wrong. -import logging -log = logging.getLogger("vswitch-cfg-update") -logging.basicConfig(filename="/var/log/vswitch-cfg-update.log", level=logging.DEBUG) - import XenAPIPlugin 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 @@ -46,10 +41,8 @@ def update(session, args): pools = session.xenapi.pool.get_all() # We assume there is only ever one pool... if len(pools) == 0: - log.error("No pool for host.") raise XenAPIPlugin.Failure("NO_POOL_FOR_HOST", []) if len(pools) > 1: - log.error("More than one pool for host.") raise XenAPIPlugin.Failure("MORE_THAN_ONE_POOL_FOR_HOST", []) pool = session.xenapi.pool.get_record(pools[0]) try: @@ -58,53 +51,40 @@ def update(session, args): controller = "" currentController = vswitchCurrentController() if controller == "" and currentController != "": - log.debug("Removing controller configuration.") delete_cacert() removeControllerCfg() return "Successfully removed controller config" elif controller != currentController: - if len(controller) == 0: - log.debug("Setting controller to: %s" % (controller)) - else: - log.debug("Changing controller from %s to %s" % (currentController, controller)) delete_cacert() setControllerCfg(controller) return "Successfully set controller to " + controller else: - log.debug("No change to controller configuration required.") - return "No change to configuration" + 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:": - log.warning("Controller does not specify ssl connection type, returning entire string.") return controller else: 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 = "" @@ -113,22 +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: - log.error("ovs-cfg-mod failed with exit code " - + str(exitcode) + " for " + repr(action_args)) 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: - log.error("vswitch reload failed with exit code " + str(exitcode)) - raise XenAPIPlugin.Failure("VSWITCH_CFG_RELOAD_FAILURE", [ str(exitcode) ]) - if __name__ == "__main__": XenAPIPlugin.dispatch({"update": update})