# Bridge table and duplicates its value to the preferred "xs-network-uuids".
import getopt
+import logging, logging.handlers
import os
import signal
import subprocess
import sys
-import syslog
import time
import XenAPI
import ovs.daemon
import ovs.db.idl
+s_log = logging.getLogger("ovs-external-ids")
+l_handler = logging.handlers.SysLogHandler(
+ "/dev/log",
+ facility=logging.handlers.SysLogHandler.LOG_DAEMON)
+l_formatter = logging.Formatter('%(filename)s: %(levelname)s: %(message)s')
+l_handler.setFormatter(l_formatter)
+s_log.addHandler(l_handler)
+
vsctl="/usr/bin/ovs-vsctl"
session = None
force_run = False
session.xenapi.login_with_password("", "")
except:
session = None
- syslog.syslog(syslog.LOG_WARNING,
- "ovs-external-ids: Couldn't login to XAPI")
+ s_log.warning("Couldn't login to XAPI")
return False
return True
# record of XAPI.
def get_bridge_id(br_name, default=None):
if not init_session():
+ s_log.warning("Failed to get bridge id %s because"
+ " XAPI session could not be initialized" % br_name)
return default
for n in session.xenapi.network.get_all():
domain,device = if_name.strip("vif").split(".")
if not init_session():
+ s_log.warning("Failed to get interface id %s because"
+ " XAPI session could not be initialized" % if_name)
return default
for n in session.xenapi.VM.get_all():
cmd = [vsctl, "--timeout=30", "-vANY:console:emer", "set", table, record, col]
exitcode = subprocess.call(cmd)
if exitcode != 0:
- syslog.syslog(syslog.LOG_WARNING,
- "ovs-external-ids: Couldn't call ovs-vsctl")
+ s_log.warning("Couldn't call ovs-vsctl")
# XAPI on XenServer 5.6 uses the external-id "network-uuids" for internal
# networks, but we now prefer "xs-network-uuids". Look for its use and
continue
if force_run:
+ s_log.info("Forced to re-run as the result of a SIGHUP")
bridges = {}
interfaces = {}
force_run = False
if __name__ == '__main__':
try:
main(sys.argv)
- except error.Error, e:
- sys.stderr.write("%s\n" % e)
+ except SystemExit:
+ # Let system.exit() calls complete normally
+ raise
+ except:
+ s_log.exception("traceback")
sys.exit(1)