Пример #1
0
    def __init__(self, setup):
        read_pref = {'PRIMARY': ReadPreference.PRIMARY, 'PRIMARY_PREFERRED': ReadPreference.PRIMARY_PREFERRED,
                     'SECONDARY': ReadPreference.SECONDARY, 'SECONDARY_PREFERRED': ReadPreference.SECONDARY_PREFERRED,
                     'NEAREST': ReadPreference.NEAREST}
        db_setup = setup.get('DATABASE', {})
        self._connection = MongoClient(host=db_setup.get('HOSTS', ['localhost:27017']),
                                       replicaSet=db_setup.get('REPLSET', None),
                                       read_preference=read_pref[db_setup.get('READ_PREF', 'PRIMARY')])
        self._db = self._connection[db_setup.get('NAME', 'malcom')]
        if 'USERNAME' in db_setup:
            self._db.authenticate(db_setup['USERNAME'], password=db_setup.get('PASSWORD', None),
                                  source=db_setup.get('SOURCE', None))
        self._db.add_son_manipulator(Transform())

        # collections
        self.elements = self._db.elements
        self.graph = self._db.graph
        self.sniffer_sessions = self._db.sniffer_sessions
        self.feeds = self._db.feeds
        self.modules=self._db.modules
        self.history = self._db.history
        self.um = UserManager(setup)

        # create indexes
        self.rebuild_indexes()

        # locks
        self.db_lock = threading.Lock()
Пример #2
0
    def __init__(self):
        self._connection = MongoClient()
        self._db = self._connection.malcom
        self._db.add_son_manipulator(Transform())

        # collections
        self.elements = self._db.elements
        self.graph = self._db.graph
        self.sniffer_sessions = self._db.sniffer_sessions
        self.feeds = self._db.feeds
        self.history = self._db.history
        self.um = UserManager()

        # create indexes
        self.rebuild_indexes()

        # locks
        self.db_lock = threading.Lock()