-
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.
- Loading branch information
1 parent
3c18587
commit e881554
Showing
1 changed file
with
133 additions
and
0 deletions.
There are no files selected for viewing
133 changes: 133 additions & 0 deletions
133
docs/hub-cloud/08-init-hosted-instance-custom-storage.ipynb
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,133 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Init hosted instance" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!lamin login testuser1" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import lamindb_setup as ln_setup\n", | ||
"from lamindb_setup.core.upath import create_path, UPath, InstanceNotEmpty\n", | ||
"from lamindb_setup.core._hub_core import (\n", | ||
" delete_instance,\n", | ||
" call_with_fallback_auth,\n", | ||
" select_instance_by_owner_name,\n", | ||
")\n", | ||
"import pytest\n", | ||
"\n", | ||
"instance_name = \"my-hosted\"\n", | ||
"assert ln_setup.settings.user.handle == \"testuser1\"" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"try:\n", | ||
" delete_instance(f\"testuser1/{instance_name}\")\n", | ||
"except InstanceNotEmpty:\n", | ||
" instance_with_storage = call_with_fallback_auth(\n", | ||
" select_instance_by_owner_name,\n", | ||
" owner=\"testuser1\",\n", | ||
" name=instance_name,\n", | ||
" )\n", | ||
" root = create_path(instance_with_storage[\"storage\"][\"root\"])\n", | ||
" for obj in root.rglob(\"\"):\n", | ||
" if obj.is_file():\n", | ||
" obj.unlink()\n", | ||
" delete_instance(f\"testuser1/{instance_name}\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"with pytest.raises(ValueError):\n", | ||
" ln_setup.init(storage=\"create-s3\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"ln_setup.init(name=\"my-hosted\", storage=\"create-s3\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"from lamindb_setup.core._aws_credentials import HOSTED_BUCKETS" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"assert ln_setup.settings.instance.storage.type_is_cloud == True\n", | ||
"assert ln_setup.settings.instance.owner == ln_setup.settings.user.handle\n", | ||
"assert ln_setup.settings.instance.name == \"my-hosted\"\n", | ||
"assert ln_setup.settings.storage.root.as_posix().startswith(HOSTED_BUCKETS)\n", | ||
"assert ln_setup.settings.storage.id is not None\n", | ||
"\n", | ||
"assert ln_setup.settings.storage._mark_storage_root.exists()" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"ln_setup.close()" | ||
] | ||
} | ||
], | ||
"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.9.17" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |