コード例 #1
0
def initRamCortex(link, conf=None, storconf=None):
    '''
    Initialize a RAM based Cortex from a link tufo.

    The path element of the link tufo, if present, is used to cache the Cortex
    instance.  Subsequent calls with the same path will return the existing
    Cortex instance.

    Args:
        link ((str, dict)): Link tufo.
        conf (dict): Configable opts for the Cortex object.
        storconf (dict): Configable opts for the storage object.

    Returns:
        s_cores_common.Cortex: Cortex created from the link tufo.
    '''
    if not conf:
        conf = {}
    if not storconf:
        storconf = {}

    path = link[1].get('path').strip('/')
    if not path:
        store = RamStorage(link, **storconf)
        return s_cores_common.Cortex(link, store, **conf)

    core = ramcores.get(path)
    if core is None:
        store = RamStorage(link, **storconf)
        core = s_cores_common.Cortex(link, store, **conf)

        ramcores[path] = core

        def onfini():
            ramcores.pop(path, None)

        core.onfini(onfini)

    return core
コード例 #2
0
def initLmdbCortex(link, conf=None, storconf=None):
    '''
    Initialize a LMDB based Cortex from a link tufo.

    Args:
        link ((str, dict)): Link tufo.
        conf (dict): Configable opts for the Cortex object.
        storconf (dict): Configable opts for the storage object.

    Returns:
        s_cores_common.Cortex: Cortex created from the link tufo.
    '''
    if not conf:
        conf = {}
    if not storconf:
        storconf = {}

    store = LmdbStorage(link, **storconf)
    return s_cores_common.Cortex(link, store, **conf)