[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-API] [PATCH 12 of 12] [PATCH] xenserver: Add --no-syslog feature to interface-reconfigure



# HG changeset patch
# User Ben Pfaff <blp@xxxxxxxxxx>
# Date 1278595551 -3600
# Node ID b4aadd0428adf9c2fb17156ff211d7761cf58895
# Parent  78a1d9979fbf6c9e19d78dad452c3d28abaf0a6d
[PATCH] xenserver: Add --no-syslog feature to interface-reconfigure.

>From b63fadcfdc8a96ddb5e944b60733edf21999a1ad Mon Sep 17 00:00:00 2001
Date: Mon, 22 Feb 2010 16:26:50 -0800
This makes it easier to do unit tests (some of which will be added in an
upcoming commit) by allowing messages to be read from stderr instead of
having to somehow intercept syslog calls.

Signed-off-by: Ben Pfaff <blp@xxxxxxxxxx>
Signed-off-by: Ian Campbell <ian.campbell@xxxxxxxxxx>
---
 .../opt_xensource_libexec_InterfaceReconfigure.py  |   16 +++++++++++++++-
 .../opt_xensource_libexec_interface-reconfigure    |    9 +++++++--
 2 files changed, 22 insertions(+), 3 deletions(-)

diff -r 78a1d9979fbf -r b4aadd0428ad scripts/InterfaceReconfigure.py
--- a/scripts/InterfaceReconfigure.py   Thu Jul 08 14:25:51 2010 +0100
+++ b/scripts/InterfaceReconfigure.py   Thu Jul 08 14:25:51 2010 +0100
@@ -10,6 +10,7 @@
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU Lesser General Public License for more details.
 #
+import sys
 import syslog
 import os
 
@@ -25,12 +26,25 @@
     global the_root_prefix
     the_root_prefix = prefix
 
+log_destination = "syslog"
+def get_log_destination():
+    """Returns the current log destination.
+    'syslog' means "log to syslog".
+    'stderr' means "log to stderr"."""
+    return log_destination
+def set_log_destination(dest):
+    global log_destination
+    log_destination = dest
+
 #
 # Logging.
 #
 
 def log(s):
-    syslog.syslog(s)
+    if get_log_destination() == 'syslog':
+        syslog.syslog(s)
+    else:
+        print >>sys.stderr, s
 
 #
 # Exceptions.
diff -r 78a1d9979fbf -r b4aadd0428ad scripts/interface-reconfigure
--- a/scripts/interface-reconfigure     Thu Jul 08 14:25:51 2010 +0100
+++ b/scripts/interface-reconfigure     Thu Jul 08 14:25:51 2010 +0100
@@ -34,6 +34,7 @@
     --pif-uuid          The UUID of a PIF.
     --force             An interface name.
     --root-prefix=DIR   Use DIR as alternate root directory (for testing).
+    --no-syslog         Write log messages to stderr instead of system log.
 """
 
 # Notes:
@@ -584,6 +585,7 @@
                         "management",
                         "mac=", "device=", "mode=", "ip=", "netmask=", 
"gateway=",
                         "root-prefix=",
+                        "no-syslog",
                         "help" ]
             arglist, args = getopt.gnu_getopt(argv[1:], shortops, longops)
         except getopt.GetoptError, msg:
@@ -606,12 +608,15 @@
                 force_rewrite_config[o[2:]] = a
             elif o == "--root-prefix":
                 set_root_prefix(a)
+            elif o == "--no-syslog":
+                set_log_destination("stderr")
             elif o == "-h" or o == "--help":
                 print __doc__ % {'command-name': os.path.basename(argv[0])}
                 return 0
 
-        syslog.openlog(os.path.basename(argv[0]))
-        log("Called as " + str.join(" ", argv))
+        if get_log_destination() == "syslog":
+            syslog.openlog(os.path.basename(argv[0]))
+            log("Called as " + str.join(" ", argv))
 
         if len(args) < 1:
             raise Usage("Required option <action> not present")
 scripts/InterfaceReconfigure.py |  16 +++++++++++++++-
 scripts/interface-reconfigure   |   9 +++++++--
 2 files changed, 22 insertions(+), 3 deletions(-)


Attachment: xenserver_Add_--no-syslog_feature_to_interface-reconfigure.patch
Description: Text Data

_______________________________________________
xen-api mailing list
xen-api@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/mailman/listinfo/xen-api

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.