Exemplo n.º 1
0
 def is_master(self, force=False):
     try:
         if force or not self._is_master:
             self._is_master = self.admin_command('isMaster', True)
     except OperationFailure, e:
         raise DBOperationError(
             "Unable to run isMaster command! Error: %s" % e)
Exemplo n.º 2
0
        else:
            pass

    def admin_command(self, admin_command, quiet=False):
        tries  = 0
        status = None
        while not status and tries < self.retries:
            try:
                status = self._conn['admin'].command(admin_command)
            except OperationFailure, e:
                if not quiet:
                    logging.error("Error running admin command '%s': %s" % (admin_command, e))
                tries += 1
                sleep(1)
        if not status:
            raise DBOperationError("Could not get output from command: '%s' after %i retries!" % (admin_command, self.retries))
        return status

    def server_version(self):
        status = self.admin_command('serverStatus')
        try:
            if 'version' in status:
                version = status['version'].split('-')[0]
                return tuple(version.split('.'))
        except Exception, e:
            raise Error("Unable to determine version from serverStatus! Error: %s" % e)

    def connection(self):
        return self._conn

    def is_mongos(self):