-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new Drive notebook tutorial detailing connecting from different e…
…nvironments.
- Loading branch information
Showing
1 changed file
with
304 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,304 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"id": "de59e2e2", | ||
"metadata": {}, | ||
"source": [ | ||
"# Drive - Connecting from different environments\n", | ||
"\n", | ||
"This notebook tutorial walks through how to connect to H2O Drive from different environments, including:\n", | ||
"- From within the H2O AI Cloud\n", | ||
"- From outside the H2O AI Cloud network (with the H2O CLI set up)\n", | ||
"- From outside the H2O AI Cloud network (without the H2O CLI set up)\n", | ||
"\n", | ||
"> ℹ️ Note\n", | ||
">\n", | ||
"> When on H2O Managed Cloud, external H2O Drive access is disabled by default. If not already enabled, contact your H2O Managed Cloud representative to have external H2O Drive access enabled for your environment." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "990fcb80-c50d-4f85-a1bb-56d0053a309b", | ||
"metadata": {}, | ||
"source": [ | ||
"## Required packages" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "6f9a20f7-5ff9-43af-a16c-a0778a31c3b2", | ||
"metadata": {}, | ||
"source": [ | ||
"First, let's explicitly install the packages for the tools used in this notebook. The `-q` flag quiets the otherwise verbose output." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f20cadb0-21ae-44be-a625-543d87983c27", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import sys\n", | ||
"!{sys.executable} -m pip install -q h2o-cloud-discovery\n", | ||
"!{sys.executable} -m pip install -q \"h2o-drive>=4\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "0b513eb7-a1f0-4aa4-b942-f442fcba2b95", | ||
"metadata": {}, | ||
"source": [ | ||
"## From within the H2O AI Cloud" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "923124f9-d709-4012-bce7-c3998d2146d3", | ||
"metadata": {}, | ||
"source": [ | ||
"Environments within the H2O AI Cloud, such as H2O notebook environments, support seamless connection to H2O services.\n", | ||
"\n", | ||
"From within an H2O notebook, we can `connect()` to H2O Drive without required arguments and rely on the client's ability to automatically determine connection details from the environment." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "31d2f400-383f-412a-b363-071d6bb954dd", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import h2o_drive\n", | ||
"\n", | ||
"drive = h2o_drive.connect()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "1ede252b-29db-4aef-808a-5a8c05568954", | ||
"metadata": {}, | ||
"source": [ | ||
"## From outside the H2O AI Cloud network (with the H2O CLI set up)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "c4cf3162-9f04-4aed-bbe9-3f682f2ccced", | ||
"metadata": {}, | ||
"source": [ | ||
"When the H2O CLI (see [the References section](#References) for links to docs) is installed and configured in a local environment, it serves as a source for performing H2O service discovery.\n", | ||
"\n", | ||
"As with connecting from within the H2O AI Cloud, we can `connect()` to H2O Drive without any required arugments." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "d742ca4d-4e41-4b28-8a60-c089bc29458a", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import h2o_drive\n", | ||
"\n", | ||
"drive = h2o_drive.connect()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "5acae2b4-6a0f-4d9c-9ac9-e12e7fe5a0d5", | ||
"metadata": {}, | ||
"source": [ | ||
"## From outside the H2O AI Cloud network (without the H2O CLI set up)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "b070c5a5-e40d-45ba-8aa6-6d02101a87fb", | ||
"metadata": {}, | ||
"source": [ | ||
"### Informative: Service discovery under the hood" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "db40711f-3ff4-4d2b-8a0c-9b38eaabb62d", | ||
"metadata": {}, | ||
"source": [ | ||
"Under the hood, H2O clients automatically determine connection details by way of H2O's service discovery. Internally, H2O Python clients may perform service discovery by way of an H2O Cloud Discovery object, which is created with the `h2o_discovery` package.\n", | ||
"\n", | ||
"An externally-initialized discovery object can be passed in to override the one initialized internally.\n", | ||
"\n", | ||
"```python\n", | ||
"import h2o_drive\n", | ||
"\n", | ||
"drive = h2o_drive.connect()\n", | ||
"\n", | ||
"#\n", | ||
"# is equivalent to \n", | ||
"#\n", | ||
"\n", | ||
"import h2o_discovery\n", | ||
"import h2o_drive\n", | ||
"\n", | ||
"discovery = h2o_discovery.discover()\n", | ||
"drive = h2o_drive.connect(discovery=discovery)\n", | ||
"```\n", | ||
"\n", | ||
"When not running within the H2O AI Cloud or with the H2O CLI configured locally, an H2O Cloud Discovery object requires certain information to fully facilitate service discovery." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "b792f6f8-7f85-4218-a398-c38f9c7d97d8", | ||
"metadata": {}, | ||
"source": [ | ||
"### Configuring a discovery object" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "88fc7e7a-d18e-490b-95c2-a738a0cae015", | ||
"metadata": {}, | ||
"source": [ | ||
"For a manually-created discovery object to serve our purposes, let's provide it two things:\n", | ||
"1. The URL to the H2O AI Cloud.\n", | ||
"2. An H2O AI Cloud platform token.\n", | ||
"\n", | ||
"The H2O Cloud Discovery library can recognize both values above as environment variables.\n", | ||
"\n", | ||
"> ℹ️ Note\n", | ||
">\n", | ||
"> Replace the values below with the URL to your H2O AI Cloud, and a platform token which can be retrieved by visiting `https://<h2o-ai-cloud-url>/auth/get-platform-token`." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "85af4544-b7e2-4550-9aaa-dfda81dfa4fa", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import os\n", | ||
"import h2o_discovery\n", | ||
"\n", | ||
"os.environ[\"H2O_CLOUD_ENVIRONMENT\"] = \"https://h2o-ai-cloud.example.com\"\n", | ||
"os.environ[\"H2O_CLOUD_CLIENT_PLATFORM_TOKEN\"] = \"... the contents of <h2o-ai-cloud-url>/auth/get-platform-token ...\"\n", | ||
"\n", | ||
"discovery = h2o_discovery.discover()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "be65afc2-5ea2-4f34-b113-f5b9601f36ac", | ||
"metadata": {}, | ||
"source": [ | ||
"The cloud environment URL can alternatively be passed in as an argument when initializing the discovery object." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "70ffa313-f330-4e23-9170-902e09d271c2", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import h2o_discovery\n", | ||
"\n", | ||
"discovery = h2o_discovery.discover(environment=\"https://h2o-ai-cloud.example.com\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "3f5ff739-47f6-4e29-94de-f3300ff63c2c", | ||
"metadata": {}, | ||
"source": [ | ||
"> ℹ️ Note\n", | ||
">\n", | ||
"> For more information about the H2O Cloud Discovery package, see links in [the References section](#References)." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "0ebf913b-1f85-439a-9f5b-74c2c73455bb", | ||
"metadata": {}, | ||
"source": [ | ||
"### Pass to the Python client" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "63ad3b20-f038-4ee9-a338-39dd4245c45e", | ||
"metadata": {}, | ||
"source": [ | ||
"With the discovery object created, it can be passed to the H2O Drive client, where it will be used to facilitate service discovery so that the client may automatically determine appropriate connection details." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "61bdd017-c26b-4bda-bb39-7f7682c395e3", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"drive = h2o_drive.connect(discovery=discovery)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "7dc9bf5b-da62-450b-91bb-f325a91660b8", | ||
"metadata": {}, | ||
"source": [ | ||
"## References" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"id": "cbc23530-d7f3-41a8-9194-2fa4f82ee669", | ||
"metadata": {}, | ||
"source": [ | ||
"- [Using the H2O command line interface](https://h2oai.github.io/h2o-ai-cloud/developerguide/cli)\n", | ||
"- [H2O Cloud Discovery client](https://github.com/h2oai/cloud-discovery-py)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.7" | ||
}, | ||
"toc": { | ||
"base_numbering": 1, | ||
"nav_menu": {}, | ||
"number_sections": true, | ||
"sideBar": true, | ||
"skip_h1_title": true, | ||
"title_cell": "Table of Contents", | ||
"title_sidebar": "Contents", | ||
"toc_cell": false, | ||
"toc_position": {}, | ||
"toc_section_display": true, | ||
"toc_window_display": true | ||
}, | ||
"toc-autonumbering": false, | ||
"toc-showcode": false, | ||
"toc-showmarkdowntxt": false, | ||
"toc-showtags": false | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |