X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=xenserver%2Fetc_xapi.d_plugins_vswitch-cfg-update;h=7472d1b476fb0298575b933de7cf365857e629b3;hb=c3e3d2a1e72f2fec8580e7974f809846788bc8ff;hp=b21cf46d2bd4734e843500b623eae510a92a3d82;hpb=064af42167bf4fc9aaea2702d80ce08074b889c0;p=openvswitch diff --git a/xenserver/etc_xapi.d_plugins_vswitch-cfg-update b/xenserver/etc_xapi.d_plugins_vswitch-cfg-update index b21cf46d..7472d1b4 100755 --- a/xenserver/etc_xapi.d_plugins_vswitch-cfg-update +++ b/xenserver/etc_xapi.d_plugins_vswitch-cfg-update @@ -6,41 +6,44 @@ # Copyright (C) 2009 Nicira Networks, Inc. # -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. +# http://www.apache.org/licenses/LICENSE-2.0 # -# You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. # 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="/root/vswitch/bin/ovs-cfg-mod" +cfg_mod="/usr/bin/ovs-cfg-mod" vswitchd_cfg_filename="/etc/ovs-vswitchd.conf" +cacert_filename="/etc/ovs-vswitchd.cacert" + +# Delete the CA certificate, so that we go back to boot-strapping mode +def delete_cacert(): + try: + os.remove(cacert_filename) + except OSError: + # Ignore error if file doesn't exist + pass 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: @@ -49,26 +52,21 @@ 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") 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:] @@ -106,8 +104,6 @@ def vswitchCfgMod(action_args): "--config-file=" + vswitchd_cfg_filename] + 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() @@ -115,7 +111,6 @@ def vswitchCfgMod(action_args): 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) ])