Пример #1
0
def init(url=None, ip=None, port=None, https=None, insecure=False, username=None, password=None, cluster_name=None,
         proxy=None, start_h2o=True, nthreads=-1, ice_root=None, enable_assertions=True,
         max_mem_size=None, min_mem_size=None, strict_version_check=True, **kwargs):
    """
    Attempt to connect to a local server, or if not successful start a new server and connect to it.

    :param url:
    :param ip:
    :param port:
    :param https:
    :param insecure:
    :param username:
    :param password:
    :param cluster_name:
    :param proxy:
    :param start_h2o:
    :param nthreads:
    :param ice_root:
    :param enable_assertions:
    :param max_mem_size:
    :param min_mem_size:
    :param strict_version_check:
    :param kwargs: (all other deprecated attributes)
    :returns: nothing
    """
    global h2oconn
    scheme = "https" if https else "http"
    proxy = proxy[scheme] if proxy is not None and scheme in proxy else \
        kwargs["proxies"][scheme] if "proxies" in kwargs and scheme in kwargs["proxies"] else None
    mmax = int(max_mem_size) if max_mem_size is not None else \
        kwargs["max_mem_size_GB"] << 30 if "max_mem_size_GB" in kwargs else None
    mmin = int(min_mem_size) if min_mem_size is not None else \
        kwargs["min_mem_size_GB"] << 30 if "min_mem_size_GB" in kwargs else None
    auth = (username, password) if username and password else None
    if not start_h2o:
        print("Warning: if you don't want to start local H2O server, then use of `h2o.connect()` is preferred.")
    if ip and ip != "localhost" and ip != "127.0.0.1" and start_h2o:
        print("Warning: connecting to remote server but falling back to local... Did you mean to use `h2o.connect()`?")
    try:
        h2oconn = H2OConnection.open(url=url, ip=ip, port=port, https=https, verify_ssl_certificates=not insecure,
                                     auth=auth, proxy=proxy, cluster_name=cluster_name, verbose=True,
                                     _msgs=("Checking whether there is an H2O instance running at {url}",
                                            "connected.", "not found."))
    except H2OConnectionError:
        # Backward compatibility: in init() port parameter really meant "baseport" when starting a local server...
        if port and not str(port).endswith("+"):
            port = str(port) + "+"
        if not start_h2o: raise
        hs = H2OLocalServer.start(nthreads=nthreads, enable_assertions=enable_assertions, max_mem_size=mmax,
                                  min_mem_size=mmin, ice_root=ice_root, port=port)
        h2oconn = H2OConnection.open(server=hs, https=https, verify_ssl_certificates=not insecure,
                                     auth=auth, proxy=proxy, cluster_name=cluster_name, verbose=True)
    if strict_version_check:
        version_check()
Пример #2
0
def connect(server=None, url=None, ip=None, port=None, https=None, verify_ssl_certificates=None, auth=None,
            proxy=None, cluster_name=None, verbose=True):
    """
    Connect to an existing H2O server, remote or local.

    There are two ways to connect to a server: either pass a `server` parameter containing an instance of
    an H2OLocalServer, or specify `ip` and `port` of the server that you want to connect to.

    :param server: An H2OLocalServer instance to connect to (optional).
    :param url: Full URL of the server to connect to (can be used instead of `ip` + `port` + `https`).
    :param ip: The ip address (or host name) of the server where H2O is running.
    :param port: Port number that H2O service is listening to.
    :param https: Set to True to connect via https:// instead of http://.
    :param verify_ssl_certificates: When using https, setting this to False will disable SSL certificates verification.
    :param auth: Either a (username, password) pair for basic authentication, or one of the requests.auth
                 authenticator objects.
    :param proxy: Proxy server address.
    :param cluster_name: Name of the H2O cluster to connect to. This option is used from Steam only.
    :param verbose: Set to False to disable printing connection status messages.
    """
    global h2oconn
    h2oconn = H2OConnection.open(server=server, url=url, ip=ip, port=port, https=https, auth=auth,
                                 verify_ssl_certificates=verify_ssl_certificates, proxy=proxy,
                                 cluster_name=cluster_name, verbose=verbose)
    if verbose:
        h2oconn.cluster.show_status()
    return h2oconn
