'Create a client and grab essential information from the server.'

def __init__(self):

    self.connected = False
    self.ismaster = {}
    self.w = None
    self.nodes = set()
    self.replica_set_name = None
    self.cmd_line = None
    self.version = Version((-1))
    self.auth_enabled = False
    self.test_commands_enabled = False
    self.is_mongos = False
    self.is_rs = False
    self.has_ipv6 = False
    self.ssl = False
    self.ssl_cert_none = False
    self.ssl_certfile = False
    self.server_is_resolvable = is_server_resolvable()
    self.ssl_client_options = {}
    self.client = _connect(host, port)
    if (HAVE_SSL and (not self.client)):
        self.client = _connect(host, port, **_SSL_OPTIONS)
        if self.client:
            self.ssl = True
            self.ssl_client_options = _SSL_OPTIONS
            self.ssl_certfile = True
            if (_SSL_OPTIONS.get('ssl_cert_reqs') == ssl.CERT_NONE):
                self.ssl_cert_none = True
    if self.client:
        self.connected = True
        ismaster = self.client.admin.command('ismaster')
        if ('setName' in ismaster):
            self.replica_set_name = ismaster['setName']
            self.is_rs = True
            self.client = pymongo.MongoClient(host, port, replicaSet=self.replica_set_name, **self.ssl_client_options)
            self.ismaster = self.client.admin.command('ismaster')
            nodes = [partition_node(node.lower()) for node in self.ismaster.get('hosts', [])]
            nodes.extend([partition_node(node.lower()) for node in self.ismaster.get('passives', [])])
            nodes.extend([partition_node(node.lower()) for node in self.ismaster.get('arbiters', [])])
            self.nodes = set(nodes)
        else:
            self.ismaster = ismaster
            self.nodes = set([(host, port)])
        self.w = (len(self.ismaster.get('hosts', [])) or 1)
        self.version = Version.from_client(self.client)
        try:
            self.cmd_line = self.client.admin.command('getCmdLineOpts')
        except pymongo.errors.OperationFailure as e:
            msg = e.details.get('errmsg', '')
            if ((e.code == 13) or ('unauthorized' in msg) or ('login' in msg)):
                self.auth_enabled = True
            else:
                raise
        else:
            self.auth_enabled = self._server_started_with_auth()
        if self.auth_enabled:
            self.user_provided = self._check_user_provided()
            if (not self.user_provided):
                roles = {}
                if self.version.at_least(2, 5, 3, (-1)):
                    roles = {'roles': ['root']}
                self.client.admin.add_user(db_user, db_pwd, **roles)
            self.client = _connect(host, port, username=db_user, password=db_pwd, replicaSet=self.replica_set_name, **self.ssl_client_options)
            self.cmd_line = self.client.admin.command('getCmdLineOpts')
        if ('enableTestCommands=1' in self.cmd_line['argv']):
            self.test_commands_enabled = True
        elif ('parsed' in self.cmd_line):
            params = self.cmd_line['parsed'].get('setParameter', [])
            if ('enableTestCommands=1' in params):
                self.test_commands_enabled = True
            else:
                params = self.cmd_line['parsed'].get('setParameter', {})
                if (params.get('enableTestCommands') == '1'):
                    self.test_commands_enabled = True
        self.is_mongos = (self.ismaster.get('msg') == 'isdbgrid')
        self.has_ipv6 = self._server_started_with_ipv6()
