[ovs-dev] [PATCH 5 of 5] Update xsconsole plugin to use first class datamodel field
Ian Campbell
ian.campbell at citrix.com
Wed Sep 30 10:57:24 UTC 2009
Log via XSConsoleLog module instead of via own log file.
diff -r aa941ec68c03 -r b09bc55cdb35 xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py
--- a/xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py Wed Sep 30 11:38:22 2009 +0100
+++ b/xenserver/usr_lib_xsconsole_plugins-base_XSFeatureVSwitch.py Wed Sep 30 11:44:51 2009 +0100
@@ -7,9 +7,7 @@
# 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
@@ -36,7 +34,7 @@
try:
output = ShellPipe(["service", self.name, "version"]).Stdout()
except StandardError, e:
- log.error("version retrieval error: " + str(e))
+ XSLogError("vswitch version retrieval error: " + str(e))
return "<unknown>"
for line in output:
if self.processname in line:
@@ -47,7 +45,7 @@
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>"
@@ -66,7 +64,7 @@
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):
@@ -85,7 +83,7 @@
output = ShellPipe([cfg_mod, "-vANY:console:emer", "-F",
vswitchd_cfg_filename, "-q", key]).Stdout()
except StandardError, e:
- log.error("config retrieval error: " + str(e))
+ XSLogError("config retrieval error: " + str(e))
return "<unknown>"
if len(output) == 0:
@@ -104,7 +102,7 @@
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 = ""
@@ -225,25 +223,21 @@
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):
@@ -280,7 +274,7 @@
pool = data.GetPoolForThisHost()
if pool is not None:
- dbController = pool.get("other_config", {}).get("vSwitchController", "")
+ dbController = pool.get("vswitch_controller", "")
else:
dbController = ""
@@ -322,5 +316,6 @@
}
)
-# 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()
More information about the dev
mailing list