Exemple #1
0
 def get_rs_status(self):
     try:
         rs_status_cmd = SON([('replSetGetStatus', 1)])
         rs_status = self.db_command(rs_status_cmd, 'admin')
         return rs_status
     except (Exception, RuntimeError), e:
         log_debug("Cannot get rs status from server '%s'. cause: %s" %
                   (self.id, e))
         log_exception(e)
         return None
Exemple #2
0
 def is_online(self):
     log_debug("(BEGIN) is_online() for %s" % self.id)
     start_date = datetime.datetime.now()
     result = False
     try:
         self.new_default_mongo_client()
         result = True
     except (OperationFailure, AutoReconnect), ofe:
         log_exception(ofe)
         result = "refused" not in str(ofe)
Exemple #3
0
 def is_online(self):
     log_debug("(BEGIN) is_online() for %s" % self.id)
     start_date = datetime.datetime.now()
     result = False
     try:
         self.new_default_mongo_client()
         result = True
     except (OperationFailure, AutoReconnect), ofe:
         log_exception(ofe)
         result = "refused" not in str(ofe)
Exemple #4
0
 def get_rs_status(self):
     try:
         rs_status_cmd = SON([('replSetGetStatus', 1)])
         rs_status =  self.db_command(rs_status_cmd, 'admin')
         return rs_status
     except (Exception,RuntimeError), e:
         log_debug("Cannot get rs status from server '%s'. cause: %s" %
                     (self.id, e))
         log_exception(e)
         return None
Exemple #5
0
    def prefer_use_ssl(self):
        if self.get_client_ssl_mode() != ClientSslMode.PREFER:
            return False

        log_debug("prefer_use_ssl() Checking if we prefer ssl for '%s'" %
                  self.id)
        try:
            ping(self.new_mongo_client(ssl=True, **DEFAULT_CLIENT_OPTIONS))
            return True
        except (OperationFailure, AutoReconnect), ofe:
            log_exception(ofe)
            return True
Exemple #6
0
    def prefer_use_ssl(self):
        if self.get_client_ssl_mode() != ClientSslMode.PREFER:
            return False

        log_debug("prefer_use_ssl() Checking if we prefer ssl for '%s'" %
                  self.id)
        try:
            self.new_ssl_test_mongo_client()
            return True
        except (OperationFailure, AutoReconnect), ofe:
            log_exception(ofe)
            return True
Exemple #7
0
    def prefer_use_ssl(self):
        if self.get_client_ssl_mode() != ClientSslMode.PREFER:
            return False

        log_debug("prefer_use_ssl() Checking if we prefer ssl for '%s'" %
                  self.id)
        try:
            ping(self.new_mongo_client(ssl=True, **DEFAULT_CLIENT_OPTIONS))
            return True
        except (OperationFailure, AutoReconnect), ofe:
            log_exception(ofe)
            return True
Exemple #8
0
    def prefer_use_ssl(self):
        if self.get_client_ssl_mode() != ClientSslMode.PREFER:
            return False

        log_debug("prefer_use_ssl() Checking if we prefer ssl for '%s'" % self.id)
        try:
            self.make_ssl_db_connection(self.get_connection_address())
            return True
        except Exception, e:
            if not "SSL handshake failed" in str(e):
                log_exception(e)
            return None
Exemple #9
0
    def prefer_use_ssl(self):
        if self.get_client_ssl_mode() != ClientSslMode.PREFER:
            return False

        log_debug("prefer_use_ssl() Checking if we prefer ssl for '%s'" %
                  self.id)
        try:
            self.new_ssl_test_mongo_client()
            return True
        except (OperationFailure, AutoReconnect), ofe:
            log_exception(ofe)
            return True
Exemple #10
0
    def get_member_rs_status(self):
        rs_status = self.get_rs_status()
        if rs_status:
            try:
                for member in rs_status['members']:
                    if 'self' in member and member['self']:
                        return member
            except (Exception, RuntimeError), e:
                log_debug("Cannot get member rs status from server '%s'."
                          " cause: %s" % (self.id, e))
                log_exception(e)

                return None
