netdev-linux: Avoid potential issues with unset FD.
[sliver-openvswitch.git] / xenserver / usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py
index 4523139..99dd15d 100644 (file)
@@ -7,16 +7,13 @@
 
 # Copyright (c) 2009 Nicira Networks.
 
-import logging
-log = logging.getLogger("vswitch-cfg-update")
-logging.basicConfig(filename="/var/log/vswitch-xsplugin.log", level=logging.DEBUG)
+from XSConsoleLog import *
 
 import os
 import socket
 import subprocess
 
-cfg_mod="/root/vswitch/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")
@@ -32,20 +29,31 @@ class VSwitchService:
         if self.processname == None:
             self.processname = name
 
+    def version(self):
+        try:
+            output = ShellPipe(["service", self.name, "version"]).Stdout()
+        except StandardError, e:
+            XSLogError("vswitch 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()
         except StandardError, e:
-            log.error("status retrieval error: " + str(e))
+            XSLogError("vswitch status retrieval error: " + str(e))
             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>"
@@ -55,7 +63,7 @@ class VSwitchService:
         try:
             ShellPipe(["service", self.name, "restart"]).Call()
         except StandardError, e:
-            log.error("restart error: " + str(e))
+            XSLogError("vswitch restart error: " + str(e))
 
     @classmethod
     def Inst(cls, name, processname=None):
@@ -69,12 +77,11 @@ 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:
-            log.error("config retrieval error: " + str(e))
+            XSLogError("config retrieval error: " + str(e))
             return "<unknown>"
 
         if len(output) == 0:
@@ -262,8 +269,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()
 
@@ -276,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:":