# 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

            cmd_server.disconnecting_db_command(rs_reconfig_cmd, "admin")

            log_info("Re-configuration command for replica set cluster '%s'"
                     " issued successfully." % self.id)

            # wait until there is a primary

            log_info("Wait for the new primary to be elected...")
            def has_primary():
                return self.get_primary_member() is not None

            if not wait_for(has_primary, timeout=60, sleep_duration=1):
                raise Exception("No primary elected 60 seconds after reconfiguration!")

            # Probably need to reconnect.  May not be primary any more.
            desired_cfg_version = desired_config['version']

            def got_the_memo(cur_cfg=None):
                current_config = cur_cfg or self.read_rs_config()
                # might've gotten None if nobody answers & tells us, so:
                current_cfg_version = (current_config['version']
                                       if current_config else 0)
                version_diff = (current_cfg_version - desired_cfg_version)
                return ((version_diff == 0) or
                        # force => mongo adds large random # to 'version'.
                        (force and version_diff >= 0))

            realized_config = self.read_rs_config()
            if not got_the_memo(realized_config):

# 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


            cmd_server.disconnecting_db_command(rs_reconfig_cmd, "admin")

            log_info("Re-configuration command for replica set cluster '%s'"
                     " issued successfully." % self.id)

            # wait until there is a primary

            log_info("Wait for the new primary to be elected...")
            def has_primary():
                return self.get_primary_member() is not None

            if not wait_for(has_primary, timeout=60, sleep_duration=1):
                raise Exception("No primary elected 60 seconds after reconfiguration!")

            # Probably need to reconnect.  May not be primary any more.
            desired_cfg_version = desired_config['version']

            def got_the_memo(cur_cfg=None):
                current_config = cur_cfg or self.read_rs_config()
                # might've gotten None if nobody answers & tells us, so:
                current_cfg_version = (current_config['version']
                                       if current_config else 0)
                version_diff = (current_cfg_version - desired_cfg_version)
                return ((version_diff == 0) or
                        # force => mongo adds large random # to 'version'.
                        (force and version_diff >= 0))

            realized_config = self.read_rs_config()
            if not got_the_memo(realized_config):

                log_verbose("Really? Config version %s? "