Exemple #11
0
    def get_member_rs_status(self):
        rs_status =  self.get_rs_status()
        if rs_status:
            try:
                for member in rs_status['members']:
                    if 'self' in member and member['self']:
                        return member
            except (Exception,RuntimeError), e:
                log_debug("Cannot get member rs status from server '%s'."
                          " cause: %s" % (self.id, e))
                log_exception(e)

                return None
Exemple #12
0
 def get_rs_config(self):
     try:
         return self.get_db('local')['system.replset'].find_one()
     except (Exception,RuntimeError), e:
         log_debug("Error whille trying to read rs config from "
                   "server '%s': %s" % (self.id, e))
         log_exception(e)
         if type(e) == MongoctlException:
             raise e
         else:
             log_verbose("Cannot get rs config from server '%s'. "
                         "cause: %s" % (self.id, e))
             return None
Exemple #13
0
 def get_rs_config(self):
     try:
         return self.get_db('local')['system.replset'].find_one()
     except (Exception, RuntimeError), e:
         log_debug("Error whille trying to read rs config from "
                   "server '%s': %s" % (self.id, e))
         log_exception(e)
         if type(e) == MongoctlException:
             raise e
         else:
             log_verbose("Cannot get rs config from server '%s'. "
                         "cause: %s" % (self.id, e))
             return None
Exemple #14
0
 def needs_to_auth(self, dbname):
     """
     Determines if the server needs to authenticate to the database.
     NOTE: we stopped depending on is_auth() since its only a configuration
     and may not be accurate
     """
     log_debug("Checking if server '%s' needs to auth on  db '%s'...." % (self.id, dbname))
     try:
         conn = self.new_db_connection()
         db = conn[dbname]
         db.collection_names()
         result = False
     except (RuntimeError, Exception), e:
         log_exception(e)
         result = "authorized" in str(e)
Exemple #15
0
 def needs_to_auth(self, dbname):
     """
     Determines if the server needs to authenticate to the database.
     NOTE: we stopped depending on is_auth() since its only a configuration
     and may not be accurate
     """
     log_debug("Checking if server '%s' needs to auth on  db '%s'...." %
               (self.id, dbname))
     try:
         client = self.get_mongo_client()
         db = client.get_database(dbname)
         db.collection_names()
         result = False
     except (RuntimeError,Exception), e:
         log_exception(e)
         result = "authorized" in str(e)
Exemple #16
0
    def get_rs_config(self):
        rs_conf = None
        try:
            if self.version_greater_than_3_0():
                rs_conf = self.db_command(SON([('replSetGetConfig', 1)]), "admin")["config"]
            else:
                rs_conf = self.get_db('local')['system.replset'].find_one()

        except (Exception,RuntimeError), e:
            log_debug("Error whille trying to read rs config from "
                      "server '%s': %s" % (self.id, e))
            log_exception(e)
            if type(e) == MongoctlException:
                raise e
            else:
                log_verbose("Cannot get rs config from server '%s'. "
                            "cause: %s" % (self.id, e))
Exemple #17
0
 def needs_to_auth(self, dbname):
     """
     Determines if the server needs to authenticate to the database.
     NOTE: we stopped depending on is_auth() since its only a configuration
     and may not be accurate
     """
     log_debug("Checking if server '%s' needs to auth on  db '%s'...." %
               (self.id, dbname))
     try:
         client = self.get_mongo_client()
         db = client.get_database(dbname)
         db.collection_names()
         result = False
     except (RuntimeError,Exception), e:
         log_exception(e)
         # updated for to handle auth failures from mongodb 3.6
         result = "authorized" in str(e) or "there are no users authenticated" in str(e)
Exemple #18
0
    def get_rs_config(self):
        rs_conf = None
        try:
            if self.version_greater_than_3_0():
                rs_conf = self.db_command(SON([('replSetGetConfig', 1)]), "admin")["config"]
            else:
                rs_conf = self.get_db('local')['system.replset'].find_one()

        except (Exception,RuntimeError), e:
            log_debug("Error whille trying to read rs config from "
                      "server '%s': %s" % (self.id, e))
            log_exception(e)
            if type(e) == MongoctlException:
                raise e
            else:
                log_verbose("Cannot get rs config from server '%s'. "
                            "cause: %s" % (self.id, e))
