xenserver: Update xsconsole plugin to use first class datamodel field.
authorBen Pfaff <blp@nicira.com>
Wed, 30 Sep 2009 19:32:17 +0000 (12:32 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 30 Sep 2009 19:42:22 +0000 (12:42 -0700)
Part of a patch from Ian Campbell <ian.campbell@citrix.com>.

xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py

index 31a48c3..ed3e033 100644 (file)
@@ -102,7 +102,7 @@ class VSwitchControllerDialogue(Dialogue):
         self.hostsUpdated = 0
         pool = data.GetPoolForThisHost()
         if pool is not None:
-            self.controller = pool.get("other_config", {}).get("vSwitchController", "")
+            self.controller = pool.get("vswitch_controller", "")
         else:
             self.controller = ""
 
@@ -223,25 +223,21 @@ class VSwitchControllerDialogue(Dialogue):
     def SetController(self, ip):
         self.hostsInPool = 0
         self.hostsUpdated = 0
-        Task.Sync(lambda s: self._modifyPoolConfig(s, "vSwitchController", ip))
+        Task.Sync(lambda s: self._modifyPoolConfig(s, ip))
         # Should be done asynchronously, maybe with an external script?
         Task.Sync(lambda s: self._updateActiveServers(s))
 
-    def _modifyPoolConfig(self, session, key, value):
+    def _modifyPoolConfig(self, session, value):
         """Modify pool configuration.
 
-        If value == None then delete key, otherwise set key to value."""
+        If value == None then delete configuration, otherwise set to value."""
         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", [])
-        session.xenapi.pool.remove_from_other_config(pools[0], key)
-        if value != None:
-            session.xenapi.pool.add_to_other_config(pools[0], key, value)
+        session.xenapi.pool.set_vswitch_controller(value)
         Data.Inst().Update()
 
     def _updateActiveServers(self, session):
@@ -278,7 +274,7 @@ class XSFeatureVSwitch:
 
         pool = data.GetPoolForThisHost()
         if pool is not None:
-            dbController = pool.get("other_config", {}).get("vSwitchController", "")
+            dbController = pool.get("vswitch_controller", "")
         else:
             dbController = ""
 
@@ -320,5 +316,6 @@ class XSFeatureVSwitch:
             }
         )
 
-# Register this plugin when module is imported
-XSFeatureVSwitch().Register()
+# Register this plugin when module is imported, IFF vswitchd is running
+if os.path.exists('/var/run/ovs-vswitchd.pid'):
+    XSFeatureVSwitch().Register()