Beispiel #1
0
    def __init__(self,
                 hostname,
                 port,
                 color=False,
                 username=None,
                 password=None,
                 encoding=None,
                 stdin=None,
                 tty=True,
                 completekey=cqlsh.DEFAULT_COMPLETEKEY,
                 browser=None,
                 use_conn=None,
                 cqlver=None,
                 keyspace=None,
                 tracing_enabled=False,
                 expand_enabled=False,
                 no_compact=False,
                 display_nanotime_format=cqlsh.DEFAULT_NANOTIME_FORMAT,
                 display_timestamp_format=cqlsh.DEFAULT_TIMESTAMP_FORMAT,
                 display_date_format=cqlsh.DEFAULT_DATE_FORMAT,
                 display_float_precision=cqlsh.DEFAULT_FLOAT_PRECISION,
                 display_double_precision=cqlsh.DEFAULT_DOUBLE_PRECISION,
                 display_timezone=None,
                 max_trace_wait=cqlsh.DEFAULT_MAX_TRACE_WAIT,
                 ssl=False,
                 single_statement=None,
                 request_timeout=cqlsh.DEFAULT_REQUEST_TIMEOUT_SECONDS,
                 protocol_version=None,
                 connect_timeout=cqlsh.DEFAULT_CONNECT_TIMEOUT_SECONDS,
                 no_file_io=cqlsh.DEFAULT_NO_FILE_IO,
                 is_subshell=False):
        from dselib.authfactory import get_auth_provider
        if username:
            if not password:
                password = getpass.getpass()

        auth_provider = get_auth_provider(cqlsh.CONFIG_FILE, os.environ,
                                          username, password, cqlsh.options)

        self.execute_as = None
        self.consistency_level = dse.ConsistencyLevel.ONE
        self.serial_consistency_level = dse.ConsistencyLevel.SERIAL
        conn = None

        execution_profile = ExecutionProfile(
            load_balancing_policy=WhiteListRoundRobinPolicy([hostname]),
            row_factory=ordered_dict_factory,
            request_timeout=request_timeout,
            consistency_level=self.consistency_level,
            serial_consistency_level=self.serial_consistency_level)

        self.execution_profiles = {EXEC_PROFILE_DEFAULT: execution_profile}

        if use_conn:
            conn = use_conn
        else:
            kwargs = {}
            if protocol_version is not None:
                kwargs['protocol_version'] = protocol_version

            conn = cqlsh.Cluster(
                contact_points=(hostname, ),
                port=port,
                cql_version=cqlver,
                auth_provider=auth_provider,
                ssl_options=sslhandling.ssl_settings(
                    hostname, cqlsh.CONFIG_FILE) if ssl else None,
                control_connection_timeout=connect_timeout,
                connect_timeout=connect_timeout,
                execution_profiles=self.execution_profiles,
                **kwargs)

        OriginalShell.__init__(
            self,
            hostname,
            port,
            color=color,
            auth_provider=auth_provider,
            username=username,
            password=password,
            encoding=encoding,
            stdin=stdin,
            tty=tty,
            completekey=completekey,
            browser=browser,
            use_conn=conn,
            cqlver=cqlver,
            keyspace=keyspace,
            tracing_enabled=tracing_enabled,
            expand_enabled=expand_enabled,
            no_compact=no_compact,
            display_nanotime_format=display_nanotime_format,
            display_timestamp_format=display_timestamp_format,
            display_date_format=display_date_format,
            display_float_precision=display_float_precision,
            display_double_precision=display_double_precision,
            display_timezone=display_timezone,
            max_trace_wait=max_trace_wait,
            ssl=ssl,
            single_statement=single_statement,
            request_timeout=request_timeout,
            protocol_version=protocol_version,
            connect_timeout=connect_timeout,
            no_file_io=no_file_io,
            is_subshell=is_subshell)

        self.owns_connection = not use_conn
        self.execution_profile = self.session.get_execution_profile(
            EXEC_PROFILE_DEFAULT)
