From 93e9555daf5d7d9d5322d229de045701331e354b Mon Sep 17 00:00:00 2001 From: gblpedia Date: Wed, 12 Apr 2023 11:01:57 +0900 Subject: [PATCH 1/3] revised the orignal screenplay, turned it into use-cases --- docs/screenplay/README.md | 4 +- docs/screenplay/image-wise-operation.ipynb | 703 ---------------- docs/screenplay/instance-type-operation.ipynb | 748 ------------------ docs/screenplay/user-wise-operation.ipynb | 485 ------------ docs/screenplay/volume-wise-operation.ipynb | 717 ----------------- 5 files changed, 2 insertions(+), 2655 deletions(-) delete mode 100644 docs/screenplay/image-wise-operation.ipynb delete mode 100644 docs/screenplay/instance-type-operation.ipynb delete mode 100644 docs/screenplay/user-wise-operation.ipynb delete mode 100644 docs/screenplay/volume-wise-operation.ipynb diff --git a/docs/screenplay/README.md b/docs/screenplay/README.md index 7598314..3198545 100644 --- a/docs/screenplay/README.md +++ b/docs/screenplay/README.md @@ -1,3 +1,3 @@ -# PrimeHub Python SDK screenplay +# PrimeHub Python SDK Use-case -PrimeHub Python SDK screenplay is a set of Juypter notebooks for user to test PrimeHub SDK function. +By these use-cases, SDK users can learn what the SDK are capable of fundamentally. diff --git a/docs/screenplay/image-wise-operation.ipynb b/docs/screenplay/image-wise-operation.ipynb deleted file mode 100644 index 13a7ba3..0000000 --- a/docs/screenplay/image-wise-operation.ipynb +++ /dev/null @@ -1,703 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "891bbcba", - "metadata": {}, - "source": [ - "# Getting Started with PrimeHub Python SDK\n", - "PrimeHub Python SDK makes you automation with PrimeHub Platform.\n", - "\n", - "In order to make the SDK working, you have to\n", - "\n", - "- install the library with pip\n", - "- create a config file in the ~/.primehub/config.json" - ] - }, - { - "cell_type": "markdown", - "id": "33144729", - "metadata": {}, - "source": [ - "# Part 1: prerequisite: Configure the environment." - ] - }, - { - "cell_type": "markdown", - "id": "c8d3ac7e", - "metadata": {}, - "source": [ - "## 1. Install with pip\n", - "Let's install PrimeHub Python SDK with pip." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "831cf7fc", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: primehub-python-sdk in /opt/conda/lib/python3.7/site-packages (0.3.8)\n", - "Requirement already satisfied: types-requests in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (2.28.11.5)\n", - "Requirement already satisfied: requests in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (2.21.0)\n", - "Requirement already satisfied: tabulate==0.8.9 in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (0.8.9)\n", - "Requirement already satisfied: types-tabulate==0.8.2 in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (0.8.2)\n", - "Requirement already satisfied: urllib3<1.25,>=1.21.1 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (1.24.3)\n", - "Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (3.0.4)\n", - "Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (2020.6.20)\n", - "Requirement already satisfied: idna<2.9,>=2.5 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (2.8)\n", - "Requirement already satisfied: types-urllib3<1.27 in /opt/conda/lib/python3.7/site-packages (from types-requests->primehub-python-sdk) (1.26.25.4)\n" - ] - } - ], - "source": [ - "!pip install primehub-python-sdk" - ] - }, - { - "cell_type": "markdown", - "id": "4cf3d67c", - "metadata": {}, - "source": [ - "## 2. Request the API Token\n", - "In order to get the token, you have to have an account in the PrimeHub cluster, the following process will ask you loing with your account.\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "73c78a9b", - "metadata": {}, - "outputs": [], - "source": [ - "# PLEASE UPDATE PRIMEHUB_CLUSTER to your cluster\n", - "PRIMEHUB_CLUSTER = 'http://primehub-python-sdk.primehub.io'" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "169edb05", - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "from primehub import PrimeHub, PrimeHubConfig\n", - "\n", - "ph = PrimeHub(PrimeHubConfig())\n", - "if not os.path.isfile(os.path.join(os.getenv(\"HOME\"), \".primehub/config.json\")):\n", - " ph.config.generate(PRIMEHUB_CLUSTER)" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "843948bc", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "PrimeHub Python SDK setup successfully\n", - "Current Group: {'id': 'ccdd52b8-db16-46ce-8a06-70343c79e82a', 'name': 'phusers', 'displayName': 'primehub users'}\n" - ] - } - ], - "source": [ - "ph = PrimeHub(PrimeHubConfig())\n", - "if ph.is_ready():\n", - " print(\"PrimeHub Python SDK setup successfully\")\n", - " print(\"Current Group:\", ph.primehub_config.current_group)\n", - "else:\n", - " print(\"PrimeHub Python SDK couldn't get the group information, please check the configuration.\")" - ] - }, - { - "cell_type": "markdown", - "id": "2943f888", - "metadata": {}, - "source": [ - "## 3. Check the account is Admin account\n", - "\n", - "Use `ph.me.me` to know that the account is admin account." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "0d9cb314", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "account_information = ph.me.me()\n", - "account_information['isAdmin']" - ] - }, - { - "cell_type": "markdown", - "id": "aada9af0", - "metadata": {}, - "source": [ - "## 4. Clean up the previous testing data.\n", - "\n", - "We need to clean up the previous data to prevent the notebook error," - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "758e5818", - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "437c31ce", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "clean the secret data: ['gitsync-secret-create-secret-by-sdk']\n" - ] - } - ], - "source": [ - "# Clean up 'gitsync-secret-create-secret-by-sdk' secret data.\n", - "\n", - "df_list = pd.DataFrame.from_records(list(ph.admin.secrets.list()))\n", - "if len(df_list) > 0:\n", - " target_id = list(df_list.loc[df_list['name'] == 'create-secret-by-sdk'][\"id\"])\n", - "\n", - " if len(target_id) == 1:\n", - " print(\"clean the secret data: {}\".format(target_id))\n", - " ph.admin.secrets.delete(\"gitsync-secret-create-secret-by-sdk\")" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "eb51012f", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "clean the image data: ['my-custom-image']\n" - ] - } - ], - "source": [ - "# Clean up 'my-custom-image' image data.\n", - "\n", - "df_list = pd.DataFrame.from_records(list(ph.admin.images.list()))\n", - "if len(df_list) > 0:\n", - " target_id = list(df_list.loc[df_list['name'] == 'my-custom-image'][\"id\"])\n", - "\n", - " if len(target_id) == 1:\n", - " print(\"clean the image data: {}\".format(target_id))\n", - " ph.admin.images.delete('my-custom-image')" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "a352befc", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "clean the image data: ['image-by-sdk']\n" - ] - } - ], - "source": [ - "# Clean up 'image-by-sdk` image data.\n", - "\n", - "df_list = pd.DataFrame.from_records(list(ph.admin.images.list()))\n", - "if len(df_list) > 0:\n", - " target_id = list(df_list.loc[df_list['name'] == 'image-by-sdk'][\"id\"])\n", - "\n", - " if len(target_id) == 1:\n", - " print(\"clean the image data: {}\".format(target_id))\n", - " ph.admin.images.delete('image-by-sdk')" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "7cfb252f", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "clean the group data: ['ba3d19ad-38a7-498b-99eb-44e0509a18b9']\n" - ] - } - ], - "source": [ - "# Clean up \"test_group_from_jupyter\" group data.\n", - "\n", - "df_list = pd.DataFrame.from_records(list(ph.admin.groups.list()))\n", - "if len(df_list) > 0:\n", - " target_id = list(df_list.loc[df_list['name'] == \"test_group_from_jupyter\"][\"id\"])\n", - "\n", - " if len(target_id) == 1:\n", - " print(\"clean the group data: {}\".format(target_id))\n", - " ph.admin.groups.delete(list(target_id)[0])" - ] - }, - { - "cell_type": "markdown", - "id": "665eae40", - "metadata": {}, - "source": [ - "# Part 2: Image-wise operation\n", - "We will test:\n", - " \n", - "- Create an image record with a existing image and a pull secret\n", - "- Disable the Global and assign the image to multiple groups\n", - "- Create another image record by building a custom image" - ] - }, - { - "cell_type": "markdown", - "id": "1663c940", - "metadata": {}, - "source": [ - "## 1. Create new secrets\n", - "Use ` ph.admin.secrets.create` to create the pull secret." - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "62bfbddc", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'id': 'gitsync-secret-create-secret-by-sdk'}" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "secret = ph.admin.secrets.create(dict(name='create-secret-by-sdk', type='opaque', secret='keep it secret'))\n", - "secret" - ] - }, - { - "cell_type": "markdown", - "id": "70ed43a3", - "metadata": {}, - "source": [ - "## 2. Create new image\n", - "Use `ph.admin.images.create` to create the jupyter image." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "id": "563a0fa4", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'id': 'image-by-sdk'}" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Create an image\n", - "config = {\n", - " \"name\": \"image-by-sdk\",\n", - " \"displayName\": \"Learning how to create an image from SDK\",\n", - " \"description\": \"base-notebook with python 3.7\",\n", - " \"type\": \"both\",\n", - " \"url\": \"infuseai/docker-stacks:base-notebook-63fdf50a\",\n", - " \"urlForGpu\": \"infuseai/docker-stacks:base-notebook-63fdf50a-gpu\",\n", - " \"global\": True,\n", - " \"useImagePullSecret\": secret['id']\n", - "}\n", - "image = ph.admin.images.create(config)\n", - "image" - ] - }, - { - "cell_type": "markdown", - "id": "f8cc7162", - "metadata": {}, - "source": [ - "## 3. Create another image record by building a custom image\n", - "Use `ph.admin.images.create` to create the jupyter image and add imageSpec to custom create image." - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "6532c4be", - "metadata": {}, - "outputs": [], - "source": [ - "# Create an custom image\n", - "config = {\n", - " \"name\": \"my-custom-image\",\n", - " \"type\": \"both\",\n", - " \"global\": True,\n", - " \"imageSpec\": {\n", - " \"baseImage\": \"jupyter/base-notebook\",\n", - " \"packages\": {\n", - " \"pip\": [\n", - " \"primehub-python-sdk\"\n", - " ]\n", - " }\n", - " }\n", - "}\n", - "image_custom = ph.admin.images.create(config)" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "id": "ad10731b", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'id': 'my-custom-image',\n", - " 'name': 'my-custom-image',\n", - " 'displayName': 'my-custom-image',\n", - " 'description': None,\n", - " 'type': 'both',\n", - " 'url': None,\n", - " 'urlForGpu': None,\n", - " 'useImagePullSecret': '',\n", - " 'global': True,\n", - " 'groups': [],\n", - " 'isReady': False,\n", - " 'imageSpec': {'baseImage': 'jupyter/base-notebook',\n", - " 'pullSecret': None,\n", - " 'packages': {'apt': [], 'conda': [], 'pip': ['primehub-python-sdk']}},\n", - " 'jobStatus': None}" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "output = ph.admin.images.get(image_custom['id'])\n", - "del output['logEndpoint']\n", - "\n", - "output" - ] - }, - { - "cell_type": "markdown", - "id": "d33fe437", - "metadata": {}, - "source": [ - "## 4. Disable the Global and assign the instance type to multiple groups\n", - "\n", - "First, we use `ph.admin.groups.create` to create the group and Use `ph.admin.instancetypes.update` to:\n", - "- Disable global instance\n", - "- Assign the instance type to multiple groups" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "id": "94cfde12", - "metadata": {}, - "outputs": [], - "source": [ - "# Create a group with admin role\n", - "config = {\n", - " \"name\": \"test_group_from_jupyter\",\n", - " \"displayName\": \"test_group\",\n", - " \"enabledDeployment\": False,\n", - " \"enabledSharedVolume\": False,\n", - " \"quotaCpu\": 0.5,\n", - " \"quotaGpu\": 0,\n", - " \"admins\": \"\",\n", - " \"users\": {\n", - " \"connect\": []\n", - " }\n", - "}\n", - "data = ph.admin.groups.create(config)" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "id": "bbcdab94", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
iddisplayNamenameadminsquotaCpuquotaGpuquotaMemoryprojectQuotaCpuprojectQuotaGpuprojectQuotaMemorysharedVolumeCapacity
0ccdd52b8-db16-46ce-8a06-70343c79e82aprimehub usersphusersphadminNaNNaNNoneNoneNoneNone1.0
1fa382829-d08a-4421-8de4-82e3231fe7a7test_grouptest_group_from_jupyter0.50.0NoneNoneNoneNoneNaN
\n", - "
" - ], - "text/plain": [ - " id displayName \\\n", - "0 ccdd52b8-db16-46ce-8a06-70343c79e82a primehub users \n", - "1 fa382829-d08a-4421-8de4-82e3231fe7a7 test_group \n", - "\n", - " name admins quotaCpu quotaGpu quotaMemory \\\n", - "0 phusers phadmin NaN NaN None \n", - "1 test_group_from_jupyter 0.5 0.0 None \n", - "\n", - " projectQuotaCpu projectQuotaGpu projectQuotaMemory sharedVolumeCapacity \n", - "0 None None None 1.0 \n", - "1 None None None NaN " - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "import pandas as pd\n", - "df_list = pd.DataFrame.from_records(list(ph.admin.groups.list()))\n", - "df_list" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "id": "a1fd5761", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[{'id': 'ccdd52b8-db16-46ce-8a06-70343c79e82a'},\n", - " {'id': 'fa382829-d08a-4421-8de4-82e3231fe7a7'}]" - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "instance_connect = []\n", - "for list_id in list(df_list['id'])[0:2]:\n", - " instance_connect.append({\"id\": list_id})\n", - "instance_connect" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "id": "16e942ee", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'id': 'image-by-sdk',\n", - " 'name': 'image-by-sdk',\n", - " 'displayName': 'Learning how to create an image from SDK',\n", - " 'description': 'base-notebook with python 3.7',\n", - " 'type': 'both',\n", - " 'url': 'infuseai/docker-stacks:base-notebook-63fdf50a',\n", - " 'urlForGpu': 'infuseai/docker-stacks:base-notebook-63fdf50a-gpu',\n", - " 'useImagePullSecret': None,\n", - " 'global': False,\n", - " 'groups': [{'id': 'ccdd52b8-db16-46ce-8a06-70343c79e82a',\n", - " 'name': 'phusers',\n", - " 'displayName': 'primehub users'},\n", - " {'id': 'fa382829-d08a-4421-8de4-82e3231fe7a7',\n", - " 'name': 'test_group_from_jupyter',\n", - " 'displayName': 'test_group'}],\n", - " 'isReady': True,\n", - " 'imageSpec': None,\n", - " 'jobStatus': None}" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Update the image information.\n", - "config = {\n", - " \"global\": False,\n", - " \"groups\": {\n", - " \"connect\": instance_connect\n", - " },\n", - "}\n", - "output = ph.admin.images.update(image['id'], config)\n", - "del output['logEndpoint']\n", - "\n", - "output" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "id": "e2096cbe", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'id': 'image-by-sdk',\n", - " 'name': 'image-by-sdk',\n", - " 'displayName': 'Learning how to create an image from SDK',\n", - " 'description': 'base-notebook with python 3.7',\n", - " 'type': 'both',\n", - " 'url': 'infuseai/docker-stacks:base-notebook-63fdf50a',\n", - " 'urlForGpu': 'infuseai/docker-stacks:base-notebook-63fdf50a-gpu',\n", - " 'useImagePullSecret': None,\n", - " 'global': False,\n", - " 'groups': [{'id': 'ccdd52b8-db16-46ce-8a06-70343c79e82a',\n", - " 'name': 'phusers',\n", - " 'displayName': 'primehub users'},\n", - " {'id': 'fa382829-d08a-4421-8de4-82e3231fe7a7',\n", - " 'name': 'test_group_from_jupyter',\n", - " 'displayName': 'test_group'}],\n", - " 'isReady': True,\n", - " 'imageSpec': None,\n", - " 'jobStatus': None}" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "output = ph.admin.images.get(image['id'])\n", - "del output['logEndpoint']\n", - "\n", - "output" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "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.7.10" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/docs/screenplay/instance-type-operation.ipynb b/docs/screenplay/instance-type-operation.ipynb deleted file mode 100644 index 1d90b01..0000000 --- a/docs/screenplay/instance-type-operation.ipynb +++ /dev/null @@ -1,748 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "b0354d44", - "metadata": {}, - "source": [ - "# Getting Started with PrimeHub Python SDK\n", - "PrimeHub Python SDK makes you automation with PrimeHub Platform.\n", - "\n", - "In order to make the SDK working, you have to\n", - "\n", - "- install the library with pip\n", - "- create a config file in the ~/.primehub/config.json" - ] - }, - { - "cell_type": "markdown", - "id": "e18be4f2", - "metadata": {}, - "source": [ - "# Part 1: prerequisite: Configure the environment." - ] - }, - { - "cell_type": "markdown", - "id": "9838338c", - "metadata": {}, - "source": [ - "## 1. Install with pip\n", - "Let's install PrimeHub Python SDK with pip." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "0ee33408", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: primehub-python-sdk in /opt/conda/lib/python3.7/site-packages (0.3.8)\n", - "Requirement already satisfied: types-requests in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (2.28.11.5)\n", - "Requirement already satisfied: types-tabulate==0.8.2 in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (0.8.2)\n", - "Requirement already satisfied: tabulate==0.8.9 in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (0.8.9)\n", - "Requirement already satisfied: requests in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (2.21.0)\n", - "Requirement already satisfied: idna<2.9,>=2.5 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (2.8)\n", - "Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (2020.6.20)\n", - "Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (3.0.4)\n", - "Requirement already satisfied: urllib3<1.25,>=1.21.1 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (1.24.3)\n", - "Requirement already satisfied: types-urllib3<1.27 in /opt/conda/lib/python3.7/site-packages (from types-requests->primehub-python-sdk) (1.26.25.4)\n" - ] - } - ], - "source": [ - "!pip install primehub-python-sdk" - ] - }, - { - "cell_type": "markdown", - "id": "3e47843c", - "metadata": {}, - "source": [ - "## 2. Request the API Token\n", - "In order to get the token, you have to have an account in the PrimeHub cluster, the following process will ask you loing with your account.\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "11bd0e6f", - "metadata": {}, - "outputs": [], - "source": [ - "# PLEASE UPDATE PRIMEHUB_CLUSTER to your cluster\n", - "PRIMEHUB_CLUSTER = 'http://primehub-python-sdk.primehub.io'" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "c80f5d6e", - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "from primehub import PrimeHub, PrimeHubConfig\n", - "\n", - "ph = PrimeHub(PrimeHubConfig())\n", - "if not os.path.isfile(os.path.join(os.getenv(\"HOME\"), \".primehub/config.json\")):\n", - " ph.config.generate(PRIMEHUB_CLUSTER)" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "a85bd60c", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "PrimeHub Python SDK setup successfully\n", - "Current Group: {'id': 'ccdd52b8-db16-46ce-8a06-70343c79e82a', 'name': 'phusers', 'displayName': 'primehub users'}\n" - ] - } - ], - "source": [ - "ph = PrimeHub(PrimeHubConfig())\n", - "if ph.is_ready():\n", - " print(\"PrimeHub Python SDK setup successfully\")\n", - " print(\"Current Group:\", ph.primehub_config.current_group)\n", - "else:\n", - " print(\"PrimeHub Python SDK couldn't get the group information, please check the configuration.\")" - ] - }, - { - "cell_type": "markdown", - "id": "f259bec3", - "metadata": {}, - "source": [ - "## 3. Check the account is Admin account\n", - "\n", - "Use `ph.me.me` to know that the account is admin account." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "7a23976b", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "account_information = ph.me.me()\n", - "account_information['isAdmin']" - ] - }, - { - "cell_type": "markdown", - "id": "99fbc695", - "metadata": {}, - "source": [ - "## 4. Clean up the previous testing data.\n", - "\n", - "We need to clean up the previous data to prevent the notebook error," - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "44c98418", - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "938e77f8", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "clean the instance type data: cpu-instance-by-sdk\n" - ] - } - ], - "source": [ - "# Clean up \"cpu-instance-by-sdk\" instancetype data.\n", - "\n", - "df_list = pd.DataFrame.from_records(list(ph.admin.instancetypes.list()))\n", - "if len(df_list) > 0:\n", - " target_id = list(df_list.loc[df_list['name'] == \"cpu-instance-by-sdk\"][\"id\"])\n", - "\n", - " if len(target_id) == 1:\n", - " print(\"clean the instance type data: {}\".format(target_id[0]))\n", - " ph.admin.instancetypes.delete(list(target_id)[0])" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "731ccef9", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "clean the group data: ['fa382829-d08a-4421-8de4-82e3231fe7a7']\n" - ] - } - ], - "source": [ - "# Clean up \"test_group_from_jupyter\" group data.\n", - "\n", - "df_list = pd.DataFrame.from_records(list(ph.admin.groups.list()))\n", - "if len(df_list) > 0:\n", - " target_id = list(df_list.loc[df_list['name'] == \"test_group_from_jupyter\"][\"id\"])\n", - "\n", - " if len(target_id) == 1:\n", - " print(\"clean the group data: {}\".format(target_id))\n", - " ph.admin.groups.delete(list(target_id)[0])" - ] - }, - { - "cell_type": "markdown", - "id": "3b2ed35d", - "metadata": {}, - "source": [ - "# Part 2: Instance-type-wise operation\n", - "We will test:\n", - " \n", - "- Create an instance type with specified CPU/GPU/Memory limits\n", - "- Disable the Global and assign the instance type to multiple groups\n", - "- Add a new Toleration\n", - "- Add a new Node Selector" - ] - }, - { - "cell_type": "markdown", - "id": "cc1275fb", - "metadata": {}, - "source": [ - "## 1. Create an instance type with specified CPU/GPU/Memory limits\n", - "\n", - "Use `ph.admin.instancetypes.create` to create the instance type." - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "83835021", - "metadata": {}, - "outputs": [], - "source": [ - "# create an instance type\n", - "config = {\n", - " \"name\": \"cpu-instance-by-sdk\",\n", - " \"displayName\": \"CPU 1\",\n", - " \"description\": \"1 vCPU / 1G Memory\",\n", - " \"cpuLimit\": 1,\n", - " \"memoryLimit\": 1,\n", - " \"global\": True\n", - "}\n", - "instancetype = ph.admin.instancetypes.create(config)" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "994480fd", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'cpu-instance-by-sdk'" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "instancetype['id']" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "287cf2c1", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'id': 'cpu-instance-by-sdk',\n", - " 'cpuRequest': None,\n", - " 'memoryRequest': None,\n", - " 'global': True,\n", - " 'groups': [],\n", - " 'tolerations': [],\n", - " 'nodeSelector': None,\n", - " 'name': 'cpu-instance-by-sdk',\n", - " 'displayName': 'CPU 1',\n", - " 'description': '1 vCPU / 1G Memory',\n", - " 'cpuLimit': 1,\n", - " 'memoryLimit': 1,\n", - " 'gpuLimit': 0}" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ph.admin.instancetypes.get(instancetype['id'])" - ] - }, - { - "cell_type": "markdown", - "id": "d6253965", - "metadata": {}, - "source": [ - "## 2. Add a new Toleration\n", - "\n", - "Use `ph.admin.instancetypes.update` to add the tolerations information into instancetype." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "id": "e53b29b6", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'id': 'cpu-instance-by-sdk',\n", - " 'global': True,\n", - " 'cpuRequest': None,\n", - " 'memoryRequest': None,\n", - " 'groups': [],\n", - " 'nodeSelector': {}}" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "config = {\n", - " \"tolerations\": {\n", - " \"set\": [\n", - " {\n", - " \"operator\": \"Equal\",\n", - " \"effect\": \"NoSchedule\",\n", - " \"key\": \"nvidia.com/gpu\",\n", - " \"value\": \"v100\"\n", - " }\n", - " ]\n", - " }\n", - "}\n", - "ph.admin.instancetypes.update(instancetype['id'], config)" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "defda096", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'id': 'cpu-instance-by-sdk',\n", - " 'cpuRequest': None,\n", - " 'memoryRequest': None,\n", - " 'global': True,\n", - " 'groups': [],\n", - " 'tolerations': [{'key': 'nvidia.com/gpu',\n", - " 'value': 'v100',\n", - " 'operator': 'Equal',\n", - " 'effect': 'NoSchedule'}],\n", - " 'nodeSelector': {},\n", - " 'name': 'cpu-instance-by-sdk',\n", - " 'displayName': 'CPU 1',\n", - " 'description': '1 vCPU / 1G Memory',\n", - " 'cpuLimit': 1,\n", - " 'memoryLimit': 1,\n", - " 'gpuLimit': 0}" - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ph.admin.instancetypes.get(instancetype['id'])" - ] - }, - { - "cell_type": "markdown", - "id": "7e346aee", - "metadata": {}, - "source": [ - "## 3. Add a new Node Selector\n", - "\n", - "Use `ph.admin.instancetypes.update` to add the Node Selector information into instancetype." - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "id": "4f54132d", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'id': 'cpu-instance-by-sdk',\n", - " 'global': True,\n", - " 'cpuRequest': None,\n", - " 'memoryRequest': None,\n", - " 'groups': [],\n", - " 'nodeSelector': {'zone': 'staging'}}" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "config = {\n", - " \"nodeSelector\": {\"zone\": \"staging\"}\n", - "}\n", - "ph.admin.instancetypes.update(instancetype['id'], config)" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "id": "7095de4c", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'id': 'cpu-instance-by-sdk',\n", - " 'cpuRequest': None,\n", - " 'memoryRequest': None,\n", - " 'global': True,\n", - " 'groups': [],\n", - " 'tolerations': [{'key': 'nvidia.com/gpu',\n", - " 'value': 'v100',\n", - " 'operator': 'Equal',\n", - " 'effect': 'NoSchedule'}],\n", - " 'nodeSelector': {'zone': 'staging'},\n", - " 'name': 'cpu-instance-by-sdk',\n", - " 'displayName': 'CPU 1',\n", - " 'description': '1 vCPU / 1G Memory',\n", - " 'cpuLimit': 1,\n", - " 'memoryLimit': 1,\n", - " 'gpuLimit': 0}" - ] - }, - "execution_count": 15, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ph.admin.instancetypes.get(instancetype['id'])" - ] - }, - { - "cell_type": "markdown", - "id": "904eddb2", - "metadata": {}, - "source": [ - "## 4. Disable the Global and assign the instance type to multiple groups\n", - "\n", - "First, we use `ph.admin.groups.create` to create the group and Use `ph.admin.instancetypes.update` to:\n", - "- Disable global instance\n", - "- Assign the instance type to multiple groups" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "id": "7ad820de", - "metadata": {}, - "outputs": [], - "source": [ - "# Create a group with admin role\n", - "config = {\n", - " \"name\": \"test_group_from_jupyter\",\n", - " \"displayName\": \"test_group\",\n", - " \"enabledDeployment\": False,\n", - " \"enabledSharedVolume\": False,\n", - " \"quotaCpu\": 0.5,\n", - " \"quotaGpu\": 0,\n", - " \"admins\": \"\",\n", - " \"users\": {\n", - " \"connect\": []\n", - " }\n", - "}\n", - "data = ph.admin.groups.create(config)" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "id": "b9ca57bf", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
iddisplayNamenameadminsquotaCpuquotaGpuquotaMemoryprojectQuotaCpuprojectQuotaGpuprojectQuotaMemorysharedVolumeCapacity
0ccdd52b8-db16-46ce-8a06-70343c79e82aprimehub usersphusersphadminNaNNaNNoneNoneNoneNone1.0
1df7fdfe4-5e12-4f1c-aeac-8004160c8e86test_grouptest_group_from_jupyter0.50.0NoneNoneNoneNoneNaN
\n", - "
" - ], - "text/plain": [ - " id displayName \\\n", - "0 ccdd52b8-db16-46ce-8a06-70343c79e82a primehub users \n", - "1 df7fdfe4-5e12-4f1c-aeac-8004160c8e86 test_group \n", - "\n", - " name admins quotaCpu quotaGpu quotaMemory \\\n", - "0 phusers phadmin NaN NaN None \n", - "1 test_group_from_jupyter 0.5 0.0 None \n", - "\n", - " projectQuotaCpu projectQuotaGpu projectQuotaMemory sharedVolumeCapacity \n", - "0 None None None 1.0 \n", - "1 None None None NaN " - ] - }, - "execution_count": 17, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "import pandas as pd\n", - "df_list = pd.DataFrame.from_records(list(ph.admin.groups.list()))\n", - "df_list" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "id": "1d2540c7", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[{'id': 'ccdd52b8-db16-46ce-8a06-70343c79e82a'},\n", - " {'id': 'df7fdfe4-5e12-4f1c-aeac-8004160c8e86'}]" - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "instance_connect = []\n", - "for list_id in list(df_list['id'])[0:2]:\n", - " instance_connect.append({\"id\": list_id})\n", - "instance_connect" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "id": "266fcf26", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'id': 'cpu-instance-by-sdk',\n", - " 'global': False,\n", - " 'cpuRequest': None,\n", - " 'memoryRequest': None,\n", - " 'groups': [{'id': 'ccdd52b8-db16-46ce-8a06-70343c79e82a',\n", - " 'name': 'phusers',\n", - " 'displayName': 'primehub users',\n", - " 'quotaCpu': None,\n", - " 'quotaGpu': None},\n", - " {'id': 'df7fdfe4-5e12-4f1c-aeac-8004160c8e86',\n", - " 'name': 'test_group_from_jupyter',\n", - " 'displayName': 'test_group',\n", - " 'quotaCpu': 0.5,\n", - " 'quotaGpu': 0}],\n", - " 'nodeSelector': {'zone': 'staging'}}" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Update an instance type\n", - "config = {\n", - " \"global\": False,\n", - " \"groups\": {\n", - " \"connect\": instance_connect\n", - " },\n", - "}\n", - "ph.admin.instancetypes.update(instancetype['id'], config)" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "id": "e7ffd081", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'id': 'cpu-instance-by-sdk',\n", - " 'cpuRequest': None,\n", - " 'memoryRequest': None,\n", - " 'global': False,\n", - " 'groups': [{'id': 'ccdd52b8-db16-46ce-8a06-70343c79e82a',\n", - " 'name': 'phusers',\n", - " 'displayName': 'primehub users',\n", - " 'quotaCpu': None,\n", - " 'quotaGpu': None},\n", - " {'id': 'df7fdfe4-5e12-4f1c-aeac-8004160c8e86',\n", - " 'name': 'test_group_from_jupyter',\n", - " 'displayName': 'test_group',\n", - " 'quotaCpu': 0.5,\n", - " 'quotaGpu': 0}],\n", - " 'tolerations': [{'key': 'nvidia.com/gpu',\n", - " 'value': 'v100',\n", - " 'operator': 'Equal',\n", - " 'effect': 'NoSchedule'}],\n", - " 'nodeSelector': {'zone': 'staging'},\n", - " 'name': 'cpu-instance-by-sdk',\n", - " 'displayName': 'CPU 1',\n", - " 'description': '1 vCPU / 1G Memory',\n", - " 'cpuLimit': 1,\n", - " 'memoryLimit': 1,\n", - " 'gpuLimit': 0}" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ph.admin.instancetypes.get(instancetype['id'])" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "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.7.10" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/docs/screenplay/user-wise-operation.ipynb b/docs/screenplay/user-wise-operation.ipynb deleted file mode 100644 index 92ff293..0000000 --- a/docs/screenplay/user-wise-operation.ipynb +++ /dev/null @@ -1,485 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "a6dee8e4", - "metadata": {}, - "source": [ - "# Getting Started with PrimeHub Python SDK\n", - "PrimeHub Python SDK makes you automation with PrimeHub Platform.\n", - "\n", - "In order to make the SDK working, you have to\n", - "\n", - "- install the library with pip\n", - "- create a config file in the ~/.primehub/config.json" - ] - }, - { - "cell_type": "markdown", - "id": "9311290d", - "metadata": {}, - "source": [ - "# Part 1: prerequisite: Configure the environment." - ] - }, - { - "cell_type": "markdown", - "id": "b6370d94", - "metadata": {}, - "source": [ - "## 1. Install with pip\n", - "Let's install PrimeHub Python SDK with pip." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "05e0ee39", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: primehub-python-sdk in /opt/conda/lib/python3.7/site-packages (0.3.8)\n", - "Requirement already satisfied: types-requests in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (2.28.11.5)\n", - "Requirement already satisfied: tabulate==0.8.9 in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (0.8.9)\n", - "Requirement already satisfied: types-tabulate==0.8.2 in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (0.8.2)\n", - "Requirement already satisfied: requests in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (2.21.0)\n", - "Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (3.0.4)\n", - "Requirement already satisfied: urllib3<1.25,>=1.21.1 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (1.24.3)\n", - "Requirement already satisfied: idna<2.9,>=2.5 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (2.8)\n", - "Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (2020.6.20)\n", - "Requirement already satisfied: types-urllib3<1.27 in /opt/conda/lib/python3.7/site-packages (from types-requests->primehub-python-sdk) (1.26.25.4)\n" - ] - } - ], - "source": [ - "!pip install primehub-python-sdk" - ] - }, - { - "cell_type": "markdown", - "id": "4d37c4d1", - "metadata": {}, - "source": [ - "## 2. Request the API Token\n", - "In order to get the token, you have to have an account in the PrimeHub cluster, the following process will ask you loing with your account.\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "8a8f0489", - "metadata": {}, - "outputs": [], - "source": [ - "# PLEASE UPDATE PRIMEHUB_CLUSTER to your cluster\n", - "PRIMEHUB_CLUSTER = 'http://primehub-python-sdk.primehub.io'" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "7e9ee04b", - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "from primehub import PrimeHub, PrimeHubConfig\n", - "\n", - "ph = PrimeHub(PrimeHubConfig())\n", - "if not os.path.isfile(os.path.join(os.getenv(\"HOME\"), \".primehub/config.json\")):\n", - " ph.config.generate(PRIMEHUB_CLUSTER)" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "66189ddf", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "PrimeHub Python SDK setup successfully\n", - "Current Group: {'id': 'ccdd52b8-db16-46ce-8a06-70343c79e82a', 'name': 'phusers', 'displayName': 'primehub users'}\n" - ] - } - ], - "source": [ - "ph = PrimeHub(PrimeHubConfig())\n", - "if ph.is_ready():\n", - " print(\"PrimeHub Python SDK setup successfully\")\n", - " print(\"Current Group:\", ph.primehub_config.current_group)\n", - "else:\n", - " print(\"PrimeHub Python SDK couldn't get the group information, please check the configuration.\")" - ] - }, - { - "cell_type": "markdown", - "id": "841a9c99", - "metadata": {}, - "source": [ - "## 3. Check the account is Admin account\n", - "\n", - "Use `ph.me.me` to know that the account is admin account." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "88c0d6e3", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "account_information = ph.me.me()\n", - "account_information['isAdmin']" - ] - }, - { - "cell_type": "markdown", - "id": "8d93feef", - "metadata": {}, - "source": [ - "## 4. Clean up the previous testing data.\n", - "\n", - "We need to clean up the previous data to prevent the notebook error," - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "26e30fb4", - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "525478fa", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "clean the group data: ['df7fdfe4-5e12-4f1c-aeac-8004160c8e86']\n" - ] - } - ], - "source": [ - "# Clean up \"test_group_from_jupyter\" group data.\n", - "\n", - "df_list = pd.DataFrame.from_records(list(ph.admin.groups.list()))\n", - "if len(df_list) > 0:\n", - " target_id = list(df_list.loc[df_list['name'] == \"test_group_from_jupyter\"][\"id\"])\n", - "\n", - " if len(target_id) == 1:\n", - " print(\"clean the group data: {}\".format(target_id))\n", - " ph.admin.groups.delete(list(target_id)[0])" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "a8ac65dc", - "metadata": {}, - "outputs": [], - "source": [ - "# Clean up \"user-admin-from-jupyter\" user data.\n", - "\n", - "df_list = pd.DataFrame.from_records(list(ph.admin.users.list()))\n", - "if len(df_list) > 0:\n", - " target_id = list(df_list.loc[df_list['username'] == \"user-admin-from-jupyter\"][\"id\"])\n", - "\n", - " if len(target_id) == 1:\n", - " print(\"clean the user data: {}\".format(target_id))\n", - " ph.admin.users.delete(list(target_id)[0])" - ] - }, - { - "cell_type": "markdown", - "id": "cdf6b2a7", - "metadata": {}, - "source": [ - "# Part 2: User-wise operation\n", - "We will test:\n", - " \n", - "- create a user\n", - "- Enabling Personal Volume Capacity with specified xxG\n", - "- Assign the user multiple groups\n", - "- Get a group list of the user" - ] - }, - { - "cell_type": "markdown", - "id": "6a8aebbc", - "metadata": {}, - "source": [ - "## 1. Create a group with admin role\n", - "\n", - "Use `ph.admin.groups.create` to create the group." - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "c569d05f", - "metadata": {}, - "outputs": [], - "source": [ - "# Create a group with admin role\n", - "config = {\n", - " \"name\": \"test_group_from_jupyter\",\n", - " \"displayName\": \"test_group\",\n", - " \"enabledDeployment\": False,\n", - " \"enabledSharedVolume\": False,\n", - " \"quotaCpu\": 0.5,\n", - " \"quotaGpu\": 0,\n", - " \"admins\": \"\",\n", - " \"users\": {\n", - " \"connect\": []\n", - " }\n", - "}\n", - "data = ph.admin.groups.create(config)" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "96b5e6a3", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "'d30688b3-fdf3-4b28-84ac-a1ef29c01033'" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "data['id']" - ] - }, - { - "cell_type": "markdown", - "id": "403be447", - "metadata": {}, - "source": [ - "## 2. Create a user with admin role\n", - "\n", - "Use `ph.admin.users.create` to :\n", - "- create the user\n", - "- enable PV capacity with specified 2Gb\n", - "- Assign the user multiple groups" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "26fc719f", - "metadata": {}, - "outputs": [], - "source": [ - "# Create a user with admin role\n", - "config = {\n", - " \"username\": \"user-admin-from-jupyter\",\n", - " \"groups\": {\n", - " \"connect\": [\n", - " {\n", - " \"id\": ph.group_id\n", - " },\n", - " {\n", - " \"id\": data['id']\n", - " }\n", - " ]\n", - " },\n", - " \"isAdmin\": True,\n", - " \"volumeCapacity\": 2\n", - "}\n", - "data = ph.admin.users.create(config)" - ] - }, - { - "cell_type": "markdown", - "id": "5602ff85", - "metadata": {}, - "source": [ - "## 3. Get a group list of the user\n", - "\n", - "Use `ph.admin.groups.list` and `ph.admin.users.list()` to get the group and user list." - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "id": "d1d714b2", - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "c2625922", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
iddisplayNamenameadminsquotaCpuquotaGpuquotaMemoryprojectQuotaCpuprojectQuotaGpuprojectQuotaMemorysharedVolumeCapacity
0ccdd52b8-db16-46ce-8a06-70343c79e82aprimehub usersphusersphadminNaNNaNNoneNoneNoneNone1.0
1d30688b3-fdf3-4b28-84ac-a1ef29c01033test_grouptest_group_from_jupyter0.50.0NoneNoneNoneNoneNaN
\n", - "
" - ], - "text/plain": [ - " id displayName \\\n", - "0 ccdd52b8-db16-46ce-8a06-70343c79e82a primehub users \n", - "1 d30688b3-fdf3-4b28-84ac-a1ef29c01033 test_group \n", - "\n", - " name admins quotaCpu quotaGpu quotaMemory \\\n", - "0 phusers phadmin NaN NaN None \n", - "1 test_group_from_jupyter 0.5 0.0 None \n", - "\n", - " projectQuotaCpu projectQuotaGpu projectQuotaMemory sharedVolumeCapacity \n", - "0 None None None 1.0 \n", - "1 None None None NaN " - ] - }, - "execution_count": 13, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "pd.DataFrame.from_records(list(ph.admin.groups.list()))" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "id": "ce28c30b", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[{'id': 'bf989d98-cafc-47a6-832b-2d9843761cf7', 'username': 'phadmin'},\n", - " {'id': '8a15793c-5845-44b1-9efa-0f1ca858fc1e',\n", - " 'username': 'user-admin-from-jupyter'}]" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ph.admin.groups.get(ph.group_id)['users']" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "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.7.10" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/docs/screenplay/volume-wise-operation.ipynb b/docs/screenplay/volume-wise-operation.ipynb deleted file mode 100644 index 81a3753..0000000 --- a/docs/screenplay/volume-wise-operation.ipynb +++ /dev/null @@ -1,717 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "84a62268", - "metadata": {}, - "source": [ - "# Getting Started with PrimeHub Python SDK\n", - "PrimeHub Python SDK makes you automation with PrimeHub Platform.\n", - "\n", - "In order to make the SDK working, you have to\n", - "\n", - "- install the library with pip\n", - "- create a config file in the ~/.primehub/config.json" - ] - }, - { - "cell_type": "markdown", - "id": "9ab3d07d", - "metadata": {}, - "source": [ - "# Part 1: prerequisite: Configure the environment." - ] - }, - { - "cell_type": "markdown", - "id": "7d8a9861", - "metadata": {}, - "source": [ - "## 1. Install with pip\n", - "Let's install PrimeHub Python SDK with pip." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "id": "542fe378", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: primehub-python-sdk in /opt/conda/lib/python3.7/site-packages (0.3.8)\n", - "Requirement already satisfied: tabulate==0.8.9 in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (0.8.9)\n", - "Requirement already satisfied: requests in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (2.21.0)\n", - "Requirement already satisfied: types-tabulate==0.8.2 in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (0.8.2)\n", - "Requirement already satisfied: types-requests in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (2.28.11.5)\n", - "Requirement already satisfied: idna<2.9,>=2.5 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (2.8)\n", - "Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (3.0.4)\n", - "Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (2020.6.20)\n", - "Requirement already satisfied: urllib3<1.25,>=1.21.1 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (1.24.3)\n", - "Requirement already satisfied: types-urllib3<1.27 in /opt/conda/lib/python3.7/site-packages (from types-requests->primehub-python-sdk) (1.26.25.4)\n" - ] - } - ], - "source": [ - "!pip install primehub-python-sdk" - ] - }, - { - "cell_type": "markdown", - "id": "7cf7a36f", - "metadata": {}, - "source": [ - "## 2. Request the API Token\n", - "In order to get the token, you have to have an account in the PrimeHub cluster, the following process will ask you loing with your account.\n", - "\n" - ] - }, - { - "cell_type": "code", - "execution_count": 2, - "id": "42fd57da", - "metadata": {}, - "outputs": [], - "source": [ - "# PLEASE UPDATE PRIMEHUB_CLUSTER to your cluster\n", - "PRIMEHUB_CLUSTER = 'http://primehub-python-sdk.primehub.io'" - ] - }, - { - "cell_type": "code", - "execution_count": 3, - "id": "b9f33b83", - "metadata": {}, - "outputs": [], - "source": [ - "import os\n", - "from primehub import PrimeHub, PrimeHubConfig\n", - "\n", - "ph = PrimeHub(PrimeHubConfig())\n", - "if not os.path.isfile(os.path.join(os.getenv(\"HOME\"), \".primehub/config.json\")):\n", - " ph.config.generate(PRIMEHUB_CLUSTER)" - ] - }, - { - "cell_type": "code", - "execution_count": 4, - "id": "08da112d", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "PrimeHub Python SDK setup successfully\n", - "Current Group: {'id': 'ccdd52b8-db16-46ce-8a06-70343c79e82a', 'name': 'phusers', 'displayName': 'primehub users'}\n" - ] - } - ], - "source": [ - "ph = PrimeHub(PrimeHubConfig())\n", - "if ph.is_ready():\n", - " print(\"PrimeHub Python SDK setup successfully\")\n", - " print(\"Current Group:\", ph.primehub_config.current_group)\n", - "else:\n", - " print(\"PrimeHub Python SDK couldn't get the group information, please check the configuration.\")" - ] - }, - { - "cell_type": "markdown", - "id": "d2f27004", - "metadata": {}, - "source": [ - "## 3. Check the account is Admin account\n", - "\n", - "Use `ph.me.me` to know that the account is admin account." - ] - }, - { - "cell_type": "code", - "execution_count": 5, - "id": "2fc193c7", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 5, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "account_information = ph.me.me()\n", - "account_information['isAdmin']" - ] - }, - { - "cell_type": "markdown", - "id": "0b65e315", - "metadata": {}, - "source": [ - "## 4. Clean up the previous testing data.\n", - "\n", - "We need to clean up the previous data to prevent the notebook error," - ] - }, - { - "cell_type": "code", - "execution_count": 6, - "id": "996e563a", - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd" - ] - }, - { - "cell_type": "code", - "execution_count": 7, - "id": "e2de98f0", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "clean the group data: ['pv-volume-1668656133']\n", - "clean the group data: ['host-path-volume']\n", - "clean the group data: ['git-volume']\n", - "clean the group data: ['env-volume']\n" - ] - } - ], - "source": [ - "# Clean up volume data we created before.\n", - "\n", - "for volume_name in [\"pv-volume\", \"host-path-volume\", \"git-volume\", \"env-volume\"]:\n", - " df_list = pd.DataFrame.from_records(list(ph.admin.volumes.list()))\n", - " if len(df_list) > 0:\n", - " target_id = list(df_list.loc[df_list['name'].str.contains(volume_name)][\"id\"])\n", - "\n", - " if len(target_id) == 1:\n", - " print(\"clean the group data: {}\".format(target_id))\n", - " ph.admin.volumes.delete(list(target_id)[0])" - ] - }, - { - "cell_type": "code", - "execution_count": 8, - "id": "cba9f20d", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "clean the group data: ['afc2366f-e9b4-4eec-991c-e128dd3a0b89']\n" - ] - } - ], - "source": [ - "# Clean up \"test_group_from_jupyter\" group data.\n", - "\n", - "df_list = pd.DataFrame.from_records(list(ph.admin.groups.list()))\n", - "if len(df_list) > 0:\n", - " target_id = list(df_list.loc[df_list['name'] == \"test_group_from_jupyter\"][\"id\"])\n", - "\n", - " if len(target_id) == 1:\n", - " print(\"clean the group data: {}\".format(target_id))\n", - " ph.admin.groups.delete(list(target_id)[0])" - ] - }, - { - "cell_type": "markdown", - "id": "01c0a565", - "metadata": {}, - "source": [ - "# Part 2: Volume-wise operation\n", - "We will test:\n", - " \n", - "- Create a volume of Persistent Volume type\n", - "- Create a volume of HostPath type\n", - "- Create a volume of Git sync type\n", - "- Create a volume of Env type\n", - "- Disable the Global of a volume and assign the volume multiple groups" - ] - }, - { - "cell_type": "markdown", - "id": "12c9f9bd", - "metadata": {}, - "source": [ - "## 1. Create a volume of Persistent Volume type\n" - ] - }, - { - "cell_type": "code", - "execution_count": 9, - "id": "1a07d81b", - "metadata": {}, - "outputs": [], - "source": [ - "import time\n", - "\n", - "# Create a pv volume with admin role\n", - "config = {\n", - " \"name\": \"pv-volume-{}\".format(int(time.time())),\n", - " \"displayName\": \"the volume created by SDK\",\n", - " \"description\": \"It is a PV volume\",\n", - " \"type\": \"pv\",\n", - " \"global\": True,\n", - " \"pvProvisioning\": \"auto\",\n", - " \"volumeSize\": 1\n", - "}\n", - "volume = ph.admin.volumes.create(config)" - ] - }, - { - "cell_type": "code", - "execution_count": 10, - "id": "26b76067", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'id': 'pv-volume-1668656166',\n", - " 'name': 'pv-volume-1668656166',\n", - " 'displayName': 'the volume created by SDK',\n", - " 'description': 'It is a PV volume',\n", - " 'type': 'pv',\n", - " 'pvProvisioning': 'auto',\n", - " 'volumeSize': 1,\n", - " 'enableUploadServer': False,\n", - " 'uploadServerLink': None,\n", - " 'global': True,\n", - " 'groups': []}" - ] - }, - "execution_count": 10, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ph.admin.volumes.get(volume[\"id\"]) " - ] - }, - { - "cell_type": "markdown", - "id": "694c3ed8", - "metadata": {}, - "source": [ - "## 2. Create a volume of HostPath type" - ] - }, - { - "cell_type": "code", - "execution_count": 11, - "id": "f89d3384", - "metadata": {}, - "outputs": [], - "source": [ - "# Create a host path volume with admin role\n", - "config = {\n", - " \"name\": \"host-path-volume\",\n", - " \"description\": \"\",\n", - " \"type\": \"hostPath\",\n", - " \"global\": True,\n", - " \"hostPath\": \"/opt/data\"\n", - "}\n", - "volume = ph.admin.volumes.create(config)" - ] - }, - { - "cell_type": "code", - "execution_count": 12, - "id": "f91b4507", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'id': 'host-path-volume',\n", - " 'name': 'host-path-volume',\n", - " 'displayName': 'host-path-volume',\n", - " 'description': '',\n", - " 'type': 'hostPath',\n", - " 'hostPath': '/opt/data',\n", - " 'enableUploadServer': False,\n", - " 'uploadServerLink': None,\n", - " 'global': True,\n", - " 'groups': []}" - ] - }, - "execution_count": 12, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ph.admin.volumes.get(volume[\"id\"]) " - ] - }, - { - "cell_type": "markdown", - "id": "7a3f58bd", - "metadata": {}, - "source": [ - "## 3. Create a volume of Git sync type\n" - ] - }, - { - "cell_type": "code", - "execution_count": 13, - "id": "29053fa7", - "metadata": {}, - "outputs": [], - "source": [ - "# Create a git sync volume with admin role\n", - "config = {\n", - " \"name\": \"git-volume\",\n", - " \"type\": \"git\",\n", - " \"global\": True,\n", - " \"url\": \"https://github.com/datasets/covid-19\"\n", - "}\n", - "volume = ph.admin.volumes.create(config)" - ] - }, - { - "cell_type": "code", - "execution_count": 14, - "id": "722644af", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'id': 'git-volume',\n", - " 'name': 'git-volume',\n", - " 'displayName': 'git-volume',\n", - " 'description': '',\n", - " 'type': 'git',\n", - " 'url': 'https://github.com/datasets/covid-19',\n", - " 'secret': None,\n", - " 'global': True,\n", - " 'groups': []}" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ph.admin.volumes.get(volume[\"id\"]) " - ] - }, - { - "cell_type": "markdown", - "id": "e62f2912", - "metadata": {}, - "source": [ - "## 4. Create a volume of Env type" - ] - }, - { - "cell_type": "code", - "execution_count": 15, - "id": "c5a3db8f", - "metadata": {}, - "outputs": [], - "source": [ - "# Create a env volume with admin role\n", - "config = {\n", - " \"name\": \"env-volume\",\n", - " \"description\": \"\",\n", - " \"type\": \"env\",\n", - " \"variables\": {\n", - " \"ENV\": \"prod\",\n", - " \"LUCKY_NUMBER\": \"7\"\n", - " }\n", - "}\n", - "volume = ph.admin.volumes.create(config)" - ] - }, - { - "cell_type": "code", - "execution_count": 16, - "id": "3c3fe19d", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'id': 'env-volume',\n", - " 'name': 'env-volume',\n", - " 'displayName': 'env-volume',\n", - " 'description': '',\n", - " 'type': 'env',\n", - " 'variables': {'ENV': 'prod', 'LUCKY_NUMBER': '7'},\n", - " 'global': False,\n", - " 'groups': []}" - ] - }, - "execution_count": 16, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "ph.admin.volumes.get(volume[\"id\"]) " - ] - }, - { - "cell_type": "markdown", - "id": "df161dbc", - "metadata": {}, - "source": [ - "## 5. Disable the Global and assign the instance type to multiple groups\n", - "\n", - "First, we use `ph.admin.groups.create` to create the group and Use `ph.admin.instancetypes.update` to:\n", - "- Disable global instance\n", - "- Assign the instance type to multiple groups" - ] - }, - { - "cell_type": "code", - "execution_count": 17, - "id": "18ec600a", - "metadata": {}, - "outputs": [], - "source": [ - "# Create a group with admin role\n", - "config = {\n", - " \"name\": \"test_group_from_jupyter\",\n", - " \"displayName\": \"test_group\",\n", - " \"enabledDeployment\": False,\n", - " \"enabledSharedVolume\": False,\n", - " \"quotaCpu\": 0.5,\n", - " \"quotaGpu\": 0,\n", - " \"admins\": \"\",\n", - " \"users\": {\n", - " \"connect\": []\n", - " }\n", - "}\n", - "data = ph.admin.groups.create(config)" - ] - }, - { - "cell_type": "code", - "execution_count": 18, - "id": "b857280e", - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "
\n", - "\n", - "\n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - "
iddisplayNamenameadminsquotaCpuquotaGpuquotaMemoryprojectQuotaCpuprojectQuotaGpuprojectQuotaMemorysharedVolumeCapacity
0ccdd52b8-db16-46ce-8a06-70343c79e82aprimehub usersphusersphadminNaNNaNNoneNoneNoneNone1.0
1c9aa9754-2805-40ac-8bb2-835aa17ad9f7test_grouptest_group_from_jupyter0.50.0NoneNoneNoneNoneNaN
\n", - "
" - ], - "text/plain": [ - " id displayName \\\n", - "0 ccdd52b8-db16-46ce-8a06-70343c79e82a primehub users \n", - "1 c9aa9754-2805-40ac-8bb2-835aa17ad9f7 test_group \n", - "\n", - " name admins quotaCpu quotaGpu quotaMemory \\\n", - "0 phusers phadmin NaN NaN None \n", - "1 test_group_from_jupyter 0.5 0.0 None \n", - "\n", - " projectQuotaCpu projectQuotaGpu projectQuotaMemory sharedVolumeCapacity \n", - "0 None None None 1.0 \n", - "1 None None None NaN " - ] - }, - "execution_count": 18, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "import pandas as pd\n", - "df_list = pd.DataFrame.from_records(list(ph.admin.groups.list()))\n", - "df_list" - ] - }, - { - "cell_type": "code", - "execution_count": 19, - "id": "4a559ff5", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[{'id': 'ccdd52b8-db16-46ce-8a06-70343c79e82a', 'writable': True},\n", - " {'id': 'c9aa9754-2805-40ac-8bb2-835aa17ad9f7', 'writable': False}]" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "instance_connect = []\n", - "for list_id in list(df_list['id'])[0:2]:\n", - " instance_connect.append({\"id\": list_id, 'writable': False})\n", - "instance_connect[0]['writable'] = True\n", - "instance_connect" - ] - }, - { - "cell_type": "code", - "execution_count": 20, - "id": "d58ec1fd", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'id': 'env-volume'}" - ] - }, - "execution_count": 20, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Update the Volume\n", - "config = {\n", - " \"global\": False,\n", - " \"groups\": {\n", - " \"connect\": instance_connect\n", - " },\n", - "}\n", - "ph.admin.volumes.update(volume[\"id\"], config)" - ] - }, - { - "cell_type": "code", - "execution_count": 21, - "id": "c35937b0", - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'id': 'env-volume',\n", - " 'name': 'env-volume',\n", - " 'displayName': 'env-volume',\n", - " 'description': '',\n", - " 'type': 'env',\n", - " 'variables': {'ENV': 'prod', 'LUCKY_NUMBER': '7'},\n", - " 'global': False,\n", - " 'groups': [{'id': 'ccdd52b8-db16-46ce-8a06-70343c79e82a',\n", - " 'name': 'phusers',\n", - " 'displayName': 'primehub users',\n", - " 'writable': False},\n", - " {'id': 'c9aa9754-2805-40ac-8bb2-835aa17ad9f7',\n", - " 'name': 'test_group_from_jupyter',\n", - " 'displayName': 'test_group',\n", - " 'writable': False}]}" - ] - }, - "execution_count": 21, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "# Get the volume information\n", - "\n", - "ph.admin.volumes.get(volume['id'])" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3", - "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.7.10" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} From 417e606b5f88b28ce0292a2bc07afaac719a3653 Mon Sep 17 00:00:00 2001 From: gblpedia Date: Wed, 12 Apr 2023 11:02:52 +0900 Subject: [PATCH 2/3] added notebooks of use-case --- docs/screenplay/environment setup.ipynb | 209 +++++ docs/screenplay/group-wise-usecase.ipynb | 833 ++++++++++++++++++++ docs/screenplay/image-wise-usecase.ipynb | 424 ++++++++++ docs/screenplay/instance-type-usecase.ipynb | 439 +++++++++++ docs/screenplay/secret-wise-usecase.ipynb | 315 ++++++++ docs/screenplay/user-wise-usecase.ipynb | 470 +++++++++++ docs/screenplay/volume-wise-usercase.ipynb | 506 ++++++++++++ 7 files changed, 3196 insertions(+) create mode 100644 docs/screenplay/environment setup.ipynb create mode 100644 docs/screenplay/group-wise-usecase.ipynb create mode 100644 docs/screenplay/image-wise-usecase.ipynb create mode 100644 docs/screenplay/instance-type-usecase.ipynb create mode 100644 docs/screenplay/secret-wise-usecase.ipynb create mode 100644 docs/screenplay/user-wise-usecase.ipynb create mode 100644 docs/screenplay/volume-wise-usercase.ipynb diff --git a/docs/screenplay/environment setup.ipynb b/docs/screenplay/environment setup.ipynb new file mode 100644 index 0000000..3f889cb --- /dev/null +++ b/docs/screenplay/environment setup.ipynb @@ -0,0 +1,209 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "85ffb1bc", + "metadata": {}, + "source": [ + "# PrimeHub Python SDK Setup\n", + "\n", + "PrimeHub Python SDK allows you to access PrimeHub platform programmically that you can automate workflows and have the integration with the existing infrastructure.\n", + "\n", + "## Prerequisites\n", + "\n", + "Before using this SDK, you need\n", + "\n", + "- PrimeHub user account as the *administrator*\n", + "- installled *primehub-python-sdk*\n", + "- stored `~/.primehub/config.json` file" + ] + }, + { + "cell_type": "markdown", + "id": "becf03df", + "metadata": {}, + "source": [ + "## Set up the environment" + ] + }, + { + "cell_type": "markdown", + "id": "3e3e6f4e", + "metadata": {}, + "source": [ + "### Install the Python SDK package" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "2944a714", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Requirement already satisfied: primehub-python-sdk in /home/jovyan/.local/lib/python3.7/site-packages (0.4.0)\n", + "Requirement already satisfied: types-requests in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (2.28.11.8)\n", + "Requirement already satisfied: requests in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (2.25.1)\n", + "Requirement already satisfied: tabulate==0.8.9 in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (0.8.9)\n", + "Requirement already satisfied: types-tabulate==0.8.2 in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (0.8.2)\n", + "Requirement already satisfied: chardet<5,>=3.0.2 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (4.0.0)\n", + "Requirement already satisfied: idna<3,>=2.5 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (2.10)\n", + "Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (2021.5.30)\n", + "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (1.26.5)\n", + "Requirement already satisfied: types-urllib3<1.27 in /opt/conda/lib/python3.7/site-packages (from types-requests->primehub-python-sdk) (1.26.25.4)\n" + ] + } + ], + "source": [ + "!pip install -U primehub-python-sdk" + ] + }, + { + "cell_type": "markdown", + "id": "546002f4", + "metadata": {}, + "source": [ + "### Initialize the configuration\n", + "\n", + "You will be prompted to login the user account to retrieve the dedicated token which will be stored in the configuration." + ] + }, + { + "cell_type": "markdown", + "id": "132f81ed", + "metadata": {}, + "source": [ + "**Replace the value below with your PrimeHub domain (*http* or *https*).**" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "a682b88b", + "metadata": {}, + "outputs": [], + "source": [ + "PRIMEHUB_CLUSTER = 'https://c.demo.primehub.io/'" + ] + }, + { + "cell_type": "markdown", + "id": "2278ccd7", + "metadata": {}, + "source": [ + "**Check if the configuration exists. If not, you need to login to retrieve the token and input it in the prompt. The configuration will be generated at**`~/.primehub/config.json`." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "c888be97", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "from primehub import PrimeHub, PrimeHubConfig\n", + "\n", + "ph = PrimeHub(PrimeHubConfig())\n", + "if not os.path.isfile(os.path.join(os.getenv(\"HOME\"), \".primehub/config.json\")):\n", + " ph.config.generate(PRIMEHUB_CLUSTER)" + ] + }, + { + "cell_type": "markdown", + "id": "2fbcd13d", + "metadata": {}, + "source": [ + "### Verify the environment" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "413688dd", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PrimeHub Python SDK 0.4.0 environment is ready, you are good to go.\n", + "Current Group: {'id': 'cb32ea66-11b9-419c-8507-f0390392aa84', 'name': 'awesome-team', 'displayName': ''}\n" + ] + } + ], + "source": [ + "ph = PrimeHub(PrimeHubConfig())\n", + "if ph.is_ready():\n", + " print(f\"PrimeHub Python SDK {ph.version.version()} environment is ready, you are good to go.\")\n", + " print(\"Current Group:\", ph.primehub_config.current_group)\n", + "else:\n", + " print(\"Failed to retrieve the information from PrimeHub cluster, please check the configuration.\")" + ] + }, + { + "cell_type": "markdown", + "id": "752fb069", + "metadata": {}, + "source": [ + "**Is the user account an administrator**\n", + "\n", + "By the return of`ph.me.me()`, you can tell if the account is an administrator by the `isAdmin` property." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "325b8666", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'id': 'f27378a4-8952-49b5-8055-94c90725e510', 'username': 'gabriel@infuseai.io', 'firstName': 'Gabriel', 'lastName': 'Lo', 'email': 'gabriel@infuseai.io', 'isAdmin': True}\n" + ] + }, + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "account_information = ph.me.me()\n", + "print(account_information)\n", + "account_information['isAdmin']" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.7.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/screenplay/group-wise-usecase.ipynb b/docs/screenplay/group-wise-usecase.ipynb new file mode 100644 index 0000000..38b4c3f --- /dev/null +++ b/docs/screenplay/group-wise-usecase.ipynb @@ -0,0 +1,833 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "35909a74", + "metadata": {}, + "source": [ + "# Group-wise operation\n", + "\n", + "This notebook demostrates common group-wise operations by using SDK.\n", + "\n", + "## Prerequisites\n", + "\n", + "You need\n", + "\n", + "- an SDK environment set up with the administrator priviledge. Check *environment setup.ipynb* for the detail." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "25134bc1", + "metadata": {}, + "outputs": [], + "source": [ + "PRIMEHUB_CLUSTER = 'your_PrimeHub_domain'" + ] + }, + { + "cell_type": "markdown", + "id": "f5b0da8d", + "metadata": {}, + "source": [ + "**Check if the configuration exists. If not, you need to login to retrieve the token and input it in the prompt. The configuration will be generated at**`~/.primehub/config.json`." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "49114404", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PrimeHub Python SDK 0.4.0 environment is ready, you are good to go.\n", + "Current Group: {'id': 'cb32ea66-11b9-419c-8507-f0390392aa84', 'name': 'awesome-team', 'displayName': ''}\n" + ] + } + ], + "source": [ + "import os\n", + "from primehub import PrimeHub, PrimeHubConfig\n", + "\n", + "ph = PrimeHub(PrimeHubConfig())\n", + "if ph.is_ready():\n", + " print(f\"PrimeHub Python SDK {ph.version.version()} environment is ready, you are good to go.\")\n", + " print(\"Current Group:\", ph.primehub_config.current_group)\n", + "else:\n", + " print(\"Failed to retrieve the information from PrimeHub cluster, please check the configuration.\")" + ] + }, + { + "cell_type": "markdown", + "id": "e4226a6f", + "metadata": {}, + "source": [ + "## ToC\n", + "\n", + "- [Fundamental Operations (CRUD)](#fundamental)\n", + "- [Common Operations](#common)" + ] + }, + { + "cell_type": "markdown", + "id": "f73b9bf1", + "metadata": {}, + "source": [ + "## Fundamental Operations " + ] + }, + { + "cell_type": "markdown", + "id": "824cadbb", + "metadata": {}, + "source": [ + "### Create Group\n", + "\n", + "Method: `ph.admin.groups.create(config)`\n", + "\n", + "By using `create()` with a configuration to :\n", + "- create a group with preset requirements" + ] + }, + { + "cell_type": "markdown", + "id": "837c7702", + "metadata": {}, + "source": [ + "Before creating a user, let's decide which group the user belongs to. Check your PrimeHub and replace the `group_name` with yours." + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "e6e7bcef", + "metadata": {}, + "outputs": [], + "source": [ + "group_name = 'Continental'" + ] + }, + { + "cell_type": "markdown", + "id": "f12c82df", + "metadata": {}, + "source": [ + "Let's prepare the configuration of creating a group, *Continental*, with the preset requirements." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "a0771e53", + "metadata": {}, + "outputs": [], + "source": [ + "# Prepare a group configuration\n", + "config = {\n", + " \"name\": group_name,\n", + " \"displayName\": \"a group of hitman\",\n", + " \"enabledDeployment\": False,\n", + " \"enabledSharedVolume\": False,\n", + " \"quotaCpu\": 4,\n", + " \"quotaGpu\": 4,\n", + " \"admins\": \"\",\n", + " \"users\": {\n", + " \"connect\": []\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "025d72d2", + "metadata": {}, + "outputs": [], + "source": [ + "specified_group = ph.admin.groups.create(config)\n", + "specified_group" + ] + }, + { + "cell_type": "markdown", + "id": "a265d84e", + "metadata": {}, + "source": [ + "### Add/Remove Group Member\n", + "\n", + "Methods\n", + "- `ph.admin.groups.connect_user(group_id, user_id`)\n", + "- `ph.admin.groups.disconnect_user(group_id, user_id)`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2bf974c4", + "metadata": {}, + "outputs": [], + "source": [ + "# Get the user id by the given user name\n", + "user_name = 'john-wick'\n", + "users = ph.admin.users.list()\n", + "for user in users:\n", + " if user['username'] == user_name:\n", + " specified_user = user\n", + "specified_user" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fdd6e470", + "metadata": {}, + "outputs": [], + "source": [ + "# Add group member\n", + "ph.admin.groups.connect_user(specified_group['id'], specified_user['id'])\n", + "\n", + "# verify\n", + "ph.admin.groups.get(specified_group['id'])['users']" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "96331050", + "metadata": {}, + "outputs": [], + "source": [ + "# remove group member\n", + "ph.admin.groups.disconnect_user(specified_group['id'], specified_user['id'])\n", + "\n", + "# verify\n", + "ph.admin.groups.get(specified_group['id'])['users']" + ] + }, + { + "cell_type": "markdown", + "id": "d28f7775", + "metadata": {}, + "source": [ + "### Add/Remove Image\n", + "\n", + "Methods:\n", + "- `ph.admin.groups.connect_image('group_id','image_id')`\n", + "- `ph.admin.groups.disconnect_image('group_id','image_id')`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "854f5cf0", + "metadata": {}, + "outputs": [], + "source": [ + "# Replace the image's id below with yours\n", + "specified_image_id = 'ngc-pytorch-jupyter'\n", + "\n", + "# Connect an image to the group\n", + "ph.admin.groups.connect_image(specified_group['id'], specified_image_id)\n", + "\n", + "# verify\n", + "ph.admin.groups.get(specified_group['id'])['images']" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6d7f76b8", + "metadata": {}, + "outputs": [], + "source": [ + "# Disconnect an image to the group\n", + "ph.admin.groups.disconnect_image(specified_group['id'], specified_image_id)\n", + "\n", + "# verify\n", + "ph.admin.groups.get(specified_group['id'])['images']" + ] + }, + { + "cell_type": "markdown", + "id": "5a981b1c", + "metadata": {}, + "source": [ + "### Add/Remove InstaceType\n", + "\n", + "Methods:\n", + "- `ph.admin.groups.connect_instancetype('group_id','instancetype_id')`\n", + "- `ph.admin.groups.disconnect_instancetype('group_id','instancetype_id')`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "44c9779d", + "metadata": {}, + "outputs": [], + "source": [ + "# Replace the instancetype's id below with yours\n", + "specified_instancetype_id = 'awesome-gpu'\n", + "\n", + "# Connect an image to the group\n", + "ph.admin.groups.connect_instancetype(specified_group['id'], specified_instancetype_id)\n", + "\n", + "# verify\n", + "ph.admin.groups.get(specified_group['id']['instanceTypes']) #instance\"T\"types, \"T\" uppercase." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "705c544e", + "metadata": {}, + "outputs": [], + "source": [ + "# Disconnect an image to the group\n", + "ph.admin.groups.disconnect_instancetype(specified_group['id'], specified_instancetype_id)\n", + "\n", + "# verify\n", + "ph.admin.groups.get(specified_group['id'])['instanceTypes']" + ] + }, + { + "cell_type": "markdown", + "id": "ecdc0645", + "metadata": {}, + "source": [ + "### Add/Remove Volume\n", + "\n", + "Methods:\n", + "- `ph.admin.groups.connect_volume('group_id','volume_id')`\n", + "- `ph.admin.groups.disconnect_volume('group_id','volume_id')`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f716aabb", + "metadata": {}, + "outputs": [], + "source": [ + "# Replace the volume's id below with yours\n", + "specified_volume_id = 'example-dataset'\n", + "\n", + "# Connect a volume to the group\n", + "ph.admin.groups.connect_volume(specified_group['id'], specified_volume_id)\n", + "\n", + "# verify\n", + "ph.admin.groups.get(specified_group['id'])['volumes']" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "64d74809", + "metadata": {}, + "outputs": [], + "source": [ + "# Disconnect an image to the group\n", + "ph.admin.groups.disconnect_volume(specified_group['id'], specified_volume_id)\n", + "\n", + "# verify\n", + "ph.admin.groups.get(specified_group['id'])['volumes']" + ] + }, + { + "cell_type": "markdown", + "id": "e4350741", + "metadata": {}, + "source": [ + "### Create an Image record and connect it to Group\n", + "\n", + "Method `ph.admin.groups.create_image('group_id', image_configuration)`\n", + "\n", + "\n", + "e.g.\n", + "\n", + "```python\n", + "image_config = {\n", + " \"name\": \"base\",\n", + " \"displayName\": \"Base image\",\n", + " \"description\": \"base-notebook with python 3.7\",\n", + " \"type\": \"both\",\n", + " \"url\": \"infuseai/docker-stacks:base-notebook-63fdf50a\",\n", + " \"urlForGpu\": \"infuseai/docker-stacks:base-notebook-63fdf50a-gpu\",\n", + " \"global\": True\n", + "}\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "90fd8495", + "metadata": {}, + "outputs": [], + "source": [ + "image_config = {\n", + " \"name\": \"test-image\",\n", + " \"displayName\": \"test image\",\n", + " \"description\": \"base-notebook with python 3.7\",\n", + " \"type\": \"both\",\n", + " \"url\": \"infuseai/docker-stacks:base-notebook-63fdf50a\",\n", + " \"urlForGpu\": \"infuseai/docker-stacks:base-notebook-63fdf50a-gpu\",\n", + " \"global\": True\n", + "}\n", + "\n", + "ph.admin.groups.create_image(specified_group['id'], image_config)" + ] + }, + { + "cell_type": "markdown", + "id": "3143548d", + "metadata": {}, + "source": [ + "### Create an InstanceType and connect it to Group\n", + "\n", + "Method: `ph.admin.groups.create_instanetype('group_id', instancetype_configuration)`\n", + "\n", + "e.g.\n", + "\n", + "```python\n", + "instancetype_config = {\n", + " \"name\": \"cpu-1\",\n", + " \"displayName\": \"CPU 1\",\n", + " \"description\": \"1 vCPU / 1G Memory\",\n", + " \"cpuLimit\": 1,\n", + " \"memoryLimit\": 1,\n", + " \"gpuLimit\": 0,\n", + " \"global\": True,\n", + " \"tolerations\": {\n", + " \"set\": [\n", + " {\n", + " \"operator\": \"Equal\",\n", + " \"effect\": \"NoSchedule\",\n", + " \"key\": \"nvidia.com/gpu\",\n", + " \"value\": \"v100\"\n", + " }\n", + " ]\n", + " }\n", + "}\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0890ddda", + "metadata": {}, + "outputs": [], + "source": [ + "instancetype_config = {\n", + " \"name\": \"test-cpu-1\",\n", + " \"displayName\": \"Test CPU 1 by SDK\",\n", + " \"description\": \"1 vCPU / 1G Memory\",\n", + " \"cpuLimit\": 1,\n", + " \"memoryLimit\": 1,\n", + " \"gpuLimit\": 0,\n", + " \"global\": True,\n", + " \"tolerations\": {\n", + " \"set\": [\n", + " {\n", + " \"operator\": \"Equal\",\n", + " \"effect\": \"NoSchedule\",\n", + " \"key\": \"nvidia.com/gpu\",\n", + " \"value\": \"v100\"\n", + " }\n", + " ]\n", + " }\n", + "}\n", + "ph.admin.groups.create_instancetype(specified_group['id'], instancetype_config)" + ] + }, + { + "cell_type": "markdown", + "id": "737e96bb", + "metadata": {}, + "source": [ + "### Create a Volume and connect it to Group\n", + "\n", + "Method: `ph.admin.groups.create_volume('group_id', writable_boolean, volume_configuration)`\n", + "\n", + "e.g.\n", + "\n", + "```python\n", + "volume_rec = {\n", + " \"name\": \"test-volume\",\n", + " \"displayName\": \"test volume by SDK\",\n", + " \"description\": \"desc\",\n", + " \"type\": \"pv\",\n", + " \"global\": false,\n", + " \"pvProvisioning\": \"auto\",\n", + " \"volumeSize\": 1\n", + "}\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6d30257d", + "metadata": {}, + "outputs": [], + "source": [ + "volume_config = {\n", + " \"name\": \"test-volume\",\n", + " \"displayName\": \"test volume by SDK\",\n", + " \"description\": \"desc\",\n", + " \"type\": \"pv\",\n", + " \"global\": False,\n", + " \"pvProvisioning\": \"auto\",\n", + " \"volumeSize\": 1\n", + "}\n", + "\n", + "ph.admin.groups.create_volume(specified_group['id'], True, volume_config)" + ] + }, + { + "cell_type": "markdown", + "id": "026d71ba", + "metadata": {}, + "source": [ + "### Update Group\n", + "\n", + "Method `ph.admin.groups.update(user_id, config)`\n", + "\n", + "By using `update()`, we can have a group sophiscated updates at once\n", + "\n", + "Such as these changes as below in one update\n", + "- increase resources quotas\n", + "- enable the deployment feauture\n", + "- assign a user the group admin" + ] + }, + { + "cell_type": "markdown", + "id": "35150ca8", + "metadata": {}, + "source": [ + "Let's remove john-wick from *Continental* and revoke his administration priviledge (*Excommunicado*) in one update." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "10217a31", + "metadata": {}, + "outputs": [], + "source": [ + "group_name = 'Continental'\n", + "# Prepare a group configuration\n", + "updated_config = {\n", + " \"name\": group_name,\n", + " \"enabledDeployment\": True,\n", + " \"quotaCpu\": 8,\n", + " \"quotaGpu\": 8,\n", + " \"admins\": 'john-wick',\n", + " #\"admins\": 'there is no such person'\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d1df2198", + "metadata": {}, + "outputs": [], + "source": [ + "result = ph.admin.groups.update(specified_group['id'], updated_config)\n", + "result" + ] + }, + { + "cell_type": "markdown", + "id": "c1138d40", + "metadata": {}, + "source": [ + "### Get Group Detail Info\n", + "\n", + "Method `ph.admin.groups.get('group_id')`\n", + "\n", + "Get the specified group detail by the group's id." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d5488a45", + "metadata": {}, + "outputs": [], + "source": [ + "# Get the group id by the given group name\n", + "group_name = 'Continental'\n", + "groups = ph.admin.groups.list()\n", + "for group in groups:\n", + " if group['name'] == group_name:\n", + " specified_group = group\n", + " \n", + "ph.admin.groups.get(specified_group['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "71474078", + "metadata": {}, + "source": [ + "### Delete Group\n", + "\n", + "Delete the specified group by the given group's id." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ea8c44b4", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.groups.delete(specified_group['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "4da4cdbb", + "metadata": {}, + "source": [ + "## Common Operations " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3cd123b5", + "metadata": {}, + "outputs": [], + "source": [ + "# Get the specified group detail by the given group name\n", + "group_name = 'Continental'\n", + "#group_name = 'End-to-end-tutorial'\n", + "groups = ph.admin.groups.list()\n", + "for group in groups:\n", + " if group['name'] == group_name:\n", + " specified_group = group\n", + " \n", + "group_detail = ph.admin.groups.get(specified_group['id'])\n", + "group_detail" + ] + }, + { + "cell_type": "markdown", + "id": "711f2b6e", + "metadata": {}, + "source": [ + "### Get group admin users" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "03359fa7", + "metadata": {}, + "outputs": [], + "source": [ + "group_detail['admins']" + ] + }, + { + "cell_type": "markdown", + "id": "ec21ee7f", + "metadata": {}, + "source": [ + "### Get groups with Zero User" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0d69ac29", + "metadata": {}, + "outputs": [], + "source": [ + "groups = ph.admin.groups.list()\n", + "empty_groups = []\n", + "\n", + "for group in groups:\n", + " group_detail = ph.admin.groups.get(group['id'])\n", + " if not group_detail['users']:\n", + " empty_groups.append((group_detail['id'], group_detail['name']))\n", + "empty_groups " + ] + }, + { + "cell_type": "markdown", + "id": "1ff44b06", + "metadata": {}, + "source": [ + "### Get groups with running Deployments" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5207eb54", + "metadata": {}, + "outputs": [], + "source": [ + "groups = ph.admin.groups.list()\n", + "deploymentsUsages = []\n", + "\n", + "for group in groups:\n", + " group_detail = ph.admin.groups.get(group['id'])\n", + " if group_detail['deploymentsUsage']:\n", + " deploymentsUsages.append((group_detail['name'], group_detail['deploymentsUsage']))\n", + "deploymentsUsages" + ] + }, + { + "cell_type": "markdown", + "id": "7162c56b", + "metadata": {}, + "source": [ + "### List groups with current resources usage" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "96a4cfcd", + "metadata": {}, + "outputs": [], + "source": [ + "groups = ph.admin.groups.list()\n", + "resourceStatus_by_group = []\n", + "\n", + "for group in groups:\n", + " group_detail = ph.admin.groups.get(group['id'])\n", + " resourceStatus_by_group.append((group_detail['name'], group_detail['resourceStatus']))\n", + "resourceStatus_by_group" + ] + }, + { + "cell_type": "markdown", + "id": "79d317e8", + "metadata": {}, + "source": [ + "### List connected Images of a group\n", + "\n", + "Method `ph.admin.groups.list_images('group_id')`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "195f3910", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.groups.list_images(group_detail['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "d2880625", + "metadata": {}, + "source": [ + "### List connected InstanceTypes of a group\n", + "\n", + "Method `ph.admin.groups.list_instancetypes('group_id')`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d3e8d57f", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.groups.list_instancetypes(group_detail['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "c06069eb", + "metadata": {}, + "source": [ + "### List connected Volumes of a group\n", + "\n", + "Method `ph.admin.groups.list_volumes('group_id')`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a8cbe228", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.groups.list_volumes(group_detail['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "2fd2f45b", + "metadata": {}, + "source": [ + "### Delete a specified group and Delete its members" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "59b7474b", + "metadata": {}, + "outputs": [], + "source": [ + "group_name = 'Continental'\n", + "groups = ph.admin.groups.list()\n", + "deleting_group = None\n", + "\n", + "for group in groups:\n", + " if group['name'] == group_name:\n", + " deleting_group = group\n", + " print(deleting_group)\n", + "\n", + "if deleting_group:\n", + " members = ph.admin.groups.list_users(deleting_group['id'])\n", + " # Delete members if any\n", + " for member in members:\n", + " if member:\n", + " ph.admin.users.delete(member['id'])\n", + " print(f'Deleted {member[\"username\"]}')\n", + "\n", + " # Finally, delete the group\n", + " ph.admin.groups.delete(deleting_group['id'])" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.7.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/screenplay/image-wise-usecase.ipynb b/docs/screenplay/image-wise-usecase.ipynb new file mode 100644 index 0000000..80c2ddc --- /dev/null +++ b/docs/screenplay/image-wise-usecase.ipynb @@ -0,0 +1,424 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "36cae2b7", + "metadata": {}, + "source": [ + "# Image-wise operation\n", + "\n", + "This notebook demostrates common image-wise operations by using SDK.\n", + "\n", + "## Prerequisites\n", + "\n", + "You need\n", + "\n", + "- an SDK environment set up with the administrator priviledge. Check \"*environment setup.ipynb*\" for the detail." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "60d236db", + "metadata": {}, + "outputs": [], + "source": [ + "PRIMEHUB_CLUSTER = 'your_PrimeHub_domain'" + ] + }, + { + "cell_type": "markdown", + "id": "9f04247f", + "metadata": {}, + "source": [ + "**Check if the configuration exists. If not, you need to login to retrieve the token and input it in the prompt. The configuration will be generated at**`~/.primehub/config.json`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6ae10b12", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "from primehub import PrimeHub, PrimeHubConfig\n", + "\n", + "ph = PrimeHub(PrimeHubConfig())\n", + "if ph.is_ready():\n", + " print(f\"PrimeHub Python SDK {ph.version.version()} environment is ready, you are good to go.\")\n", + " print(\"Current Group:\", ph.primehub_config.current_group)\n", + "else:\n", + " print(\"Failed to retrieve the information from PrimeHub cluster, please check the configuration.\")" + ] + }, + { + "cell_type": "markdown", + "id": "8b5faf57", + "metadata": {}, + "source": [ + "## ToC\n", + "\n", + "- [Fundamental Operations (CRUD)](#fundamental)\n", + "- [Common Operations](#common)" + ] + }, + { + "cell_type": "markdown", + "id": "95b4f332", + "metadata": {}, + "source": [ + "---\n", + "## Fundamental Operations " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4a6eb198", + "metadata": {}, + "outputs": [], + "source": [ + "# Get the group id by the given group name\n", + "group_name = 'Continental'\n", + "groups = ph.admin.groups.list()\n", + "for group in groups:\n", + " if group['name'] == group_name:\n", + " specified_group = group\n", + " \n", + "group_detail = ph.admin.groups.get(specified_group['id'])\n", + "group_detail" + ] + }, + { + "cell_type": "markdown", + "id": "97a6ab99", + "metadata": {}, + "source": [ + "### Add existing Image from Image Registry\n", + "\n", + "Method: `ph.admin.images.create(image_configuration)`\n", + "\n", + "You can opt for adding a *global image* or adding *an image connecting specified groups*." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "10919bc3", + "metadata": {}, + "outputs": [], + "source": [ + "image_config_global = {\n", + " \"name\": \"sdk-test-base-global\",\n", + " \"displayName\": \"Base image by SDK\",\n", + " \"description\": \"base-notebook with python 3.7\",\n", + " \"type\": \"both\",\n", + " \"url\": \"infuseai/docker-stacks:base-notebook-63fdf50a\",\n", + " \"urlForGpu\": \"infuseai/docker-stacks:base-notebook-63fdf50a-gpu\",\n", + " \"global\": True\n", + " #\"useImagePullSecret\": 'secret_id'\n", + "}\n", + "\n", + "\n", + "image_config_with_specified_groups = {\n", + " \"name\": \"sdk-test-base\",\n", + " \"displayName\": \"Base image by SDK with specified groups\",\n", + " \"description\": \"base-notebook with python 3.7\",\n", + " \"type\": \"both\",\n", + " \"url\": \"infuseai/docker-stacks:base-notebook-63fdf50a\",\n", + " \"urlForGpu\": \"infuseai/docker-stacks:base-notebook-63fdf50a-gpu\",\n", + " \"global\": False,\n", + " \"groups\": {\n", + " \"connect\": [\n", + " {\n", + " \"id\": specified_group['id'],\n", + " }\n", + " ]\n", + " },\n", + " #\"useImagePullSecret\": 'secret_id'\n", + "}\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4ca4dced", + "metadata": {}, + "outputs": [], + "source": [ + "created_image = ph.admin.images.create(image_config_with_specified_groups)\n", + "created_image" + ] + }, + { + "cell_type": "markdown", + "id": "1dbfd541", + "metadata": {}, + "source": [ + "### Update Image Configuration\n", + "\n", + "Method: `ph.admin.images.update('image_id', configuration)`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4d356fc6", + "metadata": {}, + "outputs": [], + "source": [ + "updating_config = {\n", + " \"description\": \"Base image created by SDK example\"\n", + "}\n", + "\n", + "ph.admin.images.update(created_image['id'], updating_config)" + ] + }, + { + "cell_type": "markdown", + "id": "c4d1edf8", + "metadata": {}, + "source": [ + "### Get Image Detail Info\n", + "\n", + "Method: `ph.admin.images.get('image_'id)`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "26128604", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.images.get(created_image['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "ae55ab7c", + "metadata": {}, + "source": [ + "### Get connected Groups of Image\n", + "\n", + "Method: `ph.admin.images.list_groups('image_id')`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bd004fc2", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.images.list_groups(created_image['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "99f244d9", + "metadata": {}, + "source": [ + "### List All of Images\n", + "\n", + "Method: `ph.admin.images.list()`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a049da3a", + "metadata": {}, + "outputs": [], + "source": [ + "all_images = ph.admin.images.list()\n", + "for image in all_images:\n", + " print(image)" + ] + }, + { + "cell_type": "markdown", + "id": "10f82534", + "metadata": {}, + "source": [ + "### Delete Image\n", + "\n", + "Method: `ph.admin.images.delete('image_id')`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c39a2eb5", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.images.delete(created_image['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "44c26617", + "metadata": {}, + "source": [ + "---\n", + "\n", + "## Common Operations " + ] + }, + { + "cell_type": "markdown", + "id": "4c66bb12", + "metadata": {}, + "source": [ + "### Connect/Disconnect Image to Group\n", + "\n", + "Method: \n", + "- `ph.admin.images.add_group('image_id', 'group_id')`\n", + "- `ph.admin.images.remove_group('image_id', 'group_id')`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a486e4f2", + "metadata": {}, + "outputs": [], + "source": [ + "image_id = 'bitfusion-tf-cuda11'\n", + "ph.admin.images.add_group(image_id, specified_group['id'])\n", + "\n", + "# Verify\n", + "ph.admin.images.list_groups(image_id)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "67407cbc", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.images.remove_group(image_id, specified_group['id'])\n", + "\n", + "# Verify\n", + "ph.admin.images.list_groups(image_id)" + ] + }, + { + "cell_type": "markdown", + "id": "313b0311", + "metadata": {}, + "source": [ + "### Create ImagePull secret\n", + "\n", + "By using `ph.admin.secrets.create()` to create the pull secret." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "66e620cb", + "metadata": {}, + "outputs": [], + "source": [ + "secret_config = {\n", + " \"name\": \"secret-created-by-sdk\",\n", + " \"type\": \"opaque\",\n", + " \"secret\": \"keep it secret\"\n", + "}\n", + "secret = ph.admin.secrets.create(secret_config)\n", + "secret" + ] + }, + { + "cell_type": "markdown", + "id": "f8211fe0", + "metadata": {}, + "source": [ + "### Add Image by Building a custom image\n", + "\n", + "By using `ph.admin.images.create()` with the image configruation containing `imageSpec` of the custom image." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ee28d5d7", + "metadata": {}, + "outputs": [], + "source": [ + "# Create an custom image\n", + "config = {\n", + " \"name\": \"custom-image-built-by-sdk\",\n", + " \"type\": \"both\",\n", + " \"global\": True,\n", + " \"imageSpec\": {\n", + " \"baseImage\": \"jupyter/base-notebook\",\n", + " \"packages\": {\n", + " \"pip\": [\n", + " \"primehub-python-sdk\"\n", + " ]\n", + " }\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "04701afa", + "metadata": {}, + "outputs": [], + "source": [ + "image_custom = ph.admin.images.create(config)" + ] + }, + { + "cell_type": "markdown", + "id": "94128771", + "metadata": {}, + "source": [ + "We can tell the building status from `jobStatus` by getting the custom image info." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f1132594", + "metadata": {}, + "outputs": [], + "source": [ + "output = ph.admin.images.get(image_custom['id'])\n", + "\n", + "# \"logEndpoint\" will output massive logs of the building job; usually we delete it to avoid a lengthy output \n", + "# unless you need to check.\n", + "del output['logEndpoint']\n", + "\n", + "output" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.7.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/screenplay/instance-type-usecase.ipynb b/docs/screenplay/instance-type-usecase.ipynb new file mode 100644 index 0000000..8b35dc3 --- /dev/null +++ b/docs/screenplay/instance-type-usecase.ipynb @@ -0,0 +1,439 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "1643414d", + "metadata": {}, + "source": [ + "# InstanceTypes-wise operation\n", + "\n", + "This notebook demostrates common instancetypes-wise operations by using SDK.\n", + "\n", + "## Prerequisites\n", + "\n", + "You need\n", + "\n", + "- an SDK environment set up with the administrator priviledge. Check \"*environment setup.ipynb*\" for the detail." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "479fdc41", + "metadata": {}, + "outputs": [], + "source": [ + "PRIMEHUB_CLUSTER = 'your_PrimeHub_domain'" + ] + }, + { + "cell_type": "markdown", + "id": "b1598e5c", + "metadata": {}, + "source": [ + "**Check if the configuration exists. If not, you need to login to retrieve the token and input it in the prompt. The configuration will be generated at**`~/.primehub/config.json`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d8dcaa19", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "from primehub import PrimeHub, PrimeHubConfig\n", + "\n", + "ph = PrimeHub(PrimeHubConfig())\n", + "if ph.is_ready():\n", + " print(f\"PrimeHub Python SDK {ph.version.version()} environment is ready, you are good to go.\")\n", + " print(\"Current Group:\", ph.primehub_config.current_group)\n", + "else:\n", + " print(\"Failed to retrieve the information from PrimeHub cluster, please check the configuration.\")" + ] + }, + { + "cell_type": "markdown", + "id": "93e8e614", + "metadata": {}, + "source": [ + "## ToC\n", + "\n", + "- [Fundamental Operations (CRUD)](#fundamental)\n", + "- [Common Operations](#common)" + ] + }, + { + "cell_type": "markdown", + "id": "a34b9baf", + "metadata": {}, + "source": [ + "---\n", + "## Fundamental Operations " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f73aecf4", + "metadata": {}, + "outputs": [], + "source": [ + "# Get the group id by the given group name\n", + "group_name = 'Continental'\n", + "groups = ph.admin.groups.list()\n", + "for group in groups:\n", + " if group['name'] == group_name:\n", + " specified_group = group\n", + " \n", + "group_detail = ph.admin.groups.get(specified_group['id'])\n", + "group_detail" + ] + }, + { + "cell_type": "markdown", + "id": "086fd137", + "metadata": {}, + "source": [ + "### Create InstanceType\n", + "\n", + "Method: `ph.admin.instancetypes.create(instancetype_configuration)`\n", + "\n", + "You can opt for adding a *global instancetype* or an *instancetype connecting specified groups*." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7690f22b", + "metadata": {}, + "outputs": [], + "source": [ + "instancetype_config_global = {\n", + " \"name\": \"basic-global\",\n", + " \"displayName\": \"Basic-Global by SDK\",\n", + " \"description\": \"1 CPU / 1GB Mem\",\n", + " \"cpuLimit\": 1,\n", + " \"memoryLimit\": 1,\n", + " \"global\": True\n", + "}\n", + "\n", + "instancetype_config_with_specified_groups = {\n", + " \"name\": \"basic-group\",\n", + " \"displayName\": \"Basic-Groups by SDK\",\n", + " \"description\": \"1 CPU / 1GB Mem\",\n", + " \"cpuLimit\": 1,\n", + " \"memoryLimit\": 1,\n", + " \"groups\": {\n", + " \"connect\": [\n", + " {\n", + " \"id\": specified_group['id'],\n", + " }\n", + " ]\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e64cffe2", + "metadata": {}, + "outputs": [], + "source": [ + "instancetype = ph.admin.instancetypes.create(instancetype_config_with_specified_groups)\n", + "instancetype" + ] + }, + { + "cell_type": "markdown", + "id": "3e990e86", + "metadata": {}, + "source": [ + "### Get InstanceType Detail\n", + "\n", + "Method: `ph.admin.instancetypes.get(instancetype_id)`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6376a641", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.instancetypes.get(instancetype['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "d3dbdecd", + "metadata": {}, + "source": [ + "### Update InstanceType Configuration\n", + "\n", + "Method: `ph.admin.instancetypes.update(instancetype_id, config)`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9b97a09c", + "metadata": {}, + "outputs": [], + "source": [ + "updating_config = {\n", + " \"description\": \"4 CPU / 4GB Mem\",\n", + " \"gpuLimit\": 2,\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "219e52de", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.instancetypes.update(instancetype['id'], updating_config)\n", + "\n", + "#Verify\n", + "ph.admin.instancetypes.get(instancetype['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "33a4315f", + "metadata": {}, + "source": [ + "### Get connected Groups of InstanceTypes\n", + "\n", + "Method: `ph.admin.instancetypes.list_groups('instancetype_id')`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "feab0183", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.instancetypes.list_groups(instancetype['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "74a18671", + "metadata": {}, + "source": [ + "### List All of InstaceTypes\n", + "\n", + "Method: `ph.admin.instancetypes.list()`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "82be083c", + "metadata": {}, + "outputs": [], + "source": [ + "all_images = ph.admin.instancetypes.list()\n", + "for image in all_images:\n", + " print(image)" + ] + }, + { + "cell_type": "markdown", + "id": "cd1e2746", + "metadata": {}, + "source": [ + "### Delete InstanceType\n", + "\n", + "Method: `ph.admin.instancetype.delete(instancetype_id)`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4d9c92a0", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.instancetypes.delete(instancetype['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "8582f46c", + "metadata": {}, + "source": [ + "---\n", + "\n", + "## Common Operations " + ] + }, + { + "cell_type": "markdown", + "id": "f4ef9a8f", + "metadata": {}, + "source": [ + "### Connect/Disconnect InstanceType to Group\n", + "\n", + "Method: \n", + "- `ph.admin.instancetypes.add_group('instancetype_id', 'group_id')`\n", + "- `ph.admin.instancetypes.remove_group('instancetype_id', 'group_id')`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8bc274ba", + "metadata": {}, + "outputs": [], + "source": [ + "instancetype_id = 'basic-group'\n", + "\n", + "ph.admin.instancetypes.add_group(instancetype_id, specified_group['id'])\n", + "\n", + "#Verify\n", + "ph.admin.instancetypes.list_groups(instancetype_id)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b24e769b", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.instancetypes.remove_group(instancetype_id, specified_group['id'])\n", + "\n", + "#Verify\n", + "ph.admin.instancetypes.list_groups(instancetype_id)" + ] + }, + { + "cell_type": "markdown", + "id": "082eb225", + "metadata": {}, + "source": [ + "### Add/Remove Toleration on InstanceType" + ] + }, + { + "cell_type": "markdown", + "id": "9c616da8", + "metadata": {}, + "source": [ + "By `ph.admin.instancetypes.update()` you can add a tolerations on the instancetype." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "17a98a60", + "metadata": {}, + "outputs": [], + "source": [ + "# Add\n", + "toleration_config = {\n", + " \"tolerations\": {\n", + " \"set\": [\n", + " {\n", + " \"operator\": \"Equal\",\n", + " \"effect\": \"NoSchedule\",\n", + " \"key\": \"nvidia.com/gpu\",\n", + " \"value\": \"v100\"\n", + " }\n", + " ]\n", + " }\n", + "}\n", + "ph.admin.instancetypes.update(instancetype['id'], toleration_config)\n", + "\n", + "ph.admin.instancetypes.get(instancetype['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "df87f994", + "metadata": {}, + "outputs": [], + "source": [ + "# Remove, update the config with an empty spec []\n", + "toleration_config = {\n", + " \"tolerations\": {\n", + " \"set\": []\n", + " }\n", + "}\n", + "ph.admin.instancetypes.update(instancetype['id'], toleration_config)\n", + "\n", + "ph.admin.instancetypes.get(instancetype['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "e0f450bd", + "metadata": {}, + "source": [ + "### Add/Remove Node Selector on InstanceType\n", + "\n", + "By `ph.admin.instancetypes.update()` you can add a NodeSelector on instancetype." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "32e3f419", + "metadata": {}, + "outputs": [], + "source": [ + "# Add\n", + "nodeselector_config = {\n", + " \"nodeSelector\": {\"zone\": \"staging\"}\n", + "}\n", + "\n", + "ph.admin.instancetypes.update(instancetype['id'], nodeselector_config)\n", + "ph.admin.instancetypes.get(instancetype['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "9e7e5b6c", + "metadata": {}, + "outputs": [], + "source": [ + "# Remove, update the config with None\n", + "nodeselector_config = {\n", + " \"nodeSelector\": None\n", + "}\n", + "\n", + "ph.admin.instancetypes.update(instancetype['id'], nodeselector_config)\n", + "ph.admin.instancetypes.get(instancetype['id'])" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.7.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/screenplay/secret-wise-usecase.ipynb b/docs/screenplay/secret-wise-usecase.ipynb new file mode 100644 index 0000000..643ac46 --- /dev/null +++ b/docs/screenplay/secret-wise-usecase.ipynb @@ -0,0 +1,315 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "0fc6bac7", + "metadata": {}, + "source": [ + "# Secrets-wise operation\n", + "\n", + "This notebook demostrates common volumes-wise operations by using SDK.\n", + "\n", + "## Prerequisites\n", + "\n", + "You need\n", + "\n", + "- an SDK environment set up with the administrator priviledge. Check \"*environment setup.ipynb*\" for the detail." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7b386ea6", + "metadata": {}, + "outputs": [], + "source": [ + "PRIMEHUB_CLUSTER = 'your_PrimeHub_domain'" + ] + }, + { + "cell_type": "markdown", + "id": "ef85b8b5", + "metadata": {}, + "source": [ + "**Check if the configuration exists. If not, you need to login to retrieve the token and input it in the prompt. The configuration will be generated at**`~/.primehub/config.json`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ab2964bb", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "from primehub import PrimeHub, PrimeHubConfig\n", + "\n", + "ph = PrimeHub(PrimeHubConfig())\n", + "if ph.is_ready():\n", + " print(f\"PrimeHub Python SDK {ph.version.version()} environment is ready, you are good to go.\")\n", + " print(\"Current Group:\", ph.primehub_config.current_group)\n", + "else:\n", + " print(\"Failed to retrieve the information from PrimeHub cluster, please check the configuration.\")" + ] + }, + { + "cell_type": "markdown", + "id": "84f178e3", + "metadata": {}, + "source": [ + "## ToC\n", + "\n", + "- [Fundamental Operations (CRUD)](#fundamental)\n", + "- [Common Operations](#common)" + ] + }, + { + "cell_type": "markdown", + "id": "7438a296", + "metadata": {}, + "source": [ + "---\n", + "## Fundamental Operations " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "372199db", + "metadata": {}, + "outputs": [], + "source": [ + "# Get the group id by the given group name\n", + "group_name = 'Continental'\n", + "groups = ph.admin.groups.list()\n", + "for group in groups:\n", + " if group['name'] == group_name:\n", + " specified_group = group\n", + " \n", + "group_detail = ph.admin.groups.get(specified_group['id'])\n", + "group_detail" + ] + }, + { + "cell_type": "markdown", + "id": "f7ceac0c", + "metadata": {}, + "source": [ + "### Create secret\n", + "\n", + "Method: `ph.admin.secrets.create(configuration)`\n", + "\n", + "You can create two types of secret, *opaque* or *kubernetes*." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f4d32165", + "metadata": {}, + "outputs": [], + "source": [ + "gitsync_secret_config = {\n", + " \"name\": \"git-secret\",\n", + " \"displayName\": \"git secret by sdk\",\n", + " \"type\": 'opaque', # Git Sync\n", + " \"secret\": \"a secret for git repository access\"\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bb67a929", + "metadata": {}, + "outputs": [], + "source": [ + "gitsync_secret = ph.admin.secrets.create(gitsync_secret_config)\n", + "\n", + "ph.admin.secrets.get(gitsync_secret[\"id\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ddfe0d17", + "metadata": {}, + "outputs": [], + "source": [ + "image_pull_secret_config = {\n", + " \"name\": \"image-pull-secret\",\n", + " \"displayName\": \"image pull secret by sdk\",\n", + " \"type\": 'kubernetes', # Image Pull\n", + " \"secret\": 'a secret for image-pull',\n", + " \"registryHost\": \"https://gcr.io\" ,\n", + " \"username\": \"username for gcr\",\n", + " \"password\": \"passwrod for gcr\"\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "45014596", + "metadata": {}, + "outputs": [], + "source": [ + "image_pull_secret = ph.admin.secrets.create(image_pull_secret_config)\n", + "ph.admin.secrets.get(image_pull_secret[\"id\"])" + ] + }, + { + "cell_type": "markdown", + "id": "98e43eff", + "metadata": {}, + "source": [ + "### Get secret Detail\n", + "\n", + "Method: `ph.admin.secrets.get(secret_id)`\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "94d2c3f9", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.secrets.get(image_pull_secret['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "4f2f82b7", + "metadata": {}, + "source": [ + "### Update secret Configuration\n", + "\n", + "Method: `ph.admin.secrets.update(configuration)`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "994157ce", + "metadata": {}, + "outputs": [], + "source": [ + "updating_config = {\n", + " \"displayName\": \"git secret updated by sdk\",\n", + " \"secret\": \"the secret has been updated\"\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "87f92dcc", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.secrets.update(gitsync_secret['id'], updating_config)\n", + "\n", + "ph.admin.secrets.get(gitsync_secret['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "4df4c228", + "metadata": {}, + "source": [ + "### List All of secrets\n", + "\n", + "Method: `ph.admin.secrets.list()`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8a51d407", + "metadata": {}, + "outputs": [], + "source": [ + "all_secrets = ph.admin.secrets.list()\n", + "for secret in all_secrets:\n", + " print(secret)" + ] + }, + { + "cell_type": "markdown", + "id": "d2c81fcd", + "metadata": {}, + "source": [ + "### Delete secret\n", + "\n", + "Method: `ph.admin.secrets.delete(secret_id)`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bbf46850", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.secrets.delete(gitsync_secret['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "1a58bbda", + "metadata": {}, + "source": [ + "---\n", + "\n", + "## Common Operations " + ] + }, + { + "cell_type": "markdown", + "id": "02bce8db", + "metadata": {}, + "source": [ + "### List Secrets by Type" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8616e92c", + "metadata": {}, + "outputs": [], + "source": [ + "selected_type = \"kubernetes\"\n", + "all_secrets = ph.admin.secrets.list()\n", + "gitsync_secrets = []\n", + "for secret in all_secrets:\n", + " if secret[\"type\"] == selected_type:\n", + " gitsync_secrets.append(secret)\n", + "\n", + "gitsync_secrets" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.7.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/screenplay/user-wise-usecase.ipynb b/docs/screenplay/user-wise-usecase.ipynb new file mode 100644 index 0000000..36f0fcf --- /dev/null +++ b/docs/screenplay/user-wise-usecase.ipynb @@ -0,0 +1,470 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "18b1dd95", + "metadata": {}, + "source": [ + "# User-wise operation\n", + "\n", + "This notebook demostrates common user-wise operations by using SDK.\n", + "\n", + "## Prerequisites\n", + "\n", + "You need\n", + "\n", + "- an SDK environment set up with the administrator priviledge. Check *environment setup.ipynb* for the detail." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "dbc7ff67", + "metadata": {}, + "outputs": [], + "source": [ + "PRIMEHUB_CLUSTER = 'your_PrimeHub_domain'" + ] + }, + { + "cell_type": "markdown", + "id": "f73a8b10", + "metadata": {}, + "source": [ + "**Check if the configuration exists. If not, you need to login to retrieve the token and input it in the prompt. The configuration will be generated at**`~/.primehub/config.json`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7ebe34d7", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "from primehub import PrimeHub, PrimeHubConfig\n", + "\n", + "ph = PrimeHub(PrimeHubConfig())\n", + "if ph.is_ready():\n", + " print(\"PrimeHub Python SDK environment is ready, you are good to go.\")\n", + " print(\"Current Group:\", ph.primehub_config.current_group)\n", + "else:\n", + " print(\"Failed to get the group information, please check the configuration.\")" + ] + }, + { + "cell_type": "markdown", + "id": "f73aeefb", + "metadata": {}, + "source": [ + "## ToC\n", + "\n", + "- [Fundamental Operations (CRUD)](#fundamental)\n", + "- [Common Operations](#common)" + ] + }, + { + "cell_type": "markdown", + "id": "745eed44", + "metadata": {}, + "source": [ + "## Fundamental Operations " + ] + }, + { + "cell_type": "markdown", + "id": "befa866c", + "metadata": {}, + "source": [ + "### Create user with/without admin role\n", + "\n", + "Method `ph.admin.users.create(config)`\n", + "\n", + "By using `create()` with a configuration to :\n", + "- create the user with the administration priviledge\n", + "- enable user personal volume with the specified 2Gb capacity\n", + "- Assign the user to the specified group" + ] + }, + { + "cell_type": "markdown", + "id": "f7c8e56f", + "metadata": {}, + "source": [ + "Before creating a user, let's decide which group the user belongs to. Check your PrimeHub and replace the `group_name` with yours." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "96e9e8f5", + "metadata": {}, + "outputs": [], + "source": [ + "# Get the group id by the given group name\n", + "group_name = 'Continental'\n", + "groups = ph.admin.groups.list()\n", + "for group in groups:\n", + " if group['name'] == group_name:\n", + " assigned_group = group\n", + "print(assigned_group)" + ] + }, + { + "cell_type": "markdown", + "id": "b58f1a67", + "metadata": {}, + "source": [ + "Let's prepare the configuration of creating a user, jonh-wick, and assign him to the group, continental." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a5aa1c79", + "metadata": {}, + "outputs": [], + "source": [ + "# Prepare a user configuration with admin role\n", + "config = {\n", + " \"username\": \"john-wick\",\n", + " \"groups\": {\n", + " \"connect\": [ # assigned groups\n", + " {\n", + " \"id\": assigned_group['id'] # it takes group id only\n", + " }\n", + " ]\n", + " },\n", + " \"isAdmin\": True, # grant the user administration priviledge\n", + " \"volumeCapacity\": 2 # user personal volume \n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eaa62647", + "metadata": {}, + "outputs": [], + "source": [ + "data = ph.admin.users.create(config)\n", + "data" + ] + }, + { + "cell_type": "markdown", + "id": "457708ed", + "metadata": {}, + "source": [ + "### Get User Info\n", + "\n", + "Get the specified user information by the user's id." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bced30d3", + "metadata": {}, + "outputs": [], + "source": [ + "# Get the user id by the given user name\n", + "user_name = 'john-wick'\n", + "users = ph.admin.users.list()\n", + "for user in users:\n", + " if user['username'] == user_name:\n", + " specified_user = user" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "26fd6060", + "metadata": {}, + "outputs": [], + "source": [ + "# get the user info\n", + "ph.admin.users.get(specified_user['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "438f242b", + "metadata": {}, + "source": [ + "### Assign User One Group\n", + "\n", + "Method `ph.admin.users.add_group(user_id, group_id`)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3da253ee", + "metadata": {}, + "outputs": [], + "source": [ + "# Get the user id by the given user name\n", + "user_name = 'john-wick'\n", + "users = ph.admin.users.list()\n", + "for user in users:\n", + " if user['username'] == user_name:\n", + " specified_user = user\n", + "specified_user" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f5d97dbf", + "metadata": {}, + "outputs": [], + "source": [ + "# add_group(user_id, group_id)\n", + "ph.admin.users.add_group(specified_user['id'], assigned_group['id'])\n", + "\n", + "# verify\n", + "ph.admin.users.list_groups(specified_user['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "b9a2d040", + "metadata": {}, + "source": [ + "### Remove User From One Group\n", + "\n", + "Method `ph.admin.users.remove_group(user_id, group_id)`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b0a615be", + "metadata": {}, + "outputs": [], + "source": [ + "# remove John Wick from Continental\n", + "ph.admin.users.remove_group(specified_user['id'], assigned_group['id'])\n", + "\n", + "# verify\n", + "ph.admin.users.list_groups(specified_user['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "c2ee7e84", + "metadata": {}, + "source": [ + "### Update User\n", + "\n", + "Method `ph.admin.users.update(user_id, config)`\n", + "\n", + "By using `update()`, we can have a user sophiscated updates at once\n", + "\n", + "Such as two changes as below in one update\n", + "- remove the user from the group\n", + "- revoke user's administration prviledge" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aebb2dd2", + "metadata": {}, + "outputs": [], + "source": [ + "# Get the user id by the given user name\n", + "user_name = 'john-wick'\n", + "users = ph.admin.users.list()\n", + "for user in users:\n", + " if user['username'] == user_name:\n", + " specified_user = user\n", + "specified_user" + ] + }, + { + "cell_type": "markdown", + "id": "20329654", + "metadata": {}, + "source": [ + "Let's remove john-wick from *Continental* and revoke his administration priviledge (*Excommunicado*) in one update." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c2006356", + "metadata": {}, + "outputs": [], + "source": [ + "config = {\n", + " \"groups\": {\n", + " \"disconnect\": [ # assigned groups\n", + " {\n", + " \"id\": assigned_group['id']\n", + " }\n", + " ]\n", + " },\n", + " \"isAdmin\": False, # grant the user administration priviledge\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "eb3a5eef", + "metadata": {}, + "outputs": [], + "source": [ + "result = ph.admin.users.update(specified_user['id'], config) # it takes the specified user id only.\n", + "result" + ] + }, + { + "cell_type": "markdown", + "id": "6f9bd2e0", + "metadata": {}, + "source": [ + "### Delete User\n", + "\n", + "Delete the specified user by the user's id." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f797e732", + "metadata": {}, + "outputs": [], + "source": [ + "# Get the user id by the given user name\n", + "user_name = 'john-wick'\n", + "users = ph.admin.users.list()\n", + "for user in users:\n", + " if user['username'] == user_name:\n", + " specified_user = user\n", + "specified_user" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "84dc2299", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.users.delete(specified_user['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "fc7546f7", + "metadata": {}, + "source": [ + "## Common Operations " + ] + }, + { + "cell_type": "markdown", + "id": "84dc831c", + "metadata": {}, + "source": [ + "### Get group list of a specified user" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4baed1dd", + "metadata": {}, + "outputs": [], + "source": [ + "# Get the user id by the given user name\n", + "user_name = 'john-wick'\n", + "users = ph.admin.users.list()\n", + "for user in users:\n", + " if user['username'] == user_name:\n", + " specified_user = user\n", + "specified_user" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "86216fbb", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.users.get(specified_user['id'])['groups']" + ] + }, + { + "cell_type": "markdown", + "id": "8ae68523", + "metadata": {}, + "source": [ + "### Get admin user list" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "56866899", + "metadata": {}, + "outputs": [], + "source": [ + "users = ph.admin.users.list()\n", + "admin_users = []\n", + "for user in users:\n", + " if user['isAdmin']:\n", + " admin_users.append(user)\n", + "admin_users" + ] + }, + { + "cell_type": "markdown", + "id": "15942b40", + "metadata": {}, + "source": [ + "### Get disabled user list" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b6f75543", + "metadata": {}, + "outputs": [], + "source": [ + "users = ph.admin.users.list()\n", + "disabled_users = []\n", + "for user in users:\n", + " if not user['enabled']:\n", + " disabled_users.append(user)\n", + "disabled_users" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.7.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/screenplay/volume-wise-usercase.ipynb b/docs/screenplay/volume-wise-usercase.ipynb new file mode 100644 index 0000000..68ea2ee --- /dev/null +++ b/docs/screenplay/volume-wise-usercase.ipynb @@ -0,0 +1,506 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "e4ca6bfb", + "metadata": {}, + "source": [ + "# Volumes-wise operation\n", + "\n", + "This notebook demostrates common volumes-wise operations by using SDK.\n", + "\n", + "## Prerequisites\n", + "\n", + "You need\n", + "\n", + "- an SDK environment set up with the administrator priviledge. Check \"*environment setup.ipynb*\" for the detail." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7f129ff9", + "metadata": {}, + "outputs": [], + "source": [ + "PRIMEHUB_CLUSTER = 'your_PrimeHub_domain'" + ] + }, + { + "cell_type": "markdown", + "id": "e104ec89", + "metadata": {}, + "source": [ + "**Check if the configuration exists. If not, you need to login to retrieve the token and input it in the prompt. The configuration will be generated at**`~/.primehub/config.json`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8ab5962e", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "from primehub import PrimeHub, PrimeHubConfig\n", + "\n", + "ph = PrimeHub(PrimeHubConfig())\n", + "if ph.is_ready():\n", + " print(f\"PrimeHub Python SDK {ph.version.version()} environment is ready, you are good to go.\")\n", + " print(\"Current Group:\", ph.primehub_config.current_group)\n", + "else:\n", + " print(\"Failed to retrieve the information from PrimeHub cluster, please check the configuration.\")" + ] + }, + { + "cell_type": "markdown", + "id": "c22a0309", + "metadata": {}, + "source": [ + "## ToC\n", + "\n", + "- [Fundamental Operations (CRUD)](#fundamental)\n", + "- [Common Operations](#common)" + ] + }, + { + "cell_type": "markdown", + "id": "0139c568", + "metadata": {}, + "source": [ + "---\n", + "## Fundamental Operations " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ec39a2b0", + "metadata": {}, + "outputs": [], + "source": [ + "# Get the group id by the given group name\n", + "group_name = 'Continental'\n", + "groups = ph.admin.groups.list()\n", + "for group in groups:\n", + " if group['name'] == group_name:\n", + " specified_group = group\n", + " \n", + "group_detail = ph.admin.groups.get(specified_group['id'])\n", + "group_detail" + ] + }, + { + "cell_type": "markdown", + "id": "a8ae6947", + "metadata": {}, + "source": [ + "### Create Volume\n", + "\n", + "Method: `ph.admin.volumes.create(configuration)`" + ] + }, + { + "cell_type": "markdown", + "id": "f193717d", + "metadata": {}, + "source": [ + "### Create Volume of type PV\n", + "\n", + "A volume connecting to a persistent volumne\n", + "\n", + "Yuo can opt for adding a *global volume (read-only)* and/or a *volume connecting specified groups with writable privildege*." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d4e93255", + "metadata": {}, + "outputs": [], + "source": [ + "persistent_volume_config_global = {\n", + " \"name\": \"pv-global-sdk\",\n", + " \"displayName\": \"1GB global persistent volume\",\n", + " \"description\": \"global persistent volume\",\n", + " \"type\": \"pv\",\n", + " \"global\": True,\n", + " \"pvProvisioning\": \"auto\",\n", + " \"volumeSize\": 1,\n", + " \"groups\": {\n", + " \"connect\": [\n", + " {\n", + " \"id\": specified_group['id'],\n", + " \"writable\": True\n", + " }\n", + " ]\n", + " }\n", + "}\n", + "\n", + "persistent_volume_config_with_specified_groups = {\n", + " \"name\": \"pv-groups-sdk\",\n", + " \"displayName\": \"1GB persistent volume\",\n", + " \"description\": \"persistent volume connecting groups\",\n", + " \"type\": \"pv\",\n", + " \"global\": False,\n", + " \"pvProvisioning\": \"auto\",\n", + " \"volumeSize\": 1,\n", + " \"groups\": {\n", + " \"connect\": [\n", + " {\n", + " \"id\": specified_group['id'],\n", + " \"writable\": True\n", + " }\n", + " ]\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "696c9b4d", + "metadata": {}, + "outputs": [], + "source": [ + "persistent_volume = ph.admin.volumes.create(persistent_volume_config_global)\n", + "\n", + "ph.admin.volumes.get(persistent_volume[\"id\"])" + ] + }, + { + "cell_type": "markdown", + "id": "61a2ac7e", + "metadata": {}, + "source": [ + "### Create Volume of type HostPath\n", + "\n", + "A voloume connecting to a local path/directory. It is writable only to specified groups, read-only to others." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8eefd215", + "metadata": {}, + "outputs": [], + "source": [ + "# Create a host path volume with admin role\n", + "hostpath_config = {\n", + " \"name\": \"local-data-volume\",\n", + " \"description\": \"created by sdk\",\n", + " \"type\": \"hostPath\",\n", + " \"global\": True,\n", + " \"hostPath\": \"/opt/data\",\n", + " \"groups\": {\n", + " \"connect\": [\n", + " {\n", + " \"id\": specified_group['id'],\n", + " \"writable\": True\n", + " }\n", + " ]\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "595e3bd5", + "metadata": {}, + "outputs": [], + "source": [ + "hostpath_volume = ph.admin.volumes.create(hostpath_config)\n", + "\n", + "ph.admin.volumes.get(hostpath_volume[\"id\"]) " + ] + }, + { + "cell_type": "markdown", + "id": "5cb83b3c", + "metadata": {}, + "source": [ + "### Create Volume of type Git Sync\n", + "\n", + "A read-only volume connecting to a git repository" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "258f1fbb", + "metadata": {}, + "outputs": [], + "source": [ + "# Create a git sync volume with admin role\n", + "gitsync_volume_config = {\n", + " \"name\": \"covid-19-dataset\",\n", + " \"description\": \"created by sdk\",\n", + " \"type\": \"git\",\n", + " \"global\": False,\n", + " \"url\": \"https://github.com/datasets/covid-19\",\n", + " #\"secret\": \"secred_id\" if required,\n", + " \"groups\": {\n", + " \"connect\": [\n", + " {\n", + " \"id\": specified_group['id'],\n", + " \"writable\": False # must be False\n", + " }\n", + " ]\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a0a34b65", + "metadata": {}, + "outputs": [], + "source": [ + "gitsync_volume = ph.admin.volumes.create(gitsync_volume_config)\n", + "\n", + "ph.admin.volumes.get(gitsync_volume[\"id\"]) " + ] + }, + { + "cell_type": "markdown", + "id": "d54bc2d8", + "metadata": {}, + "source": [ + "### Create Volume of type Env\n", + "A read-only volume containing *environmental variables*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b3f50572", + "metadata": {}, + "outputs": [], + "source": [ + "ev_volume_config = {\n", + " \"name\": \"database-env\",\n", + " \"description\": \"created by sdk\",\n", + " \"type\": \"env\",\n", + " \"global\": False,\n", + " \"variables\": {\n", + " \"PROD_MySQL\": \"The url to the production MySQL database\",\n", + " \"STG_MySQL\": \"The url to the staging MySQL database\"\n", + " },\n", + " \"groups\": {\n", + " \"connect\": [\n", + " {\n", + " \"id\": specified_group['id'],\n", + " \"writable\": False # must be False\n", + " }\n", + " ]\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f3225338", + "metadata": {}, + "outputs": [], + "source": [ + "ev_volume = ph.admin.volumes.create(ev_volume_config)\n", + "\n", + "ph.admin.volumes.get(ev_volume[\"id\"])" + ] + }, + { + "cell_type": "markdown", + "id": "423f5871", + "metadata": {}, + "source": [ + "### Get Volume Detail\n", + "\n", + "Method: `ph.admin.volumes.get(volume_id)`\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d5fbd137", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.volumes.get(persistent_volume['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "28410b31", + "metadata": {}, + "source": [ + "### Update Volume Configuration\n", + "\n", + "Method: `ph.admin.volumes.update(configuration)`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "33e8f82d", + "metadata": {}, + "outputs": [], + "source": [ + "updating_config = {\n", + " \"variables\": {\n", + " \"PROD_MySQL\": \"The url to the production MySQL database\",\n", + " \"STG_MySQL\": \"The url to the staging MySQL database\",\n", + " \"UAT_MySQL\": \"The url to the user acceptance testing MySQL database\"\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "afd00852", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.volumes.update(ev_volume['id'], updading_config)\n", + "\n", + "ph.admin.volumes.get(ev_volume['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "de6b0055", + "metadata": {}, + "source": [ + "### Get connected Groups of Volume\n", + "\n", + "Method: `ph.admin.volumes.list_groups('volume_id')`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8d74456c", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.volumes.list_groups(ev_volume['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "def1c969", + "metadata": {}, + "source": [ + "### List All of Volumes\n", + "\n", + "Method: `ph.admin.volumes.list()`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "57acd89b", + "metadata": {}, + "outputs": [], + "source": [ + "all_volumes = ph.admin.volumes.list()\n", + "for volume in all_volumes:\n", + " print(volume)" + ] + }, + { + "cell_type": "markdown", + "id": "7bf449b5", + "metadata": {}, + "source": [ + "### Delete Volume\n", + "\n", + "Method: `ph.admin.volumes.delete(volume_id)`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fea6bcff", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.volumes.delete(ev_volume['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "be7f5828", + "metadata": {}, + "source": [ + "---\n", + "\n", + "## Common Operations " + ] + }, + { + "cell_type": "markdown", + "id": "7c3e51bd", + "metadata": {}, + "source": [ + "### Connect/Disconnect Volume to Group\n", + "\n", + "Method: \n", + "- `ph.admin.volumes.add_group('volume_id', 'group_id')`\n", + "- `ph.admin.volumes.remove_group('volume_id', 'group_id')`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8b45d871", + "metadata": {}, + "outputs": [], + "source": [ + "volume_id = 'database-env'\n", + "\n", + "ph.admin.volumes.add_group(volume_id, specified_group['id'])\n", + "\n", + "#Verify\n", + "ph.admin.volumes.list_groups(volume_id)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "240e94b4", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.volumes.remove_group(volume_id, specified_group['id'])\n", + "\n", + "#Verify\n", + "ph.admin.volumes.list_groups(volume_id)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.7.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From ec8848ce847005b2c99aea50643b589dee21538c Mon Sep 17 00:00:00 2001 From: gblpedia Date: Fri, 21 Apr 2023 11:12:09 +0900 Subject: [PATCH 3/3] updated usecases according to the changes in sdk 0.4.2 --- docs/{screenplay => usecases}/README.md | 0 .../environment setup.ipynb | 86 +-- .../group-wise-usecase.ipynb | 156 +++--- .../image-wise-usecase.ipynb | 74 +-- .../instance-type-usecase.ipynb | 74 +-- .../secret-wise-usecase.ipynb | 58 +- .../user-wise-usecase.ipynb | 86 +-- docs/usecases/volume-wise-usecase.ipynb | 514 ++++++++++++++++++ .../volume-wise-usercase.ipynb | 0 9 files changed, 774 insertions(+), 274 deletions(-) rename docs/{screenplay => usecases}/README.md (100%) rename docs/{screenplay => usecases}/environment setup.ipynb (56%) rename docs/{screenplay => usecases}/group-wise-usecase.ipynb (90%) rename docs/{screenplay => usecases}/image-wise-usecase.ipynb (90%) rename docs/{screenplay => usecases}/instance-type-usecase.ipynb (91%) rename docs/{screenplay => usecases}/secret-wise-usecase.ipynb (90%) rename docs/{screenplay => usecases}/user-wise-usecase.ipynb (89%) create mode 100644 docs/usecases/volume-wise-usecase.ipynb rename docs/{screenplay => usecases}/volume-wise-usercase.ipynb (100%) diff --git a/docs/screenplay/README.md b/docs/usecases/README.md similarity index 100% rename from docs/screenplay/README.md rename to docs/usecases/README.md diff --git a/docs/screenplay/environment setup.ipynb b/docs/usecases/environment setup.ipynb similarity index 56% rename from docs/screenplay/environment setup.ipynb rename to docs/usecases/environment setup.ipynb index 3f889cb..42b1928 100644 --- a/docs/screenplay/environment setup.ipynb +++ b/docs/usecases/environment setup.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "85ffb1bc", + "id": "bc587508", "metadata": {}, "source": [ "# PrimeHub Python SDK Setup\n", @@ -20,7 +20,7 @@ }, { "cell_type": "markdown", - "id": "becf03df", + "id": "e65022ec", "metadata": {}, "source": [ "## Set up the environment" @@ -28,7 +28,7 @@ }, { "cell_type": "markdown", - "id": "3e3e6f4e", + "id": "db61af40", "metadata": {}, "source": [ "### Install the Python SDK package" @@ -36,34 +36,17 @@ }, { "cell_type": "code", - "execution_count": 5, - "id": "2944a714", + "execution_count": null, + "id": "49f8729a", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Requirement already satisfied: primehub-python-sdk in /home/jovyan/.local/lib/python3.7/site-packages (0.4.0)\n", - "Requirement already satisfied: types-requests in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (2.28.11.8)\n", - "Requirement already satisfied: requests in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (2.25.1)\n", - "Requirement already satisfied: tabulate==0.8.9 in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (0.8.9)\n", - "Requirement already satisfied: types-tabulate==0.8.2 in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (0.8.2)\n", - "Requirement already satisfied: chardet<5,>=3.0.2 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (4.0.0)\n", - "Requirement already satisfied: idna<3,>=2.5 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (2.10)\n", - "Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (2021.5.30)\n", - "Requirement already satisfied: urllib3<1.27,>=1.21.1 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (1.26.5)\n", - "Requirement already satisfied: types-urllib3<1.27 in /opt/conda/lib/python3.7/site-packages (from types-requests->primehub-python-sdk) (1.26.25.4)\n" - ] - } - ], + "outputs": [], "source": [ "!pip install -U primehub-python-sdk" ] }, { "cell_type": "markdown", - "id": "546002f4", + "id": "007c8d7e", "metadata": {}, "source": [ "### Initialize the configuration\n", @@ -73,7 +56,7 @@ }, { "cell_type": "markdown", - "id": "132f81ed", + "id": "f65a7cd8", "metadata": {}, "source": [ "**Replace the value below with your PrimeHub domain (*http* or *https*).**" @@ -81,8 +64,8 @@ }, { "cell_type": "code", - "execution_count": 1, - "id": "a682b88b", + "execution_count": null, + "id": "632296f5", "metadata": {}, "outputs": [], "source": [ @@ -91,7 +74,7 @@ }, { "cell_type": "markdown", - "id": "2278ccd7", + "id": "a68deafb", "metadata": {}, "source": [ "**Check if the configuration exists. If not, you need to login to retrieve the token and input it in the prompt. The configuration will be generated at**`~/.primehub/config.json`." @@ -99,8 +82,8 @@ }, { "cell_type": "code", - "execution_count": 2, - "id": "c888be97", + "execution_count": null, + "id": "b5d398e2", "metadata": {}, "outputs": [], "source": [ @@ -114,7 +97,7 @@ }, { "cell_type": "markdown", - "id": "2fbcd13d", + "id": "3709ddbd", "metadata": {}, "source": [ "### Verify the environment" @@ -122,19 +105,10 @@ }, { "cell_type": "code", - "execution_count": 3, - "id": "413688dd", + "execution_count": null, + "id": "31e0cf90", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "PrimeHub Python SDK 0.4.0 environment is ready, you are good to go.\n", - "Current Group: {'id': 'cb32ea66-11b9-419c-8507-f0390392aa84', 'name': 'awesome-team', 'displayName': ''}\n" - ] - } - ], + "outputs": [], "source": [ "ph = PrimeHub(PrimeHubConfig())\n", "if ph.is_ready():\n", @@ -146,7 +120,7 @@ }, { "cell_type": "markdown", - "id": "752fb069", + "id": "22f43b52", "metadata": {}, "source": [ "**Is the user account an administrator**\n", @@ -156,28 +130,10 @@ }, { "cell_type": "code", - "execution_count": 4, - "id": "325b8666", + "execution_count": null, + "id": "d6bea7c2", "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "{'id': 'f27378a4-8952-49b5-8055-94c90725e510', 'username': 'gabriel@infuseai.io', 'firstName': 'Gabriel', 'lastName': 'Lo', 'email': 'gabriel@infuseai.io', 'isAdmin': True}\n" - ] - }, - { - "data": { - "text/plain": [ - "True" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "account_information = ph.me.me()\n", "print(account_information)\n", diff --git a/docs/screenplay/group-wise-usecase.ipynb b/docs/usecases/group-wise-usecase.ipynb similarity index 90% rename from docs/screenplay/group-wise-usecase.ipynb rename to docs/usecases/group-wise-usecase.ipynb index 38b4c3f..74daee5 100644 --- a/docs/screenplay/group-wise-usecase.ipynb +++ b/docs/usecases/group-wise-usecase.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "35909a74", + "id": "840bcccf", "metadata": {}, "source": [ "# Group-wise operation\n", @@ -16,19 +16,27 @@ "- an SDK environment set up with the administrator priviledge. Check *environment setup.ipynb* for the detail." ] }, + { + "cell_type": "markdown", + "id": "e09680ba", + "metadata": {}, + "source": [ + "**Replace the value below with your PrimeHub domain (*http* or *https*).**" + ] + }, { "cell_type": "code", - "execution_count": 1, - "id": "25134bc1", + "execution_count": null, + "id": "690b6e7f", "metadata": {}, "outputs": [], "source": [ - "PRIMEHUB_CLUSTER = 'your_PrimeHub_domain'" + "PRIMEHUB_CLUSTER = 'https://c.demo.primehub.io'" ] }, { "cell_type": "markdown", - "id": "f5b0da8d", + "id": "cb1e169b", "metadata": {}, "source": [ "**Check if the configuration exists. If not, you need to login to retrieve the token and input it in the prompt. The configuration will be generated at**`~/.primehub/config.json`." @@ -36,19 +44,10 @@ }, { "cell_type": "code", - "execution_count": 2, - "id": "49114404", - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "PrimeHub Python SDK 0.4.0 environment is ready, you are good to go.\n", - "Current Group: {'id': 'cb32ea66-11b9-419c-8507-f0390392aa84', 'name': 'awesome-team', 'displayName': ''}\n" - ] - } - ], + "execution_count": null, + "id": "8de6f73d", + "metadata": {}, + "outputs": [], "source": [ "import os\n", "from primehub import PrimeHub, PrimeHubConfig\n", @@ -63,7 +62,7 @@ }, { "cell_type": "markdown", - "id": "e4226a6f", + "id": "f177c24e", "metadata": {}, "source": [ "## ToC\n", @@ -74,7 +73,7 @@ }, { "cell_type": "markdown", - "id": "f73b9bf1", + "id": "904f3be8", "metadata": {}, "source": [ "## Fundamental Operations " @@ -82,7 +81,7 @@ }, { "cell_type": "markdown", - "id": "824cadbb", + "id": "26eb679b", "metadata": {}, "source": [ "### Create Group\n", @@ -95,7 +94,7 @@ }, { "cell_type": "markdown", - "id": "837c7702", + "id": "36e079d6", "metadata": {}, "source": [ "Before creating a user, let's decide which group the user belongs to. Check your PrimeHub and replace the `group_name` with yours." @@ -103,8 +102,8 @@ }, { "cell_type": "code", - "execution_count": 3, - "id": "e6e7bcef", + "execution_count": null, + "id": "305eb28f", "metadata": {}, "outputs": [], "source": [ @@ -113,7 +112,7 @@ }, { "cell_type": "markdown", - "id": "f12c82df", + "id": "d4ba540d", "metadata": {}, "source": [ "Let's prepare the configuration of creating a group, *Continental*, with the preset requirements." @@ -121,8 +120,8 @@ }, { "cell_type": "code", - "execution_count": 4, - "id": "a0771e53", + "execution_count": null, + "id": "96ffac56", "metadata": {}, "outputs": [], "source": [ @@ -144,7 +143,7 @@ { "cell_type": "code", "execution_count": null, - "id": "025d72d2", + "id": "cff6ee6d", "metadata": {}, "outputs": [], "source": [ @@ -154,7 +153,7 @@ }, { "cell_type": "markdown", - "id": "a265d84e", + "id": "68416589", "metadata": {}, "source": [ "### Add/Remove Group Member\n", @@ -167,7 +166,7 @@ { "cell_type": "code", "execution_count": null, - "id": "2bf974c4", + "id": "0a77502c", "metadata": {}, "outputs": [], "source": [ @@ -183,7 +182,7 @@ { "cell_type": "code", "execution_count": null, - "id": "fdd6e470", + "id": "06706ba0", "metadata": {}, "outputs": [], "source": [ @@ -197,7 +196,7 @@ { "cell_type": "code", "execution_count": null, - "id": "96331050", + "id": "63e539f8", "metadata": {}, "outputs": [], "source": [ @@ -210,7 +209,7 @@ }, { "cell_type": "markdown", - "id": "d28f7775", + "id": "94ce929c", "metadata": {}, "source": [ "### Add/Remove Image\n", @@ -223,7 +222,7 @@ { "cell_type": "code", "execution_count": null, - "id": "854f5cf0", + "id": "8959ca54", "metadata": {}, "outputs": [], "source": [ @@ -240,7 +239,7 @@ { "cell_type": "code", "execution_count": null, - "id": "6d7f76b8", + "id": "255c2de5", "metadata": {}, "outputs": [], "source": [ @@ -253,7 +252,7 @@ }, { "cell_type": "markdown", - "id": "5a981b1c", + "id": "1f124d89", "metadata": {}, "source": [ "### Add/Remove InstaceType\n", @@ -266,7 +265,7 @@ { "cell_type": "code", "execution_count": null, - "id": "44c9779d", + "id": "53d38bf2", "metadata": {}, "outputs": [], "source": [ @@ -283,7 +282,7 @@ { "cell_type": "code", "execution_count": null, - "id": "705c544e", + "id": "1e03e058", "metadata": {}, "outputs": [], "source": [ @@ -296,7 +295,7 @@ }, { "cell_type": "markdown", - "id": "ecdc0645", + "id": "49694697", "metadata": {}, "source": [ "### Add/Remove Volume\n", @@ -309,7 +308,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f716aabb", + "id": "2bcb8e32", "metadata": {}, "outputs": [], "source": [ @@ -326,7 +325,7 @@ { "cell_type": "code", "execution_count": null, - "id": "64d74809", + "id": "4a3df7b8", "metadata": {}, "outputs": [], "source": [ @@ -339,7 +338,7 @@ }, { "cell_type": "markdown", - "id": "e4350741", + "id": "fff5aa9c", "metadata": {}, "source": [ "### Create an Image record and connect it to Group\n", @@ -365,13 +364,13 @@ { "cell_type": "code", "execution_count": null, - "id": "90fd8495", + "id": "db9afc31", "metadata": {}, "outputs": [], "source": [ "image_config = {\n", - " \"name\": \"test-image\",\n", - " \"displayName\": \"test image\",\n", + " \"name\": \"sdk-test-image\",\n", + " \"displayName\": \"sdk test image\",\n", " \"description\": \"base-notebook with python 3.7\",\n", " \"type\": \"both\",\n", " \"url\": \"infuseai/docker-stacks:base-notebook-63fdf50a\",\n", @@ -384,7 +383,7 @@ }, { "cell_type": "markdown", - "id": "3143548d", + "id": "25f294dc", "metadata": {}, "source": [ "### Create an InstanceType and connect it to Group\n", @@ -419,12 +418,12 @@ { "cell_type": "code", "execution_count": null, - "id": "0890ddda", + "id": "61f18ee1", "metadata": {}, "outputs": [], "source": [ "instancetype_config = {\n", - " \"name\": \"test-cpu-1\",\n", + " \"name\": \"sdk-test-cpu-1\",\n", " \"displayName\": \"Test CPU 1 by SDK\",\n", " \"description\": \"1 vCPU / 1G Memory\",\n", " \"cpuLimit\": 1,\n", @@ -447,7 +446,7 @@ }, { "cell_type": "markdown", - "id": "737e96bb", + "id": "6ee58460", "metadata": {}, "source": [ "### Create a Volume and connect it to Group\n", @@ -472,7 +471,7 @@ { "cell_type": "code", "execution_count": null, - "id": "6d30257d", + "id": "920cc8e8", "metadata": {}, "outputs": [], "source": [ @@ -491,7 +490,7 @@ }, { "cell_type": "markdown", - "id": "026d71ba", + "id": "6e5acaf9", "metadata": {}, "source": [ "### Update Group\n", @@ -508,7 +507,7 @@ }, { "cell_type": "markdown", - "id": "35150ca8", + "id": "68f2e759", "metadata": {}, "source": [ "Let's remove john-wick from *Continental* and revoke his administration priviledge (*Excommunicado*) in one update." @@ -517,7 +516,7 @@ { "cell_type": "code", "execution_count": null, - "id": "10217a31", + "id": "a473b6b0", "metadata": {}, "outputs": [], "source": [ @@ -528,15 +527,15 @@ " \"enabledDeployment\": True,\n", " \"quotaCpu\": 8,\n", " \"quotaGpu\": 8,\n", - " \"admins\": 'john-wick',\n", - " #\"admins\": 'there is no such person'\n", + " \"admins\": [specified_user['id']]\n", + "# \"admins\": \"\" #remove all of admins\n", "}" ] }, { "cell_type": "code", "execution_count": null, - "id": "d1df2198", + "id": "e6598105", "metadata": {}, "outputs": [], "source": [ @@ -546,7 +545,7 @@ }, { "cell_type": "markdown", - "id": "c1138d40", + "id": "2ca387ba", "metadata": {}, "source": [ "### Get Group Detail Info\n", @@ -559,7 +558,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d5488a45", + "id": "f4d843c6", "metadata": {}, "outputs": [], "source": [ @@ -575,7 +574,7 @@ }, { "cell_type": "markdown", - "id": "71474078", + "id": "82c88f39", "metadata": {}, "source": [ "### Delete Group\n", @@ -586,7 +585,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ea8c44b4", + "id": "80fb30b1", "metadata": {}, "outputs": [], "source": [ @@ -595,7 +594,7 @@ }, { "cell_type": "markdown", - "id": "4da4cdbb", + "id": "d2e3c9c6", "metadata": {}, "source": [ "## Common Operations " @@ -604,13 +603,12 @@ { "cell_type": "code", "execution_count": null, - "id": "3cd123b5", + "id": "06ce25fa", "metadata": {}, "outputs": [], "source": [ "# Get the specified group detail by the given group name\n", "group_name = 'Continental'\n", - "#group_name = 'End-to-end-tutorial'\n", "groups = ph.admin.groups.list()\n", "for group in groups:\n", " if group['name'] == group_name:\n", @@ -622,7 +620,7 @@ }, { "cell_type": "markdown", - "id": "711f2b6e", + "id": "a788dbbc", "metadata": {}, "source": [ "### Get group admin users" @@ -631,7 +629,7 @@ { "cell_type": "code", "execution_count": null, - "id": "03359fa7", + "id": "6887a53d", "metadata": {}, "outputs": [], "source": [ @@ -640,7 +638,7 @@ }, { "cell_type": "markdown", - "id": "ec21ee7f", + "id": "8d06a047", "metadata": {}, "source": [ "### Get groups with Zero User" @@ -649,7 +647,7 @@ { "cell_type": "code", "execution_count": null, - "id": "0d69ac29", + "id": "74ed9ea4", "metadata": {}, "outputs": [], "source": [ @@ -665,7 +663,7 @@ }, { "cell_type": "markdown", - "id": "1ff44b06", + "id": "507aaf98", "metadata": {}, "source": [ "### Get groups with running Deployments" @@ -674,7 +672,7 @@ { "cell_type": "code", "execution_count": null, - "id": "5207eb54", + "id": "7af2b0fc", "metadata": {}, "outputs": [], "source": [ @@ -690,7 +688,7 @@ }, { "cell_type": "markdown", - "id": "7162c56b", + "id": "9fae7a20", "metadata": {}, "source": [ "### List groups with current resources usage" @@ -699,7 +697,7 @@ { "cell_type": "code", "execution_count": null, - "id": "96a4cfcd", + "id": "c45c69eb", "metadata": {}, "outputs": [], "source": [ @@ -714,7 +712,7 @@ }, { "cell_type": "markdown", - "id": "79d317e8", + "id": "6698de69", "metadata": {}, "source": [ "### List connected Images of a group\n", @@ -725,7 +723,7 @@ { "cell_type": "code", "execution_count": null, - "id": "195f3910", + "id": "f0e20bad", "metadata": {}, "outputs": [], "source": [ @@ -734,7 +732,7 @@ }, { "cell_type": "markdown", - "id": "d2880625", + "id": "04f15c54", "metadata": {}, "source": [ "### List connected InstanceTypes of a group\n", @@ -745,7 +743,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d3e8d57f", + "id": "8ffd0426", "metadata": {}, "outputs": [], "source": [ @@ -754,7 +752,7 @@ }, { "cell_type": "markdown", - "id": "c06069eb", + "id": "f5fedcfa", "metadata": {}, "source": [ "### List connected Volumes of a group\n", @@ -765,7 +763,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a8cbe228", + "id": "544dfcf8", "metadata": {}, "outputs": [], "source": [ @@ -774,7 +772,7 @@ }, { "cell_type": "markdown", - "id": "2fd2f45b", + "id": "862d21c6", "metadata": {}, "source": [ "### Delete a specified group and Delete its members" @@ -783,7 +781,7 @@ { "cell_type": "code", "execution_count": null, - "id": "59b7474b", + "id": "673b580e", "metadata": {}, "outputs": [], "source": [ diff --git a/docs/screenplay/image-wise-usecase.ipynb b/docs/usecases/image-wise-usecase.ipynb similarity index 90% rename from docs/screenplay/image-wise-usecase.ipynb rename to docs/usecases/image-wise-usecase.ipynb index 80c2ddc..b6dd454 100644 --- a/docs/screenplay/image-wise-usecase.ipynb +++ b/docs/usecases/image-wise-usecase.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "36cae2b7", + "id": "9ec29b42", "metadata": {}, "source": [ "# Image-wise operation\n", @@ -16,19 +16,27 @@ "- an SDK environment set up with the administrator priviledge. Check \"*environment setup.ipynb*\" for the detail." ] }, + { + "cell_type": "markdown", + "id": "2420ffdf", + "metadata": {}, + "source": [ + "**Replace the value below with your PrimeHub domain (*http* or *https*).**" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "60d236db", + "id": "d338df8b", "metadata": {}, "outputs": [], "source": [ - "PRIMEHUB_CLUSTER = 'your_PrimeHub_domain'" + "PRIMEHUB_CLUSTER = 'https://c.demo.primehub.io'" ] }, { "cell_type": "markdown", - "id": "9f04247f", + "id": "8e63f6a4", "metadata": {}, "source": [ "**Check if the configuration exists. If not, you need to login to retrieve the token and input it in the prompt. The configuration will be generated at**`~/.primehub/config.json`." @@ -37,7 +45,7 @@ { "cell_type": "code", "execution_count": null, - "id": "6ae10b12", + "id": "70649bdd", "metadata": {}, "outputs": [], "source": [ @@ -54,7 +62,7 @@ }, { "cell_type": "markdown", - "id": "8b5faf57", + "id": "f1644981", "metadata": {}, "source": [ "## ToC\n", @@ -65,7 +73,7 @@ }, { "cell_type": "markdown", - "id": "95b4f332", + "id": "cb657f40", "metadata": {}, "source": [ "---\n", @@ -75,7 +83,7 @@ { "cell_type": "code", "execution_count": null, - "id": "4a6eb198", + "id": "b33e91e9", "metadata": {}, "outputs": [], "source": [ @@ -92,7 +100,7 @@ }, { "cell_type": "markdown", - "id": "97a6ab99", + "id": "0b2bad7a", "metadata": {}, "source": [ "### Add existing Image from Image Registry\n", @@ -105,7 +113,7 @@ { "cell_type": "code", "execution_count": null, - "id": "10919bc3", + "id": "d57e5b59", "metadata": {}, "outputs": [], "source": [ @@ -143,7 +151,7 @@ { "cell_type": "code", "execution_count": null, - "id": "4ca4dced", + "id": "9fd8b282", "metadata": {}, "outputs": [], "source": [ @@ -153,7 +161,7 @@ }, { "cell_type": "markdown", - "id": "1dbfd541", + "id": "24e16147", "metadata": {}, "source": [ "### Update Image Configuration\n", @@ -164,12 +172,12 @@ { "cell_type": "code", "execution_count": null, - "id": "4d356fc6", + "id": "2e496c8e", "metadata": {}, "outputs": [], "source": [ "updating_config = {\n", - " \"description\": \"Base image created by SDK example\"\n", + " \"description\": \"Base image updated by SDK example\"\n", "}\n", "\n", "ph.admin.images.update(created_image['id'], updating_config)" @@ -177,7 +185,7 @@ }, { "cell_type": "markdown", - "id": "c4d1edf8", + "id": "648171d1", "metadata": {}, "source": [ "### Get Image Detail Info\n", @@ -188,7 +196,7 @@ { "cell_type": "code", "execution_count": null, - "id": "26128604", + "id": "9eb4565e", "metadata": {}, "outputs": [], "source": [ @@ -197,7 +205,7 @@ }, { "cell_type": "markdown", - "id": "ae55ab7c", + "id": "5e72c4c9", "metadata": {}, "source": [ "### Get connected Groups of Image\n", @@ -208,7 +216,7 @@ { "cell_type": "code", "execution_count": null, - "id": "bd004fc2", + "id": "0b038a85", "metadata": {}, "outputs": [], "source": [ @@ -217,7 +225,7 @@ }, { "cell_type": "markdown", - "id": "99f244d9", + "id": "b29c50d5", "metadata": {}, "source": [ "### List All of Images\n", @@ -228,7 +236,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a049da3a", + "id": "9a1fad3b", "metadata": {}, "outputs": [], "source": [ @@ -239,7 +247,7 @@ }, { "cell_type": "markdown", - "id": "10f82534", + "id": "061ab63a", "metadata": {}, "source": [ "### Delete Image\n", @@ -250,7 +258,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c39a2eb5", + "id": "79367521", "metadata": {}, "outputs": [], "source": [ @@ -259,7 +267,7 @@ }, { "cell_type": "markdown", - "id": "44c26617", + "id": "c8f700ac", "metadata": {}, "source": [ "---\n", @@ -269,7 +277,7 @@ }, { "cell_type": "markdown", - "id": "4c66bb12", + "id": "cb48c979", "metadata": {}, "source": [ "### Connect/Disconnect Image to Group\n", @@ -282,7 +290,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a486e4f2", + "id": "1510e584", "metadata": {}, "outputs": [], "source": [ @@ -296,7 +304,7 @@ { "cell_type": "code", "execution_count": null, - "id": "67407cbc", + "id": "7759b0b1", "metadata": {}, "outputs": [], "source": [ @@ -308,7 +316,7 @@ }, { "cell_type": "markdown", - "id": "313b0311", + "id": "8dd92f71", "metadata": {}, "source": [ "### Create ImagePull secret\n", @@ -319,7 +327,7 @@ { "cell_type": "code", "execution_count": null, - "id": "66e620cb", + "id": "d11fc3d6", "metadata": {}, "outputs": [], "source": [ @@ -334,7 +342,7 @@ }, { "cell_type": "markdown", - "id": "f8211fe0", + "id": "1448a6bf", "metadata": {}, "source": [ "### Add Image by Building a custom image\n", @@ -345,7 +353,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ee28d5d7", + "id": "3bcfeb05", "metadata": {}, "outputs": [], "source": [ @@ -368,7 +376,7 @@ { "cell_type": "code", "execution_count": null, - "id": "04701afa", + "id": "514882d4", "metadata": {}, "outputs": [], "source": [ @@ -377,7 +385,7 @@ }, { "cell_type": "markdown", - "id": "94128771", + "id": "50a11315", "metadata": {}, "source": [ "We can tell the building status from `jobStatus` by getting the custom image info." @@ -386,7 +394,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f1132594", + "id": "1146e0eb", "metadata": {}, "outputs": [], "source": [ diff --git a/docs/screenplay/instance-type-usecase.ipynb b/docs/usecases/instance-type-usecase.ipynb similarity index 91% rename from docs/screenplay/instance-type-usecase.ipynb rename to docs/usecases/instance-type-usecase.ipynb index 8b35dc3..d6d92b3 100644 --- a/docs/screenplay/instance-type-usecase.ipynb +++ b/docs/usecases/instance-type-usecase.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "1643414d", + "id": "66fcea6e", "metadata": {}, "source": [ "# InstanceTypes-wise operation\n", @@ -16,19 +16,27 @@ "- an SDK environment set up with the administrator priviledge. Check \"*environment setup.ipynb*\" for the detail." ] }, + { + "cell_type": "markdown", + "id": "1cb8ac76", + "metadata": {}, + "source": [ + "**Replace the value below with your PrimeHub domain (*http* or *https*).**" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "479fdc41", + "id": "71e83b36", "metadata": {}, "outputs": [], "source": [ - "PRIMEHUB_CLUSTER = 'your_PrimeHub_domain'" + "PRIMEHUB_CLUSTER = 'https://c.demo.primehub.io'" ] }, { "cell_type": "markdown", - "id": "b1598e5c", + "id": "ceed2d1f", "metadata": {}, "source": [ "**Check if the configuration exists. If not, you need to login to retrieve the token and input it in the prompt. The configuration will be generated at**`~/.primehub/config.json`." @@ -37,7 +45,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d8dcaa19", + "id": "3c3881e6", "metadata": {}, "outputs": [], "source": [ @@ -54,7 +62,7 @@ }, { "cell_type": "markdown", - "id": "93e8e614", + "id": "5784fb94", "metadata": {}, "source": [ "## ToC\n", @@ -65,7 +73,7 @@ }, { "cell_type": "markdown", - "id": "a34b9baf", + "id": "0e0a3309", "metadata": {}, "source": [ "---\n", @@ -75,7 +83,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f73aecf4", + "id": "7a041006", "metadata": {}, "outputs": [], "source": [ @@ -92,7 +100,7 @@ }, { "cell_type": "markdown", - "id": "086fd137", + "id": "b30bc9aa", "metadata": {}, "source": [ "### Create InstanceType\n", @@ -105,7 +113,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7690f22b", + "id": "78a73ff8", "metadata": {}, "outputs": [], "source": [ @@ -137,7 +145,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e64cffe2", + "id": "6aba3193", "metadata": {}, "outputs": [], "source": [ @@ -147,7 +155,7 @@ }, { "cell_type": "markdown", - "id": "3e990e86", + "id": "585743b2", "metadata": {}, "source": [ "### Get InstanceType Detail\n", @@ -158,7 +166,7 @@ { "cell_type": "code", "execution_count": null, - "id": "6376a641", + "id": "2d46df26", "metadata": {}, "outputs": [], "source": [ @@ -167,7 +175,7 @@ }, { "cell_type": "markdown", - "id": "d3dbdecd", + "id": "091b43e9", "metadata": {}, "source": [ "### Update InstanceType Configuration\n", @@ -178,7 +186,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9b97a09c", + "id": "8415ed66", "metadata": {}, "outputs": [], "source": [ @@ -191,7 +199,7 @@ { "cell_type": "code", "execution_count": null, - "id": "219e52de", + "id": "6044d3ff", "metadata": {}, "outputs": [], "source": [ @@ -203,7 +211,7 @@ }, { "cell_type": "markdown", - "id": "33a4315f", + "id": "5619da15", "metadata": {}, "source": [ "### Get connected Groups of InstanceTypes\n", @@ -214,7 +222,7 @@ { "cell_type": "code", "execution_count": null, - "id": "feab0183", + "id": "4897c996", "metadata": {}, "outputs": [], "source": [ @@ -223,7 +231,7 @@ }, { "cell_type": "markdown", - "id": "74a18671", + "id": "8bb8cffe", "metadata": {}, "source": [ "### List All of InstaceTypes\n", @@ -234,7 +242,7 @@ { "cell_type": "code", "execution_count": null, - "id": "82be083c", + "id": "23dffe85", "metadata": {}, "outputs": [], "source": [ @@ -245,7 +253,7 @@ }, { "cell_type": "markdown", - "id": "cd1e2746", + "id": "edcb1771", "metadata": {}, "source": [ "### Delete InstanceType\n", @@ -256,7 +264,7 @@ { "cell_type": "code", "execution_count": null, - "id": "4d9c92a0", + "id": "4d8597b3", "metadata": {}, "outputs": [], "source": [ @@ -265,7 +273,7 @@ }, { "cell_type": "markdown", - "id": "8582f46c", + "id": "84df3fea", "metadata": {}, "source": [ "---\n", @@ -275,7 +283,7 @@ }, { "cell_type": "markdown", - "id": "f4ef9a8f", + "id": "12f9eb47", "metadata": {}, "source": [ "### Connect/Disconnect InstanceType to Group\n", @@ -288,7 +296,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8bc274ba", + "id": "8c243e87", "metadata": {}, "outputs": [], "source": [ @@ -303,7 +311,7 @@ { "cell_type": "code", "execution_count": null, - "id": "b24e769b", + "id": "bab9b645", "metadata": {}, "outputs": [], "source": [ @@ -315,7 +323,7 @@ }, { "cell_type": "markdown", - "id": "082eb225", + "id": "ef7ebcc6", "metadata": {}, "source": [ "### Add/Remove Toleration on InstanceType" @@ -323,7 +331,7 @@ }, { "cell_type": "markdown", - "id": "9c616da8", + "id": "336ab13a", "metadata": {}, "source": [ "By `ph.admin.instancetypes.update()` you can add a tolerations on the instancetype." @@ -332,7 +340,7 @@ { "cell_type": "code", "execution_count": null, - "id": "17a98a60", + "id": "9f164bde", "metadata": {}, "outputs": [], "source": [ @@ -357,7 +365,7 @@ { "cell_type": "code", "execution_count": null, - "id": "df87f994", + "id": "70ae4737", "metadata": {}, "outputs": [], "source": [ @@ -374,7 +382,7 @@ }, { "cell_type": "markdown", - "id": "e0f450bd", + "id": "4e3f86e8", "metadata": {}, "source": [ "### Add/Remove Node Selector on InstanceType\n", @@ -385,7 +393,7 @@ { "cell_type": "code", "execution_count": null, - "id": "32e3f419", + "id": "fd5567bc", "metadata": {}, "outputs": [], "source": [ @@ -401,7 +409,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9e7e5b6c", + "id": "ae4d73a4", "metadata": {}, "outputs": [], "source": [ diff --git a/docs/screenplay/secret-wise-usecase.ipynb b/docs/usecases/secret-wise-usecase.ipynb similarity index 90% rename from docs/screenplay/secret-wise-usecase.ipynb rename to docs/usecases/secret-wise-usecase.ipynb index 643ac46..c5536c0 100644 --- a/docs/screenplay/secret-wise-usecase.ipynb +++ b/docs/usecases/secret-wise-usecase.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "0fc6bac7", + "id": "9813dcab", "metadata": {}, "source": [ "# Secrets-wise operation\n", @@ -16,19 +16,27 @@ "- an SDK environment set up with the administrator priviledge. Check \"*environment setup.ipynb*\" for the detail." ] }, + { + "cell_type": "markdown", + "id": "6ed7b110", + "metadata": {}, + "source": [ + "**Replace the value below with your PrimeHub domain (*http* or *https*).**" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "7b386ea6", + "id": "409bea3a", "metadata": {}, "outputs": [], "source": [ - "PRIMEHUB_CLUSTER = 'your_PrimeHub_domain'" + "PRIMEHUB_CLUSTER = 'https://c.demo.primehub.io'" ] }, { "cell_type": "markdown", - "id": "ef85b8b5", + "id": "ad78b217", "metadata": {}, "source": [ "**Check if the configuration exists. If not, you need to login to retrieve the token and input it in the prompt. The configuration will be generated at**`~/.primehub/config.json`." @@ -37,7 +45,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ab2964bb", + "id": "cfc2bfbd", "metadata": {}, "outputs": [], "source": [ @@ -54,7 +62,7 @@ }, { "cell_type": "markdown", - "id": "84f178e3", + "id": "b0084886", "metadata": {}, "source": [ "## ToC\n", @@ -65,7 +73,7 @@ }, { "cell_type": "markdown", - "id": "7438a296", + "id": "63f5672c", "metadata": {}, "source": [ "---\n", @@ -75,7 +83,7 @@ { "cell_type": "code", "execution_count": null, - "id": "372199db", + "id": "9f9948aa", "metadata": {}, "outputs": [], "source": [ @@ -92,7 +100,7 @@ }, { "cell_type": "markdown", - "id": "f7ceac0c", + "id": "b5c6fa9a", "metadata": {}, "source": [ "### Create secret\n", @@ -105,7 +113,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f4d32165", + "id": "19022d68", "metadata": {}, "outputs": [], "source": [ @@ -120,7 +128,7 @@ { "cell_type": "code", "execution_count": null, - "id": "bb67a929", + "id": "33a875a2", "metadata": {}, "outputs": [], "source": [ @@ -132,7 +140,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ddfe0d17", + "id": "674fbc76", "metadata": {}, "outputs": [], "source": [ @@ -150,7 +158,7 @@ { "cell_type": "code", "execution_count": null, - "id": "45014596", + "id": "43383aae", "metadata": {}, "outputs": [], "source": [ @@ -160,7 +168,7 @@ }, { "cell_type": "markdown", - "id": "98e43eff", + "id": "1c60fb92", "metadata": {}, "source": [ "### Get secret Detail\n", @@ -171,7 +179,7 @@ { "cell_type": "code", "execution_count": null, - "id": "94d2c3f9", + "id": "184b002a", "metadata": {}, "outputs": [], "source": [ @@ -180,7 +188,7 @@ }, { "cell_type": "markdown", - "id": "4f2f82b7", + "id": "5b44ad00", "metadata": {}, "source": [ "### Update secret Configuration\n", @@ -191,7 +199,7 @@ { "cell_type": "code", "execution_count": null, - "id": "994157ce", + "id": "eb7287c3", "metadata": {}, "outputs": [], "source": [ @@ -204,7 +212,7 @@ { "cell_type": "code", "execution_count": null, - "id": "87f92dcc", + "id": "d08d8140", "metadata": {}, "outputs": [], "source": [ @@ -215,7 +223,7 @@ }, { "cell_type": "markdown", - "id": "4df4c228", + "id": "b9fa2a5c", "metadata": {}, "source": [ "### List All of secrets\n", @@ -226,7 +234,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8a51d407", + "id": "decc4aae", "metadata": {}, "outputs": [], "source": [ @@ -237,7 +245,7 @@ }, { "cell_type": "markdown", - "id": "d2c81fcd", + "id": "d1b11371", "metadata": {}, "source": [ "### Delete secret\n", @@ -248,7 +256,7 @@ { "cell_type": "code", "execution_count": null, - "id": "bbf46850", + "id": "1053c878", "metadata": {}, "outputs": [], "source": [ @@ -257,7 +265,7 @@ }, { "cell_type": "markdown", - "id": "1a58bbda", + "id": "7505a9d2", "metadata": {}, "source": [ "---\n", @@ -267,7 +275,7 @@ }, { "cell_type": "markdown", - "id": "02bce8db", + "id": "971655d7", "metadata": {}, "source": [ "### List Secrets by Type" @@ -276,7 +284,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8616e92c", + "id": "ffdff894", "metadata": {}, "outputs": [], "source": [ diff --git a/docs/screenplay/user-wise-usecase.ipynb b/docs/usecases/user-wise-usecase.ipynb similarity index 89% rename from docs/screenplay/user-wise-usecase.ipynb rename to docs/usecases/user-wise-usecase.ipynb index 36f0fcf..95c6338 100644 --- a/docs/screenplay/user-wise-usecase.ipynb +++ b/docs/usecases/user-wise-usecase.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "18b1dd95", + "id": "4cd0fc56", "metadata": {}, "source": [ "# User-wise operation\n", @@ -16,19 +16,27 @@ "- an SDK environment set up with the administrator priviledge. Check *environment setup.ipynb* for the detail." ] }, + { + "cell_type": "markdown", + "id": "0239be15", + "metadata": {}, + "source": [ + "**Replace the value below with your PrimeHub domain (*http* or *https*).**" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "dbc7ff67", + "id": "d8d74181", "metadata": {}, "outputs": [], "source": [ - "PRIMEHUB_CLUSTER = 'your_PrimeHub_domain'" + "PRIMEHUB_CLUSTER = 'https://c.demo.primehub.io'" ] }, { "cell_type": "markdown", - "id": "f73a8b10", + "id": "d4e66361", "metadata": {}, "source": [ "**Check if the configuration exists. If not, you need to login to retrieve the token and input it in the prompt. The configuration will be generated at**`~/.primehub/config.json`." @@ -37,7 +45,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7ebe34d7", + "id": "aecc5e6d", "metadata": {}, "outputs": [], "source": [ @@ -46,15 +54,15 @@ "\n", "ph = PrimeHub(PrimeHubConfig())\n", "if ph.is_ready():\n", - " print(\"PrimeHub Python SDK environment is ready, you are good to go.\")\n", + " print(f\"PrimeHub Python SDK {ph.version.version()} environment is ready, you are good to go.\")\n", " print(\"Current Group:\", ph.primehub_config.current_group)\n", "else:\n", - " print(\"Failed to get the group information, please check the configuration.\")" + " print(\"Failed to retrieve the information from PrimeHub cluster, please check the configuration.\")" ] }, { "cell_type": "markdown", - "id": "f73aeefb", + "id": "adb34dc5", "metadata": {}, "source": [ "## ToC\n", @@ -65,7 +73,7 @@ }, { "cell_type": "markdown", - "id": "745eed44", + "id": "b322fc83", "metadata": {}, "source": [ "## Fundamental Operations " @@ -73,7 +81,7 @@ }, { "cell_type": "markdown", - "id": "befa866c", + "id": "2086675b", "metadata": {}, "source": [ "### Create user with/without admin role\n", @@ -88,7 +96,7 @@ }, { "cell_type": "markdown", - "id": "f7c8e56f", + "id": "573dc491", "metadata": {}, "source": [ "Before creating a user, let's decide which group the user belongs to. Check your PrimeHub and replace the `group_name` with yours." @@ -97,7 +105,7 @@ { "cell_type": "code", "execution_count": null, - "id": "96e9e8f5", + "id": "55643992", "metadata": {}, "outputs": [], "source": [ @@ -112,7 +120,7 @@ }, { "cell_type": "markdown", - "id": "b58f1a67", + "id": "5d211203", "metadata": {}, "source": [ "Let's prepare the configuration of creating a user, jonh-wick, and assign him to the group, continental." @@ -121,7 +129,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a5aa1c79", + "id": "87ea9469", "metadata": {}, "outputs": [], "source": [ @@ -143,7 +151,7 @@ { "cell_type": "code", "execution_count": null, - "id": "eaa62647", + "id": "b12d3db0", "metadata": {}, "outputs": [], "source": [ @@ -153,7 +161,7 @@ }, { "cell_type": "markdown", - "id": "457708ed", + "id": "3a6e1e85", "metadata": {}, "source": [ "### Get User Info\n", @@ -164,7 +172,7 @@ { "cell_type": "code", "execution_count": null, - "id": "bced30d3", + "id": "afea82c7", "metadata": {}, "outputs": [], "source": [ @@ -179,7 +187,7 @@ { "cell_type": "code", "execution_count": null, - "id": "26fd6060", + "id": "c15d9017", "metadata": {}, "outputs": [], "source": [ @@ -189,7 +197,7 @@ }, { "cell_type": "markdown", - "id": "438f242b", + "id": "922c3b72", "metadata": {}, "source": [ "### Assign User One Group\n", @@ -200,7 +208,7 @@ { "cell_type": "code", "execution_count": null, - "id": "3da253ee", + "id": "643aba64", "metadata": {}, "outputs": [], "source": [ @@ -216,7 +224,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f5d97dbf", + "id": "73e3720c", "metadata": {}, "outputs": [], "source": [ @@ -229,7 +237,7 @@ }, { "cell_type": "markdown", - "id": "b9a2d040", + "id": "a489bde0", "metadata": {}, "source": [ "### Remove User From One Group\n", @@ -240,7 +248,7 @@ { "cell_type": "code", "execution_count": null, - "id": "b0a615be", + "id": "ed39d164", "metadata": {}, "outputs": [], "source": [ @@ -253,7 +261,7 @@ }, { "cell_type": "markdown", - "id": "c2ee7e84", + "id": "b56c150d", "metadata": {}, "source": [ "### Update User\n", @@ -270,7 +278,7 @@ { "cell_type": "code", "execution_count": null, - "id": "aebb2dd2", + "id": "e35c3e4c", "metadata": {}, "outputs": [], "source": [ @@ -285,7 +293,7 @@ }, { "cell_type": "markdown", - "id": "20329654", + "id": "e9f8ddce", "metadata": {}, "source": [ "Let's remove john-wick from *Continental* and revoke his administration priviledge (*Excommunicado*) in one update." @@ -294,7 +302,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c2006356", + "id": "2d89cb35", "metadata": {}, "outputs": [], "source": [ @@ -313,7 +321,7 @@ { "cell_type": "code", "execution_count": null, - "id": "eb3a5eef", + "id": "349a1b83", "metadata": {}, "outputs": [], "source": [ @@ -323,7 +331,7 @@ }, { "cell_type": "markdown", - "id": "6f9bd2e0", + "id": "b978b8ee", "metadata": {}, "source": [ "### Delete User\n", @@ -334,7 +342,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f797e732", + "id": "be2e456f", "metadata": {}, "outputs": [], "source": [ @@ -350,7 +358,7 @@ { "cell_type": "code", "execution_count": null, - "id": "84dc2299", + "id": "f807f8a9", "metadata": {}, "outputs": [], "source": [ @@ -359,7 +367,7 @@ }, { "cell_type": "markdown", - "id": "fc7546f7", + "id": "0962247c", "metadata": {}, "source": [ "## Common Operations " @@ -367,7 +375,7 @@ }, { "cell_type": "markdown", - "id": "84dc831c", + "id": "5a12e3d2", "metadata": {}, "source": [ "### Get group list of a specified user" @@ -376,7 +384,7 @@ { "cell_type": "code", "execution_count": null, - "id": "4baed1dd", + "id": "bb9f6cb9", "metadata": {}, "outputs": [], "source": [ @@ -392,7 +400,7 @@ { "cell_type": "code", "execution_count": null, - "id": "86216fbb", + "id": "39a3102b", "metadata": {}, "outputs": [], "source": [ @@ -401,7 +409,7 @@ }, { "cell_type": "markdown", - "id": "8ae68523", + "id": "c65d97c0", "metadata": {}, "source": [ "### Get admin user list" @@ -410,7 +418,7 @@ { "cell_type": "code", "execution_count": null, - "id": "56866899", + "id": "89fb6547", "metadata": {}, "outputs": [], "source": [ @@ -424,7 +432,7 @@ }, { "cell_type": "markdown", - "id": "15942b40", + "id": "d3ec18ed", "metadata": {}, "source": [ "### Get disabled user list" @@ -433,7 +441,7 @@ { "cell_type": "code", "execution_count": null, - "id": "b6f75543", + "id": "59756b53", "metadata": {}, "outputs": [], "source": [ diff --git a/docs/usecases/volume-wise-usecase.ipynb b/docs/usecases/volume-wise-usecase.ipynb new file mode 100644 index 0000000..0af5b23 --- /dev/null +++ b/docs/usecases/volume-wise-usecase.ipynb @@ -0,0 +1,514 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "635d2ba8", + "metadata": {}, + "source": [ + "# Volumes-wise operation\n", + "\n", + "This notebook demostrates common volumes-wise operations by using SDK.\n", + "\n", + "## Prerequisites\n", + "\n", + "You need\n", + "\n", + "- an SDK environment set up with the administrator priviledge. Check \"*environment setup.ipynb*\" for the detail." + ] + }, + { + "cell_type": "markdown", + "id": "75d70d54", + "metadata": {}, + "source": [ + "**Replace the value below with your PrimeHub domain (*http* or *https*).**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "260f61cc", + "metadata": {}, + "outputs": [], + "source": [ + "PRIMEHUB_CLUSTER = 'https://c.demo.primehub.io'" + ] + }, + { + "cell_type": "markdown", + "id": "317264ca", + "metadata": {}, + "source": [ + "**Check if the configuration exists. If not, you need to login to retrieve the token and input it in the prompt. The configuration will be generated at**`~/.primehub/config.json`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1d1004d1", + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", + "from primehub import PrimeHub, PrimeHubConfig\n", + "\n", + "ph = PrimeHub(PrimeHubConfig())\n", + "if ph.is_ready():\n", + " print(f\"PrimeHub Python SDK {ph.version.version()} environment is ready, you are good to go.\")\n", + " print(\"Current Group:\", ph.primehub_config.current_group)\n", + "else:\n", + " print(\"Failed to retrieve the information from PrimeHub cluster, please check the configuration.\")" + ] + }, + { + "cell_type": "markdown", + "id": "7ad61b5a", + "metadata": {}, + "source": [ + "## ToC\n", + "\n", + "- [Fundamental Operations (CRUD)](#fundamental)\n", + "- [Common Operations](#common)" + ] + }, + { + "cell_type": "markdown", + "id": "1d069318", + "metadata": {}, + "source": [ + "---\n", + "## Fundamental Operations " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3d18d957", + "metadata": {}, + "outputs": [], + "source": [ + "# Get the group id by the given group name\n", + "group_name = 'Continental'\n", + "groups = ph.admin.groups.list()\n", + "for group in groups:\n", + " if group['name'] == group_name:\n", + " specified_group = group\n", + " \n", + "group_detail = ph.admin.groups.get(specified_group['id'])\n", + "group_detail" + ] + }, + { + "cell_type": "markdown", + "id": "b61dd13b", + "metadata": {}, + "source": [ + "### Create Volume\n", + "\n", + "Method: `ph.admin.volumes.create(configuration)`" + ] + }, + { + "cell_type": "markdown", + "id": "deb723b2", + "metadata": {}, + "source": [ + "### Create Volume of type PV\n", + "\n", + "A volume connecting to a persistent volumne\n", + "\n", + "Yuo can opt for adding a *global volume (read-only)* and/or a *volume connecting specified groups with writable privildege*." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c671bcce", + "metadata": {}, + "outputs": [], + "source": [ + "persistent_volume_config_global = {\n", + " \"name\": \"pv-global-sdk\",\n", + " \"displayName\": \"1GB global persistent volume\",\n", + " \"description\": \"global persistent volume\",\n", + " \"type\": \"pv\",\n", + " \"global\": True,\n", + " \"pvProvisioning\": \"auto\",\n", + " \"volumeSize\": 1,\n", + " \"groups\": {\n", + " \"connect\": [\n", + " {\n", + " \"id\": specified_group['id'],\n", + " \"writable\": True\n", + " }\n", + " ]\n", + " }\n", + "}\n", + "\n", + "persistent_volume_config_with_specified_groups = {\n", + " \"name\": \"pv-groups-sdk\",\n", + " \"displayName\": \"1GB persistent volume\",\n", + " \"description\": \"persistent volume connecting groups\",\n", + " \"type\": \"pv\",\n", + " \"global\": False,\n", + " \"pvProvisioning\": \"auto\",\n", + " \"volumeSize\": 1,\n", + " \"groups\": {\n", + " \"connect\": [\n", + " {\n", + " \"id\": specified_group['id'],\n", + " \"writable\": True\n", + " }\n", + " ]\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8d9538ae", + "metadata": {}, + "outputs": [], + "source": [ + "persistent_volume = ph.admin.volumes.create(persistent_volume_config_global)\n", + "\n", + "ph.admin.volumes.get(persistent_volume[\"id\"])" + ] + }, + { + "cell_type": "markdown", + "id": "db5c49dc", + "metadata": {}, + "source": [ + "### Create Volume of type HostPath\n", + "\n", + "A voloume connecting to a local path/directory. It is writable only to specified groups, read-only to others." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "218ef32b", + "metadata": {}, + "outputs": [], + "source": [ + "# Create a host path volume with admin role\n", + "hostpath_config = {\n", + " \"name\": \"local-data-volume\",\n", + " \"description\": \"created by sdk\",\n", + " \"type\": \"hostPath\",\n", + " \"global\": True,\n", + " \"hostPath\": \"/opt/data\",\n", + " \"groups\": {\n", + " \"connect\": [\n", + " {\n", + " \"id\": specified_group['id'],\n", + " \"writable\": True\n", + " }\n", + " ]\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4f851c0d", + "metadata": {}, + "outputs": [], + "source": [ + "hostpath_volume = ph.admin.volumes.create(hostpath_config)\n", + "\n", + "ph.admin.volumes.get(hostpath_volume[\"id\"]) " + ] + }, + { + "cell_type": "markdown", + "id": "e02f8047", + "metadata": {}, + "source": [ + "### Create Volume of type Git Sync\n", + "\n", + "A read-only volume connecting to a git repository" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "63d11e39", + "metadata": {}, + "outputs": [], + "source": [ + "# Create a git sync volume with admin role\n", + "gitsync_volume_config = {\n", + " \"name\": \"covid-19-dataset\",\n", + " \"description\": \"created by sdk\",\n", + " \"type\": \"git\",\n", + " \"global\": False,\n", + " \"url\": \"https://github.com/datasets/covid-19\",\n", + " #\"secret\": \"secred_id\" if required,\n", + " \"groups\": {\n", + " \"connect\": [\n", + " {\n", + " \"id\": specified_group['id'],\n", + " \"writable\": False # must be False\n", + " }\n", + " ]\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "359154e1", + "metadata": {}, + "outputs": [], + "source": [ + "gitsync_volume = ph.admin.volumes.create(gitsync_volume_config)\n", + "\n", + "ph.admin.volumes.get(gitsync_volume[\"id\"]) " + ] + }, + { + "cell_type": "markdown", + "id": "63a668b4", + "metadata": {}, + "source": [ + "### Create Volume of type Env\n", + "A read-only volume containing *environmental variables*" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "5d298043", + "metadata": {}, + "outputs": [], + "source": [ + "ev_volume_config = {\n", + " \"name\": \"database-env\",\n", + " \"description\": \"created by sdk\",\n", + " \"type\": \"env\",\n", + " \"global\": False,\n", + " \"variables\": {\n", + " \"PROD_MySQL\": \"The url to the production MySQL database\",\n", + " \"STG_MySQL\": \"The url to the staging MySQL database\"\n", + " },\n", + " \"groups\": {\n", + " \"connect\": [\n", + " {\n", + " \"id\": specified_group['id'],\n", + " \"writable\": False # must be False\n", + " }\n", + " ]\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b68fa5e9", + "metadata": {}, + "outputs": [], + "source": [ + "ev_volume = ph.admin.volumes.create(ev_volume_config)\n", + "\n", + "ph.admin.volumes.get(ev_volume[\"id\"])" + ] + }, + { + "cell_type": "markdown", + "id": "79f0a1db", + "metadata": {}, + "source": [ + "### Get Volume Detail\n", + "\n", + "Method: `ph.admin.volumes.get(volume_id)`\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "93cf90eb", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.volumes.get(persistent_volume['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "00781a02", + "metadata": {}, + "source": [ + "### Update Volume Configuration\n", + "\n", + "Method: `ph.admin.volumes.update(configuration)`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "78669ff2", + "metadata": {}, + "outputs": [], + "source": [ + "updating_config = {\n", + " \"variables\": {\n", + " \"PROD_MySQL\": \"The url to the production MySQL database\",\n", + " \"STG_MySQL\": \"The url to the staging MySQL database\",\n", + " \"UAT_MySQL\": \"The url to the user acceptance testing MySQL database\"\n", + " }\n", + "}" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bf86299a", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.volumes.update(ev_volume['id'], updading_config)\n", + "\n", + "ph.admin.volumes.get(ev_volume['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "f98625ae", + "metadata": {}, + "source": [ + "### Get connected Groups of Volume\n", + "\n", + "Method: `ph.admin.volumes.list_groups('volume_id')`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4b90e972", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.volumes.list_groups(ev_volume['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "0427a25b", + "metadata": {}, + "source": [ + "### List All of Volumes\n", + "\n", + "Method: `ph.admin.volumes.list()`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4d565217", + "metadata": {}, + "outputs": [], + "source": [ + "all_volumes = ph.admin.volumes.list()\n", + "for volume in all_volumes:\n", + " print(volume)" + ] + }, + { + "cell_type": "markdown", + "id": "ebff7399", + "metadata": {}, + "source": [ + "### Delete Volume\n", + "\n", + "Method: `ph.admin.volumes.delete(volume_id)`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "97768503", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.volumes.delete(ev_volume['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "06f0023a", + "metadata": {}, + "source": [ + "---\n", + "\n", + "## Common Operations " + ] + }, + { + "cell_type": "markdown", + "id": "ff4aa30a", + "metadata": {}, + "source": [ + "### Connect/Disconnect Volume to Group\n", + "\n", + "Method: \n", + "- `ph.admin.volumes.add_group('volume_id', 'group_id')`\n", + "- `ph.admin.volumes.remove_group('volume_id', 'group_id')`" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "344121d0", + "metadata": {}, + "outputs": [], + "source": [ + "volume_id = 'database-env'\n", + "\n", + "ph.admin.volumes.add_group(volume_id, specified_group['id'])\n", + "\n", + "#Verify\n", + "ph.admin.volumes.list_groups(volume_id)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a23b45b0", + "metadata": {}, + "outputs": [], + "source": [ + "ph.admin.volumes.remove_group(volume_id, specified_group['id'])\n", + "\n", + "#Verify\n", + "ph.admin.volumes.list_groups(volume_id)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "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.7.10" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/screenplay/volume-wise-usercase.ipynb b/docs/usecases/volume-wise-usercase.ipynb similarity index 100% rename from docs/screenplay/volume-wise-usercase.ipynb rename to docs/usecases/volume-wise-usercase.ipynb