Пример #3
0
def connect(server=None,
            url=None,
            ip=None,
            port=None,
            https=None,
            verify_ssl_certificates=None,
            auth=None,
            proxy=None,
            cluster_name=None,
            verbose=True):
    """
    Connect to an existing H2O server, remote or local.

    There are two ways to connect to a server: either pass a `server` parameter containing an instance of
    an H2OLocalServer, or specify `ip` and `port` of the server that you want to connect to.

    :param server: An H2OLocalServer instance to connect to (optional).
    :param url: Full URL of the server to connect to (can be used instead of `ip` + `port` + `https`).
    :param ip: The ip address (or host name) of the server where H2O is running.
    :param port: Port number that H2O service is listening to.
    :param https: Set to True to connect via https:// instead of http://.
    :param verify_ssl_certificates: When using https, setting this to False will disable SSL certificates verification.
    :param auth: Either a (username, password) pair for basic authentication, or one of the requests.auth
                 authenticator objects.
    :param proxy: Proxy server address.
    :param cluster_name: Name of the H2O cluster to connect to. This option is used from Steam only.
    :param verbose: Set to False to disable printing connection status messages.
    """
    global h2oconn
    h2oconn = H2OConnection.open(**locals())
    if verbose:
        h2oconn.info().pprint()
    return h2oconn
Пример #4
0
def init(url=None,
         ip=None,
         port=None,
         https=None,
         insecure=False,
         username=None,
         password=None,
         cluster_name=None,
         proxy=None,
         start_h2o=True,
         nthreads=-1,
         ice_root=None,
         enable_assertions=True,
         max_mem_size=None,
         min_mem_size=None,
         strict_version_check=True,
         **kwargs):
    """
    Attempt to connect to a local server, or if not successful start a new server and connect to it.

    :param url:
    :param ip:
    :param port:
    :param https:
    :param insecure:
    :param username:
    :param password:
    :param cluster_name:
    :param proxy:
    :param start_h2o:
    :param nthreads:
    :param ice_root:
    :param enable_assertions:
    :param max_mem_size:
    :param min_mem_size:
    :param strict_version_check:
    :param kwargs: (all other deprecated attributes)
    :returns: nothing
    """
    global h2oconn
    scheme = "https" if https else "http"
    proxy = proxy[scheme] if proxy is not None and scheme in proxy else \
        kwargs["proxies"][scheme] if "proxies" in kwargs and scheme in kwargs["proxies"] else None
    mmax = int(max_mem_size) if max_mem_size is not None else \
        kwargs["max_mem_size_GB"] << 30 if "max_mem_size_GB" in kwargs else None
    mmin = int(min_mem_size) if min_mem_size is not None else \
        kwargs["min_mem_size_GB"] << 30 if "min_mem_size_GB" in kwargs else None
    auth = (username, password) if username and password else None
    if not start_h2o:
        print(
            "Warning: if you don't want to start local H2O server, then use of `h2o.connect()` is preferred."
        )
    if ip and ip != "localhost" and ip != "127.0.0.1" and start_h2o:
        print(
            "Warning: connecting to remote server but falling back to local... Did you mean to use `h2o.connect()`?"
        )
    try:
        h2oconn = H2OConnection.open(
            url=url,
            ip=ip,
            port=port,
            https=https,
            verify_ssl_certificates=not insecure,
            auth=auth,
            proxy=proxy,
            cluster_name=cluster_name,
            verbose=True,
            _msgs=(
                "Checking whether there is an H2O instance running at {url}",
                "connected.", "not found."))
    except H2OConnectionError:
        # Backward compatibility: in init() port parameter really meant "baseport" when starting a local server...
        if port and not str(port).endswith("+"):
            port = str(port) + "+"
        if not start_h2o: raise
        hs = H2OLocalServer.start(nthreads=nthreads,
                                  enable_assertions=enable_assertions,
                                  max_mem_size=mmax,
                                  min_mem_size=mmin,
                                  ice_root=ice_root,
                                  port=port)
        h2oconn = H2OConnection.open(server=hs,
                                     https=https,
                                     verify_ssl_certificates=not insecure,
                                     auth=auth,
                                     proxy=proxy,
                                     cluster_name=cluster_name,
                                     verbose=True)
    if strict_version_check:
        version_check()