Ejemplo n.º 1
0
def cache_result(data, **kwargs):
    record = dict(kwargs.items())
    record['__ts'] = datetime.utcnow()
    if not data:
        data = EMPTY
    record['__data'] = data
    record['section'] = config.section()
    get_db().loadcache.update(kwargs, record, upsert=True)
Ejemplo n.º 2
0
def list_switches():
    switches = {}
    for k in cfg.sections():
        if k.startswith("device.") and not "default" in k:
            switches[k[7:]] = dict([
                (x, y) for x, y in config.section(cfg, k).items()
            ])
    return switches
Ejemplo n.º 3
0
def cache_result(data, **kwargs):
    record = dict(kwargs.items())
    record["__ts"] = datetime.utcnow()
    if not data:
        data = EMPTY
    record["__data"] = data
    record["section"] = config.section()
    get_db().loadcache.update(kwargs, record, upsert=True)
Ejemplo n.º 4
0
def load_cached(**kwargs):
    if config.bool('cache'):
        kwargs['section'] = config.section()
        data = get_db().loadcache.find_one(kwargs)
        if data:
            return data.get('__data', {})
Ejemplo n.º 5
0
def list_switches():
    switches = {}
    for k in cfg.sections():
        if k.startswith("device.") and not "default" in k:
            switches[k[7:]] = dict([(x,y) for x,y in config.section(cfg, k).items()])
    return switches
Ejemplo n.º 6
0
def load_cached(**kwargs):
    if config.bool("cache"):
        kwargs["section"] = config.section()
        data = get_db().loadcache.find_one(kwargs)
        if data:
            return data.get("__data", {})