Exemple #19
0
    def is_online(self):
        log_debug("(BEGIN) is_online() for %s" % self.id)
        start_date = datetime.datetime.now()
        result = False
        try:
            self.new_default_mongo_client()
            result = True
        except (OperationFailure, AutoReconnect), ofe:
            log_exception(ofe)
            result = "refused" not in str(ofe)
        except ConnectionFailure, cfe:
            log_exception(cfe)
            result = "connection closed" in str(cfe)

        duration = timedelta_total_seconds(datetime.datetime.now() - start_date)
        log_debug("(BEGIN) is_online() for %s finished in %s seconds" % (self.id, duration))
        return result

    ###########################################################################
    def can_function(self):
        status = self.get_status()
        if status['connection']:
            if 'error' not in status:
                return True
            else:
                log_verbose("Error while connecting to server '%s': %s " %
                            (self.id, status['error']))

    ###########################################################################
    def is_online_locally(self):
        return self.is_use_local() and self.is_online()
Exemple #20
0
    def is_online(self):
        log_debug("(BEGIN) is_online() for %s" % self.id)
        start_date = datetime.datetime.now()
        result = False
        try:
            self.new_default_mongo_client()
            result = True
        except (OperationFailure, AutoReconnect), ofe:
            log_exception(ofe)
            result = "refused" not in str(ofe)
        except ConnectionFailure, cfe:
            log_exception(cfe)
            result = "connection closed" in str(cfe)

        duration = timedelta_total_seconds(datetime.datetime.now() - start_date)
        log_debug("(BEGIN) is_online() for %s finished in %s seconds" % (self.id, duration))
        return result

    ###########################################################################
    def can_function(self):
        status = self.get_status()
        if status['connection']:
            if 'error' not in status:
                return True
            else:
                log_verbose("Error while connecting to server '%s': %s " %
                            (self.id, status['error']))

    ###########################################################################
    def is_online_locally(self):
        return self.is_use_local() and self.is_online()
Exemple #21
0
        Determines if the server needs to authenticate to the database.
        NOTE: we stopped depending on is_auth() since its only a configuration
        and may not be accurate
        """
        log_debug("Checking if server '%s' needs to auth on  db '%s'...." %
                  (self.id, dbname))
        try:
            conn = self.new_db_connection()
            db = conn[dbname]
            db.collection_names()
            result = False
        except (RuntimeError,Exception), e:
            log_exception(e)
            result = "authorized" in str(e)

        log_debug("needs_to_auth check for server '%s'  on db '%s' : %s" %
                  (self.id, dbname, result))
        return result

    ###########################################################################
    def get_status(self, admin=False):
        status = {}
        ## check if the server is online
        try:
            self.get_db_connection()
            status['connection'] = True

            # grab status summary if it was specified + if i am not an arbiter
            if admin:
                server_summary = self.get_server_status_summary()
                status["serverStatusSummary"] = server_summary
Exemple #22
0
        Determines if the server needs to authenticate to the database.
        NOTE: we stopped depending on is_auth() since its only a configuration
        and may not be accurate
        """
        log_debug("Checking if server '%s' needs to auth on  db '%s'...." %
                  (self.id, dbname))
        try:
            conn = self.new_db_connection()
            db = conn[dbname]
            db.collection_names()
            result = False
        except (RuntimeError, Exception), e:
            log_exception(e)
            result = "authorized" in str(e)

        log_debug("needs_to_auth check for server '%s'  on db '%s' : %s" %
                  (self.id, dbname, result))
        return result

    ###########################################################################
    def get_status(self, admin=False):
        status = {}
        ## check if the server is online
        try:
            self.get_db_connection()
            status['connection'] = True

            # grab status summary if it was specified + if i am not an arbiter
            if admin:
                server_summary = self.get_server_status_summary()
                status["serverStatusSummary"] = server_summary