Beispiel #2
0
    def __init__(self,
                 hostname,
                 port,
                 color=False,
                 username=None,
                 password=None,
                 encoding=None,
                 stdin=None,
                 tty=True,
                 completekey=cqlsh.DEFAULT_COMPLETEKEY,
                 browser=None,
                 use_conn=None,
                 cqlver=None,
                 keyspace=None,
                 secure_connect_bundle=None,
                 consistency_level=None,
                 serial_consistency_level=None,
                 tracing_enabled=False,
                 timing_enabled=False,
                 expand_enabled=False,
                 display_nanotime_format=cqlsh.DEFAULT_NANOTIME_FORMAT,
                 display_timestamp_format=cqlsh.DEFAULT_TIMESTAMP_FORMAT,
                 display_date_format=cqlsh.DEFAULT_DATE_FORMAT,
                 display_float_precision=cqlsh.DEFAULT_FLOAT_PRECISION,
                 display_double_precision=cqlsh.DEFAULT_DOUBLE_PRECISION,
                 display_timezone=None,
                 max_trace_wait=cqlsh.DEFAULT_MAX_TRACE_WAIT,
                 ssl=False,
                 single_statement=None,
                 request_timeout=cqlsh.DEFAULT_REQUEST_TIMEOUT_SECONDS,
                 protocol_version=None,
                 connect_timeout=cqlsh.DEFAULT_CONNECT_TIMEOUT_SECONDS,
                 no_file_io=cqlsh.DEFAULT_NO_FILE_IO,
                 is_subshell=False):
        from dselib.authfactory import get_auth_provider
        if username:
            if not password:
                password = getpass.getpass()

        auth_provider = get_auth_provider(cqlsh.CONFIG_FILE, os.environ, username, password, cqlsh.options) \
            if not is_unix_socket(hostname) else None

        self.execute_as = None

        if not consistency_level:
            raise Exception('Argument consistency_level must not be None')
        if not serial_consistency_level:
            raise Exception(
                'Argument serial_consistency_level must not be None')
        self.consistency_level = consistency_level
        self.serial_consistency_level = serial_consistency_level

        execution_profile = ExecutionProfile(
            row_factory=ordered_dict_factory,
            request_timeout=request_timeout,
            consistency_level=self.consistency_level,
            serial_consistency_level=self.serial_consistency_level)

        self.execution_profiles = {EXEC_PROFILE_DEFAULT: execution_profile}

        if use_conn:
            conn = use_conn
        else:
            conn = cluster_factory(
                hostname,
                port=port,
                protocol_version=protocol_version
                if protocol_version is not None else _NOT_SET,
                cql_version=cqlver,
                auth_provider=auth_provider,
                ssl_options=sslhandling.ssl_settings(
                    hostname, cqlsh.CONFIG_FILE) if ssl else None,
                control_connection_timeout=connect_timeout,
                connect_timeout=connect_timeout,
                execution_profiles=self.execution_profiles,
                secure_connect_bundle=secure_connect_bundle)

        OriginalShell.__init__(
            self,
            hostname,
            port,
            color=color,
            auth_provider=auth_provider,
            username=username,
            password=password,
            encoding=encoding,
            stdin=stdin,
            tty=tty,
            completekey=completekey,
            browser=browser,
            use_conn=conn,
            cqlver=cqlver,
            keyspace=keyspace,
            secure_connect_bundle=secure_connect_bundle,
            consistency_level=consistency_level,
            serial_consistency_level=serial_consistency_level,
            tracing_enabled=tracing_enabled,
            timing_enabled=timing_enabled,
            expand_enabled=expand_enabled,
            display_nanotime_format=display_nanotime_format,
            display_timestamp_format=display_timestamp_format,
            display_date_format=display_date_format,
            display_float_precision=display_float_precision,
            display_double_precision=display_double_precision,
            display_timezone=display_timezone,
            max_trace_wait=max_trace_wait,
            ssl=ssl,
            single_statement=single_statement,
            request_timeout=request_timeout,
            protocol_version=protocol_version,
            connect_timeout=connect_timeout,
            no_file_io=no_file_io,
            is_subshell=is_subshell)

        self.owns_connection = not use_conn
        self.execution_profile = self.session.get_execution_profile(
            EXEC_PROFILE_DEFAULT)