xenserver: Use ovs-vsctl for controller configuration in xsconsole
authorJustin Pettit <jpettit@nicira.com>
Fri, 18 Dec 2009 22:14:37 +0000 (14:14 -0800)
committerJustin Pettit <jpettit@nicira.com>
Mon, 21 Dec 2009 06:05:22 +0000 (22:05 -0800)
xenserver/etc_xapi.d_plugins_vswitch-cfg-update
xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py

index 7472d1b476fb0298575b933de7cf365857e629b3..1ae767fd00bb34b03503821529179db3f9fe4e4d 100755 (executable)
@@ -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})
index 31a48c37dc47ac0586efdcabb2986a31c73c9f43..99dd15d8da52bdd5d7ca958c0443b305ee0b108c 100644 (file)
@@ -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:":