xenserver: Retrieve vSwitch version from binary in xsconsole
authorJustin Pettit <jpettit@nicira.com>
Tue, 28 Jul 2009 22:24:32 +0000 (15:24 -0700)
committerJustin Pettit <jpettit@nicira.com>
Tue, 28 Jul 2009 22:24:32 +0000 (15:24 -0700)
The xsconsole plugin shows status information about Open vSwitch.  The
version information was retrieved from XAPI, but this could cause
problems.  The most easily reproduced is to make a XenServer part of a
pool, then remove it.  The version string is no longer in the
XenServer's local XAPI view, so it reports "<unknown>".  A more direct
way to get the information is to directly query the binary, which is
what this commit does.

Bug #1626

xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py

index 4523139..dbd00a4 100644 (file)
@@ -32,6 +32,17 @@ class VSwitchService:
         if self.processname == None:
             self.processname = name
 
+    def version(self):
+        try:
+            output = ShellPipe(["service", self.name, "version"]).Stdout()
+        except StandardError, e:
+            log.error("version retrieval error: " + str(e))
+            return "<unknown>"
+        for line in output:
+            if self.processname in line:
+                return line.split()[-1]
+        return "<unknown>"
+
     def status(self):
         try:
             output = ShellPipe(["service", self.name, "status"]).Stdout()
@@ -40,12 +51,12 @@ class VSwitchService:
             return "<unknown>"
         if len(output) == 0:
             return "<unknown>"
-        for l in output:
-            if self.processname not in l:
+        for line in output:
+            if self.processname not in line:
                 continue
-            elif "running" in l:
+            elif "running" in line:
                 return "Running"
-            elif "stop" in l:
+            elif "stop" in line:
                 return "Stopped"
             else:
                 return "<unknown>"
@@ -262,8 +273,8 @@ class XSFeatureVSwitch:
 
         inPane.NewLine()
 
-        versionStr = data.host.other_config({}).get("vSwitchVersion", "<Unknown>")
-        inPane.AddStatusField(Lang("Version", 20), versionStr)
+        inPane.AddStatusField(Lang("Version", 20),
+                              VSwitchService.Inst("vswitch", "ovs-vswitchd").version())
 
         inPane.NewLine()