X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=xenserver%2Fetc_xapi.d_plugins_openvswitch-cfg-update;h=e2dc939f0515ba758af24d81885c81edc61bd3b7;hb=aae3743bf24cd0e14be726c774a0be49ff0459d7;hp=7333018687347a620e81573953e0cab979e108c7;hpb=6b7b9d34c0eab9871cf6284c41108a84129817f3;p=openvswitch diff --git a/xenserver/etc_xapi.d_plugins_openvswitch-cfg-update b/xenserver/etc_xapi.d_plugins_openvswitch-cfg-update index 73330186..e2dc939f 100755 --- a/xenserver/etc_xapi.d_plugins_openvswitch-cfg-update +++ b/xenserver/etc_xapi.d_plugins_openvswitch-cfg-update @@ -4,7 +4,7 @@ # 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. @@ -64,6 +64,7 @@ def update(session, args): controller = pool["other_config"]["vSwitchController"] except KeyError, e: controller = "" + ret_str = "" currentController = vswitchCurrentController() if controller == "" and currentController != "": delete_cacert() @@ -72,7 +73,7 @@ def update(session, args): except: pass removeControllerCfg() - return "Successfully removed controller config" + ret_str += "Successfully removed controller config. " elif controller != currentController: delete_cacert() try: @@ -80,13 +81,85 @@ def update(session, args): except: pass setControllerCfg(controller) - return "Successfully set controller to " + controller + ret_str += "Successfully set controller to %s. " % controller + + try: + pool_fail_mode = pool["other_config"]["vswitch-controller-fail-mode"] + except KeyError, e: + pool_fail_mode = None + + bton = {} + + for n in session.xenapi.network.get_all(): + rec = session.xenapi.network.get_record(n) + try: + bton[rec['bridge']] = rec + except KeyError: + pass + + dib_changed = False + fail_mode_changed = False + for bridge in vswitchCfgQuery(['list-br']).split(): + network = bton[bridge] + bridge = vswitchCfgQuery(['br-to-parent', bridge]) + + xapi_dib = network['other_config'].get('vswitch-disable-in-band') + if not xapi_dib: + xapi_dib = '' + + ovs_dib = vswitchCfgQuery(['get', 'Bridge', bridge, + 'other_config:disable-in-band']).strip('"') + + # Do nothing if setting is invalid, and warn the user. + if xapi_dib not in ['true', 'false', '']: + ret_str += '"' + xapi_dib + '"' + \ + ' is an invalid value for vswitch-disable-in-band on ' + \ + bridge + ' ' + + # Change bridge disable-in-band option if XAPI and OVS states differ. + elif xapi_dib != ovs_dib: + # 'true' or 'false' + if xapi_dib: + vswitchCfgMod(['--', 'set', 'Bridge', bridge, + 'other_config:disable-in-band=' + xapi_dib]) + # '' or None + else: + vswitchCfgMod(['--', 'remove', 'Bridge', bridge, + 'other_config', 'disable-in-band']) + dib_changed = True + + # Change bridge fail_mode if XAPI state differs from OVS state. + bridge_fail_mode = vswitchCfgQuery(["get", "Bridge", + bridge, "fail_mode"]).strip('[]"') + + try: + fail_mode = bton[bridge]["other_config"]["vswitch-controller-fail-mode"] + except KeyError, e: + fail_mode = None + + if fail_mode not in ['secure', 'standalone']: + fail_mode = pool_fail_mode + + if fail_mode != 'secure': + fail_mode = 'standalone' + + if bridge_fail_mode != fail_mode: + vswitchCfgMod(['--', 'set', 'Bridge', bridge, + "fail_mode=%s" % fail_mode]) + fail_mode_changed = True + + if dib_changed: + ret_str += "Updated in-band management. " + if fail_mode_changed: + ret_str += "Updated fail_mode. " + + if ret_str != '': + return ret_str else: return "No change to configuration" def vswitchCurrentController(): - controller = vswitchCfgQuery(["get", "Open_vSwitch", - ".", "managers"]).strip('[]"') + controller = vswitchCfgQuery(["get-manager"]) if controller == "": return controller if len(controller) < 4 or controller[0:4] != "ssl:": @@ -95,20 +168,19 @@ def vswitchCurrentController(): return controller.split(':')[1] def removeControllerCfg(): - vswitchCfgMod(["--", "clear", "Open_vSwitch", ".", "managers", + vswitchCfgMod(["--", "del-manager", "--", "del-ssl"]) def setControllerCfg(controller): # /etc/xensource/xapi-ssl.pem is mentioned twice below because it # contains both the private key and the certificate. - vswitchCfgMod(["--", "clear", "Open_vSwitch", ".", "managers", + vswitchCfgMod(["--", "del-manager", "--", "del-ssl", "--", "--bootstrap", "set-ssl", "/etc/xensource/xapi-ssl.pem", "/etc/xensource/xapi-ssl.pem", cacert_filename, - "--", "set", "Open_vSwitch", ".", - 'managers="ssl:' + controller + ':6632"']) + "--", "set-manager", 'ssl:' + controller + ':6632']) def vswitchCfgQuery(action_args): cmd = [vsctl, "--timeout=5", "-vANY:console:emer"] + action_args