예제 #1
0
def get_mongoctl_database():

    # if not using db then return
    if not has_db_repository():
        return

    global __mongoctl_db__

    if __mongoctl_db__ is not None:
        return __mongoctl_db__

    log_verbose("Connecting to mongoctl db...")
    try:

        (conn, dbname) = _db_repo_connect()

        __mongoctl_db__ = conn[dbname]
        return __mongoctl_db__
    except Exception, e:
        log_exception(e)
        __mongoctl_db__ = "OFFLINE"
        log_warning("\n*************\n"
                    "Will not be using database repository for configurations"
                    " at this time!"
                    "\nREASON: Could not establish a database"
                    " connection to mongoctl's database repository."
                    "\nCAUSE: %s."
                    "\n*************" % e)
예제 #2
0
def get_mongoctl_database():

    # if not using db then return
    if not has_db_repository():
        return

    global __mongoctl_db__

    if __mongoctl_db__ is not None:
        return __mongoctl_db__

    log_verbose("Connecting to mongoctl db...")
    try:

        (conn, dbname) = _db_repo_connect()

        __mongoctl_db__ = conn[dbname]
        return __mongoctl_db__
    except Exception, e:
        log_exception(e)
        __mongoctl_db__ = "OFFLINE"
        log_warning("\n*************\n"
                    "Will not be using database repository for configurations"
                    " at this time!"
                    "\nREASON: Could not establish a database"
                    " connection to mongoctl's database repository."
                    "\nCAUSE: %s."
                    "\n*************" % e)
예제 #3
0
def get_mongoctl_database():

    # if not using db then return
    if not has_db_repository():
        return

    global __mongoctl_db__

    if __mongoctl_db__ is not None:
        return __mongoctl_db__

    log_verbose("Connecting to mongoctl db...")
    try:
        client = _db_repo_connect()
        # issue a call to server to ensure it connects
        client.get_database("admin").command({"ping": 1})
        __mongoctl_db__ = client.get_default_database()
        return __mongoctl_db__
    except Exception, e:
        log_exception(e)
        __mongoctl_db__ = "OFFLINE"
        log_warning("\n*************\n"
                    "Will not be using database repository for configurations"
                    " at this time!"
                    "\nREASON: Could not establish a database"
                    " connection to mongoctl's database repository."
                    "\nCAUSE: %s."
                    "\n*************" % e)
예제 #4
0
def get_mongoctl_database():

    # if not using db then return
    if not has_db_repository():
        return

    global __mongoctl_db__

    if __mongoctl_db__ is not None:
        return __mongoctl_db__

    log_verbose("Connecting to mongoctl db...")
    try:
        client = _db_repo_connect()
        # issue a call to server to ensure it connects
        client.get_database("admin").command({"ping": 1})
        __mongoctl_db__ = client.get_default_database()
        return __mongoctl_db__
    except Exception, e:
        log_exception(e)
        __mongoctl_db__ = "OFFLINE"
        log_warning("\n*************\n"
                    "Will not be using database repository for configurations"
                    " at this time!"
                    "\nREASON: Could not establish a database"
                    " connection to mongoctl's database repository."
                    "\nCAUSE: %s."
                    "\n*************" % e)
예제 #5
0
파일: users.py 프로젝트: zenglzh/mongoctl
###############################################################################
def _mongo_add_user(server, db, username, password, read_only=False,
                    num_tries=1):
    try:
        db.add_user(username, password, read_only)
    except OperationFailure, ofe:
        # This is a workaround for PYTHON-407. i.e. catching a harmless
        # error that is raised after adding the first
        if "login" in str(ofe):
            pass
        else:
            raise
    except AutoReconnect, ar:
        log_exception(ar)
        if num_tries < 3:
            log_warning("_mongo_add_user: Caught a AutoReconnect error. %s " %
                        ar)
            # check if the user/pass was saved successfully
            if db.authenticate(username, password):
                log_info("_mongo_add_user: user was added successfully. "
                         "no need to retry")
            else:
                log_warning("_mongo_add_user: re-trying ...")
                _mongo_add_user(server, db, username, password,
                                read_only=read_only, num_tries=num_tries+1)
        else:
            raise


###############################################################################
def setup_server_db_users(server, dbname, db_users):
    log_verbose("Checking if there are any users that needs to be added for "
예제 #6
0
파일: users.py 프로젝트: zenglzh/mongoctl
                    password,
                    read_only=False,
                    num_tries=1):
    try:
        db.add_user(username, password, read_only)
    except OperationFailure, ofe:
        # This is a workaround for PYTHON-407. i.e. catching a harmless
        # error that is raised after adding the first
        if "login" in str(ofe):
            pass
        else:
            raise
    except AutoReconnect, ar:
        log_exception(ar)
        if num_tries < 3:
            log_warning("_mongo_add_user: Caught a AutoReconnect error. %s " %
                        ar)
            # check if the user/pass was saved successfully
            if db.authenticate(username, password):
                log_info("_mongo_add_user: user was added successfully. "
                         "no need to retry")
            else:
                log_warning("_mongo_add_user: re-trying ...")
                _mongo_add_user(server,
                                db,
                                username,
                                password,
                                read_only=read_only,
                                num_tries=num_tries + 1)
        else:
            raise