Exemplo n.º 1
0
 def inject_ctx(*args, **kwargs):
     truncate = lambda i: i if len(i) <= 40 else "%s..." % i[:40]
     context = {
         "CTX-UUID": gen_context_uid(),
         "HTTP.ENV.SERVER_PROTOCOL": request.environ.get("SERVER_PROTOCOL"),
         "HTTP.ENV.REQUEST_METHOD": request.environ.get("REQUEST_METHOD"),
         "HTTP.ENV.REMOTE_ADDR": request.environ.get("REMOTE_ADDR"),
         "HTTP.ENV.PATH_INFO": request.environ.get("PATH_INFO"),
     }
     if request.headers.get("X-Real-IP"):
         context["HTTP.ENV.X-Real-IP"] = request.headers.get("X-Real-IP")
     if request.headers.get("X-Forwarded-For"):
         context["HTTP.ENV.X-Forwarded-For"] = request.headers.get("X-Forwarded-For")
     for arg, val in kwargs.iteritems():
         if arg not in ("cfg", "logger", "context"):
             context["kwargs.%s" % arg] = truncate(val)
     for arg, val in request.query.iteritems():
         context["HTTP.QUERYSTR.%s" % arg] = truncate(val)
     for arg, val in request.forms.iteritems():
         context["HTTP.FORMDATA.%s" % arg] = truncate(val)
     request["context"] = context
     return f(*args, **kwargs)
Exemplo n.º 2
0
def worker():
    logger.info("Waking up persistence-control worker...")
    devices = list_pending_persistence_jobs()
    if devices is None:
        logger.info("No pending persistence jobs found")
        return
    for device in devices:
        sw_cfg_persist_lock = acquire_persistence_lock(device)
        if sw_cfg_persist_lock is None:
            logger.warn("Could not acquire persistence lock for device '%s'. Probably because it's already acquired by another instance" % device)
            continue
        context = {"CTX-UUID": gen_context_uid()}
        try:
            logger.info("Starting persistence-job for device '%s' -- context: %s" % (device, context))
            swinst = get_switch_instance(device)
            swinst.save_config()
            finish_persistence_job(device)
        except NotImplementedError, e:
            logger.exception("Error on saving configuration on device '%s' -- context: %s" % (device, context))
            finish_persistence_job(device)
        except Exception, e:
            logger.exception("Error on saving configuration on device '%s' -- context: %s" % (device, context))