# Path: mongoctl/users.py
# def parse_global_login_user_arg(username, password, server_id):
# def get_global_login_user(server, dbname):
# def setup_server_users(server):
# def setup_cluster_users(cluster, primary_server):
# def should_seed_db_users(server, dbname):
# def setup_db_users(server, db, db_users):
# def _mongo_add_user(server, db, username, password, read_only=False,
#                     num_tries=1):
# def list_database_users(server, db):
# def setup_server_db_users(server, dbname, db_users):
# def prepend_global_admin_user(other_users, server):
# def setup_server_admin_users(server):
# def setup_root_admin_user(server, admin_users):
# def setup_server_local_users(server):
# def read_seed_password(dbname, username):
# def set_server_login_user(server, dbname, username, password):
# def get_server_login_user(server, dbname):
# def _get_server_login_record(server, create_new=True):
# def is_system_user(username):
# LOGIN_USERS = {}
# 
# Path: mongoctl/config.py
# def get_cluster_member_alt_address_mapping():
#     return get_mongoctl_config_val('clusterMemberAltAddressesMapping', {})
# 
# Path: mongoctl/mongoctl_logging.py
# def log_verbose(msg):
#     get_logger().log(VERBOSE, msg)
# 
# def log_error(msg):
#     get_logger().error(msg)
# 
# def log_db_command(cmd):
#     log_info( "Executing db command %s" % utils.document_pretty_string(cmd))


import mongoctl.repository as repository
from cluster import Cluster
from mongoctl import users
from base import DocumentWrapper
from mongoctl.utils import *
from bson import DBRef
from mongoctl.config import get_cluster_member_alt_address_mapping
from mongoctl.mongoctl_logging import log_verbose, log_error, log_db_command
from mongoctl.prompt import prompt_confirm
            wait_for(is_init,timeout=60 * 10, sleep_duration=1)

            if self.is_replicaset_initialized():
                log_info("Successfully initiated replica set cluster '%s'!" %
                         self.id)
            else:
                msg = ("Timeout error: Initializing replicaset '%s' took "
                       "longer than expected. This does not necessarily"
                       " mean that it failed but it could have failed. " %
                       self.id)
                raise MongoctlException(msg)
                ## add the admin user after the set has been initiated
            ## Wait for the server to become primary though (at MongoDB's end)

            def is_primary_for_real():
                return primary_server.is_primary()

            log_info("Will now wait for the intended primary server to "
                     "become primary.")
            wait_for(is_primary_for_real,timeout=60, sleep_duration=1)

            if not is_primary_for_real():
                msg = ("Timeout error: Waiting for server '%s' to become "
                       "primary took longer than expected. "
                       "Please try again later." % primary_server.id)
                raise MongoctlException(msg)

            log_info("Server '%s' is primary now!" % primary_server.id)

            # setup cluster users

# Path: mongoctl/users.py
# def parse_global_login_user_arg(username, password, server_id):
# def get_global_login_user(server, dbname):
# def setup_server_users(server):
# def setup_cluster_users(cluster, primary_server):
# def should_seed_db_users(server, dbname):
# def setup_db_users(server, db, db_users):
# def _mongo_add_user(server, db, username, password, read_only=False,
#                     num_tries=1):
# def list_database_users(server, db):
# def setup_server_db_users(server, dbname, db_users):
# def prepend_global_admin_user(other_users, server):
# def setup_server_admin_users(server):
# def setup_root_admin_user(server, admin_users):
# def setup_server_local_users(server):
# def read_seed_password(dbname, username):
# def set_server_login_user(server, dbname, username, password):
# def get_server_login_user(server, dbname):
# def _get_server_login_record(server, create_new=True):
# def is_system_user(username):
# LOGIN_USERS = {}
# 
# Path: mongoctl/config.py
# def get_cluster_member_alt_address_mapping():
#     return get_mongoctl_config_val('clusterMemberAltAddressesMapping', {})
# 
# Path: mongoctl/mongoctl_logging.py
# def log_verbose(msg):
#     get_logger().log(VERBOSE, msg)
# 
# def log_error(msg):
#     get_logger().error(msg)
# 
# def log_db_command(cmd):
#     log_info( "Executing db command %s" % utils.document_pretty_string(cmd))


# Path: mongoctl/objects/replicaset_cluster.py
import mongoctl.repository as repository
from cluster import Cluster
from mongoctl import users
from base import DocumentWrapper
from mongoctl.utils import *
from bson import DBRef
from mongoctl.config import get_cluster_member_alt_address_mapping
from mongoctl.mongoctl_logging import log_verbose, log_error, log_db_command
from mongoctl.prompt import prompt_confirm

            wait_for(is_init,timeout=60 * 10, sleep_duration=1)

            if self.is_replicaset_initialized():
                log_info("Successfully initiated replica set cluster '%s'!" %
                         self.id)
            else:
                msg = ("Timeout error: Initializing replicaset '%s' took "
                       "longer than expected. This does not necessarily"
                       " mean that it failed but it could have failed. " %
                       self.id)
                raise MongoctlException(msg)
                ## add the admin user after the set has been initiated
            ## Wait for the server to become primary though (at MongoDB's end)

            def is_primary_for_real():
                return primary_server.is_primary()

            log_info("Will now wait for the intended primary server to "
                     "become primary.")
            wait_for(is_primary_for_real,timeout=60, sleep_duration=1)

            if not is_primary_for_real():
                msg = ("Timeout error: Waiting for server '%s' to become "
                       "primary took longer than expected. "
                       "Please try again later." % primary_server.id)
                raise MongoctlException(msg)

            log_info("Server '%s' is primary now!" % primary_server.id)

            # setup cluster users

            users.setup_cluster_users(self, primary_server)