diff --git a/docs/screenplay/README.md b/docs/screenplay/README.md
deleted file mode 100644
index 7598314..0000000
--- a/docs/screenplay/README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-# PrimeHub Python SDK screenplay
-
-PrimeHub Python SDK screenplay is a set of Juypter notebooks for user to test PrimeHub SDK function.
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",
- " id | \n",
- " displayName | \n",
- " name | \n",
- " admins | \n",
- " quotaCpu | \n",
- " quotaGpu | \n",
- " quotaMemory | \n",
- " projectQuotaCpu | \n",
- " projectQuotaGpu | \n",
- " projectQuotaMemory | \n",
- " sharedVolumeCapacity | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " ccdd52b8-db16-46ce-8a06-70343c79e82a | \n",
- " primehub users | \n",
- " phusers | \n",
- " phadmin | \n",
- " NaN | \n",
- " NaN | \n",
- " None | \n",
- " None | \n",
- " None | \n",
- " None | \n",
- " 1.0 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " fa382829-d08a-4421-8de4-82e3231fe7a7 | \n",
- " test_group | \n",
- " test_group_from_jupyter | \n",
- " | \n",
- " 0.5 | \n",
- " 0.0 | \n",
- " None | \n",
- " None | \n",
- " None | \n",
- " None | \n",
- " NaN | \n",
- "
\n",
- " \n",
- "
\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",
- " id | \n",
- " displayName | \n",
- " name | \n",
- " admins | \n",
- " quotaCpu | \n",
- " quotaGpu | \n",
- " quotaMemory | \n",
- " projectQuotaCpu | \n",
- " projectQuotaGpu | \n",
- " projectQuotaMemory | \n",
- " sharedVolumeCapacity | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " ccdd52b8-db16-46ce-8a06-70343c79e82a | \n",
- " primehub users | \n",
- " phusers | \n",
- " phadmin | \n",
- " NaN | \n",
- " NaN | \n",
- " None | \n",
- " None | \n",
- " None | \n",
- " None | \n",
- " 1.0 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " df7fdfe4-5e12-4f1c-aeac-8004160c8e86 | \n",
- " test_group | \n",
- " test_group_from_jupyter | \n",
- " | \n",
- " 0.5 | \n",
- " 0.0 | \n",
- " None | \n",
- " None | \n",
- " None | \n",
- " None | \n",
- " NaN | \n",
- "
\n",
- " \n",
- "
\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",
- " id | \n",
- " displayName | \n",
- " name | \n",
- " admins | \n",
- " quotaCpu | \n",
- " quotaGpu | \n",
- " quotaMemory | \n",
- " projectQuotaCpu | \n",
- " projectQuotaGpu | \n",
- " projectQuotaMemory | \n",
- " sharedVolumeCapacity | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " ccdd52b8-db16-46ce-8a06-70343c79e82a | \n",
- " primehub users | \n",
- " phusers | \n",
- " phadmin | \n",
- " NaN | \n",
- " NaN | \n",
- " None | \n",
- " None | \n",
- " None | \n",
- " None | \n",
- " 1.0 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " d30688b3-fdf3-4b28-84ac-a1ef29c01033 | \n",
- " test_group | \n",
- " test_group_from_jupyter | \n",
- " | \n",
- " 0.5 | \n",
- " 0.0 | \n",
- " None | \n",
- " None | \n",
- " None | \n",
- " None | \n",
- " NaN | \n",
- "
\n",
- " \n",
- "
\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",
- " id | \n",
- " displayName | \n",
- " name | \n",
- " admins | \n",
- " quotaCpu | \n",
- " quotaGpu | \n",
- " quotaMemory | \n",
- " projectQuotaCpu | \n",
- " projectQuotaGpu | \n",
- " projectQuotaMemory | \n",
- " sharedVolumeCapacity | \n",
- "
\n",
- " \n",
- " \n",
- " \n",
- " 0 | \n",
- " ccdd52b8-db16-46ce-8a06-70343c79e82a | \n",
- " primehub users | \n",
- " phusers | \n",
- " phadmin | \n",
- " NaN | \n",
- " NaN | \n",
- " None | \n",
- " None | \n",
- " None | \n",
- " None | \n",
- " 1.0 | \n",
- "
\n",
- " \n",
- " 1 | \n",
- " c9aa9754-2805-40ac-8bb2-835aa17ad9f7 | \n",
- " test_group | \n",
- " test_group_from_jupyter | \n",
- " | \n",
- " 0.5 | \n",
- " 0.0 | \n",
- " None | \n",
- " None | \n",
- " None | \n",
- " None | \n",
- " NaN | \n",
- "
\n",
- " \n",
- "
\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
-}
diff --git a/docs/usecases/README.md b/docs/usecases/README.md
new file mode 100644
index 0000000..3198545
--- /dev/null
+++ b/docs/usecases/README.md
@@ -0,0 +1,3 @@
+# PrimeHub Python SDK Use-case
+
+By these use-cases, SDK users can learn what the SDK are capable of fundamentally.
diff --git a/docs/usecases/environment setup.ipynb b/docs/usecases/environment setup.ipynb
new file mode 100644
index 0000000..42b1928
--- /dev/null
+++ b/docs/usecases/environment setup.ipynb
@@ -0,0 +1,165 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "id": "bc587508",
+ "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": "e65022ec",
+ "metadata": {},
+ "source": [
+ "## Set up the environment"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "db61af40",
+ "metadata": {},
+ "source": [
+ "### Install the Python SDK package"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "49f8729a",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "!pip install -U primehub-python-sdk"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "007c8d7e",
+ "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": "f65a7cd8",
+ "metadata": {},
+ "source": [
+ "**Replace the value below with your PrimeHub domain (*http* or *https*).**"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "632296f5",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "PRIMEHUB_CLUSTER = 'https://c.demo.primehub.io/'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "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`."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "b5d398e2",
+ "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": "3709ddbd",
+ "metadata": {},
+ "source": [
+ "### Verify the environment"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "31e0cf90",
+ "metadata": {},
+ "outputs": [],
+ "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": "22f43b52",
+ "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": null,
+ "id": "d6bea7c2",
+ "metadata": {},
+ "outputs": [],
+ "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/usecases/group-wise-usecase.ipynb b/docs/usecases/group-wise-usecase.ipynb
new file mode 100644
index 0000000..74daee5
--- /dev/null
+++ b/docs/usecases/group-wise-usecase.ipynb
@@ -0,0 +1,831 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "id": "840bcccf",
+ "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": "markdown",
+ "id": "e09680ba",
+ "metadata": {},
+ "source": [
+ "**Replace the value below with your PrimeHub domain (*http* or *https*).**"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "690b6e7f",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "PRIMEHUB_CLUSTER = 'https://c.demo.primehub.io'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "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`."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "8de6f73d",
+ "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": "f177c24e",
+ "metadata": {},
+ "source": [
+ "## ToC\n",
+ "\n",
+ "- [Fundamental Operations (CRUD)](#fundamental)\n",
+ "- [Common Operations](#common)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "904f3be8",
+ "metadata": {},
+ "source": [
+ "## Fundamental Operations "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "26eb679b",
+ "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": "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."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "305eb28f",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "group_name = 'Continental'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "d4ba540d",
+ "metadata": {},
+ "source": [
+ "Let's prepare the configuration of creating a group, *Continental*, with the preset requirements."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "96ffac56",
+ "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": "cff6ee6d",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "specified_group = ph.admin.groups.create(config)\n",
+ "specified_group"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "68416589",
+ "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": "0a77502c",
+ "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": "06706ba0",
+ "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": "63e539f8",
+ "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": "94ce929c",
+ "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": "8959ca54",
+ "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": "255c2de5",
+ "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": "1f124d89",
+ "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": "53d38bf2",
+ "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": "1e03e058",
+ "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": "49694697",
+ "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": "2bcb8e32",
+ "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": "4a3df7b8",
+ "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": "fff5aa9c",
+ "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": "db9afc31",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "image_config = {\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",
+ " \"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": "25f294dc",
+ "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": "61f18ee1",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "instancetype_config = {\n",
+ " \"name\": \"sdk-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": "6ee58460",
+ "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": "920cc8e8",
+ "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": "6e5acaf9",
+ "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": "68f2e759",
+ "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": "a473b6b0",
+ "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\": [specified_user['id']]\n",
+ "# \"admins\": \"\" #remove all of admins\n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "e6598105",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "result = ph.admin.groups.update(specified_group['id'], updated_config)\n",
+ "result"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "2ca387ba",
+ "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": "f4d843c6",
+ "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": "82c88f39",
+ "metadata": {},
+ "source": [
+ "### Delete Group\n",
+ "\n",
+ "Delete the specified group by the given group's id."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "80fb30b1",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ph.admin.groups.delete(specified_group['id'])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "d2e3c9c6",
+ "metadata": {},
+ "source": [
+ "## Common Operations "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "06ce25fa",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# Get the specified group detail 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": "a788dbbc",
+ "metadata": {},
+ "source": [
+ "### Get group admin users"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "6887a53d",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "group_detail['admins']"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "8d06a047",
+ "metadata": {},
+ "source": [
+ "### Get groups with Zero User"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "74ed9ea4",
+ "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": "507aaf98",
+ "metadata": {},
+ "source": [
+ "### Get groups with running Deployments"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "7af2b0fc",
+ "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": "9fae7a20",
+ "metadata": {},
+ "source": [
+ "### List groups with current resources usage"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "c45c69eb",
+ "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": "6698de69",
+ "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": "f0e20bad",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ph.admin.groups.list_images(group_detail['id'])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "04f15c54",
+ "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": "8ffd0426",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ph.admin.groups.list_instancetypes(group_detail['id'])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "f5fedcfa",
+ "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": "544dfcf8",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ph.admin.groups.list_volumes(group_detail['id'])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "862d21c6",
+ "metadata": {},
+ "source": [
+ "### Delete a specified group and Delete its members"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "673b580e",
+ "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/usecases/image-wise-usecase.ipynb b/docs/usecases/image-wise-usecase.ipynb
new file mode 100644
index 0000000..b6dd454
--- /dev/null
+++ b/docs/usecases/image-wise-usecase.ipynb
@@ -0,0 +1,432 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "id": "9ec29b42",
+ "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": "markdown",
+ "id": "2420ffdf",
+ "metadata": {},
+ "source": [
+ "**Replace the value below with your PrimeHub domain (*http* or *https*).**"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "d338df8b",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "PRIMEHUB_CLUSTER = 'https://c.demo.primehub.io'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "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`."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "70649bdd",
+ "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": "f1644981",
+ "metadata": {},
+ "source": [
+ "## ToC\n",
+ "\n",
+ "- [Fundamental Operations (CRUD)](#fundamental)\n",
+ "- [Common Operations](#common)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "cb657f40",
+ "metadata": {},
+ "source": [
+ "---\n",
+ "## Fundamental Operations "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "b33e91e9",
+ "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": "0b2bad7a",
+ "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": "d57e5b59",
+ "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": "9fd8b282",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "created_image = ph.admin.images.create(image_config_with_specified_groups)\n",
+ "created_image"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "24e16147",
+ "metadata": {},
+ "source": [
+ "### Update Image Configuration\n",
+ "\n",
+ "Method: `ph.admin.images.update('image_id', configuration)`"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "2e496c8e",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "updating_config = {\n",
+ " \"description\": \"Base image updated by SDK example\"\n",
+ "}\n",
+ "\n",
+ "ph.admin.images.update(created_image['id'], updating_config)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "648171d1",
+ "metadata": {},
+ "source": [
+ "### Get Image Detail Info\n",
+ "\n",
+ "Method: `ph.admin.images.get('image_'id)`"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "9eb4565e",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ph.admin.images.get(created_image['id'])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "5e72c4c9",
+ "metadata": {},
+ "source": [
+ "### Get connected Groups of Image\n",
+ "\n",
+ "Method: `ph.admin.images.list_groups('image_id')`"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "0b038a85",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ph.admin.images.list_groups(created_image['id'])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "b29c50d5",
+ "metadata": {},
+ "source": [
+ "### List All of Images\n",
+ "\n",
+ "Method: `ph.admin.images.list()`"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "9a1fad3b",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "all_images = ph.admin.images.list()\n",
+ "for image in all_images:\n",
+ " print(image)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "061ab63a",
+ "metadata": {},
+ "source": [
+ "### Delete Image\n",
+ "\n",
+ "Method: `ph.admin.images.delete('image_id')`"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "79367521",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ph.admin.images.delete(created_image['id'])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "c8f700ac",
+ "metadata": {},
+ "source": [
+ "---\n",
+ "\n",
+ "## Common Operations "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "cb48c979",
+ "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": "1510e584",
+ "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": "7759b0b1",
+ "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": "8dd92f71",
+ "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": "d11fc3d6",
+ "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": "1448a6bf",
+ "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": "3bcfeb05",
+ "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": "514882d4",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "image_custom = ph.admin.images.create(config)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "50a11315",
+ "metadata": {},
+ "source": [
+ "We can tell the building status from `jobStatus` by getting the custom image info."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "1146e0eb",
+ "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/usecases/instance-type-usecase.ipynb b/docs/usecases/instance-type-usecase.ipynb
new file mode 100644
index 0000000..d6d92b3
--- /dev/null
+++ b/docs/usecases/instance-type-usecase.ipynb
@@ -0,0 +1,447 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "id": "66fcea6e",
+ "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": "markdown",
+ "id": "1cb8ac76",
+ "metadata": {},
+ "source": [
+ "**Replace the value below with your PrimeHub domain (*http* or *https*).**"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "71e83b36",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "PRIMEHUB_CLUSTER = 'https://c.demo.primehub.io'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "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`."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "3c3881e6",
+ "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": "5784fb94",
+ "metadata": {},
+ "source": [
+ "## ToC\n",
+ "\n",
+ "- [Fundamental Operations (CRUD)](#fundamental)\n",
+ "- [Common Operations](#common)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "0e0a3309",
+ "metadata": {},
+ "source": [
+ "---\n",
+ "## Fundamental Operations "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "7a041006",
+ "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": "b30bc9aa",
+ "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": "78a73ff8",
+ "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": "6aba3193",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "instancetype = ph.admin.instancetypes.create(instancetype_config_with_specified_groups)\n",
+ "instancetype"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "585743b2",
+ "metadata": {},
+ "source": [
+ "### Get InstanceType Detail\n",
+ "\n",
+ "Method: `ph.admin.instancetypes.get(instancetype_id)`"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "2d46df26",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ph.admin.instancetypes.get(instancetype['id'])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "091b43e9",
+ "metadata": {},
+ "source": [
+ "### Update InstanceType Configuration\n",
+ "\n",
+ "Method: `ph.admin.instancetypes.update(instancetype_id, config)`"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "8415ed66",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "updating_config = {\n",
+ " \"description\": \"4 CPU / 4GB Mem\",\n",
+ " \"gpuLimit\": 2,\n",
+ "}"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "6044d3ff",
+ "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": "5619da15",
+ "metadata": {},
+ "source": [
+ "### Get connected Groups of InstanceTypes\n",
+ "\n",
+ "Method: `ph.admin.instancetypes.list_groups('instancetype_id')`"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "4897c996",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ph.admin.instancetypes.list_groups(instancetype['id'])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "8bb8cffe",
+ "metadata": {},
+ "source": [
+ "### List All of InstaceTypes\n",
+ "\n",
+ "Method: `ph.admin.instancetypes.list()`"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "23dffe85",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "all_images = ph.admin.instancetypes.list()\n",
+ "for image in all_images:\n",
+ " print(image)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "edcb1771",
+ "metadata": {},
+ "source": [
+ "### Delete InstanceType\n",
+ "\n",
+ "Method: `ph.admin.instancetype.delete(instancetype_id)`"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "4d8597b3",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ph.admin.instancetypes.delete(instancetype['id'])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "84df3fea",
+ "metadata": {},
+ "source": [
+ "---\n",
+ "\n",
+ "## Common Operations "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "12f9eb47",
+ "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": "8c243e87",
+ "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": "bab9b645",
+ "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": "ef7ebcc6",
+ "metadata": {},
+ "source": [
+ "### Add/Remove Toleration on InstanceType"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "336ab13a",
+ "metadata": {},
+ "source": [
+ "By `ph.admin.instancetypes.update()` you can add a tolerations on the instancetype."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "9f164bde",
+ "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": "70ae4737",
+ "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": "4e3f86e8",
+ "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": "fd5567bc",
+ "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": "ae4d73a4",
+ "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/usecases/secret-wise-usecase.ipynb b/docs/usecases/secret-wise-usecase.ipynb
new file mode 100644
index 0000000..c5536c0
--- /dev/null
+++ b/docs/usecases/secret-wise-usecase.ipynb
@@ -0,0 +1,323 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "id": "9813dcab",
+ "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": "markdown",
+ "id": "6ed7b110",
+ "metadata": {},
+ "source": [
+ "**Replace the value below with your PrimeHub domain (*http* or *https*).**"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "409bea3a",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "PRIMEHUB_CLUSTER = 'https://c.demo.primehub.io'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "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`."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "cfc2bfbd",
+ "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": "b0084886",
+ "metadata": {},
+ "source": [
+ "## ToC\n",
+ "\n",
+ "- [Fundamental Operations (CRUD)](#fundamental)\n",
+ "- [Common Operations](#common)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "63f5672c",
+ "metadata": {},
+ "source": [
+ "---\n",
+ "## Fundamental Operations "
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "9f9948aa",
+ "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": "b5c6fa9a",
+ "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": "19022d68",
+ "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": "33a875a2",
+ "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": "674fbc76",
+ "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": "43383aae",
+ "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": "1c60fb92",
+ "metadata": {},
+ "source": [
+ "### Get secret Detail\n",
+ "\n",
+ "Method: `ph.admin.secrets.get(secret_id)`\n"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "184b002a",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ph.admin.secrets.get(image_pull_secret['id'])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "5b44ad00",
+ "metadata": {},
+ "source": [
+ "### Update secret Configuration\n",
+ "\n",
+ "Method: `ph.admin.secrets.update(configuration)`"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "eb7287c3",
+ "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": "d08d8140",
+ "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": "b9fa2a5c",
+ "metadata": {},
+ "source": [
+ "### List All of secrets\n",
+ "\n",
+ "Method: `ph.admin.secrets.list()`"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "decc4aae",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "all_secrets = ph.admin.secrets.list()\n",
+ "for secret in all_secrets:\n",
+ " print(secret)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "d1b11371",
+ "metadata": {},
+ "source": [
+ "### Delete secret\n",
+ "\n",
+ "Method: `ph.admin.secrets.delete(secret_id)`"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "1053c878",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ph.admin.secrets.delete(gitsync_secret['id'])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "7505a9d2",
+ "metadata": {},
+ "source": [
+ "---\n",
+ "\n",
+ "## Common Operations "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "971655d7",
+ "metadata": {},
+ "source": [
+ "### List Secrets by Type"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "ffdff894",
+ "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/usecases/user-wise-usecase.ipynb b/docs/usecases/user-wise-usecase.ipynb
new file mode 100644
index 0000000..95c6338
--- /dev/null
+++ b/docs/usecases/user-wise-usecase.ipynb
@@ -0,0 +1,478 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "id": "4cd0fc56",
+ "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": "markdown",
+ "id": "0239be15",
+ "metadata": {},
+ "source": [
+ "**Replace the value below with your PrimeHub domain (*http* or *https*).**"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "d8d74181",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "PRIMEHUB_CLUSTER = 'https://c.demo.primehub.io'"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "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`."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "aecc5e6d",
+ "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": "adb34dc5",
+ "metadata": {},
+ "source": [
+ "## ToC\n",
+ "\n",
+ "- [Fundamental Operations (CRUD)](#fundamental)\n",
+ "- [Common Operations](#common)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "b322fc83",
+ "metadata": {},
+ "source": [
+ "## Fundamental Operations "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "2086675b",
+ "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": "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."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "55643992",
+ "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": "5d211203",
+ "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": "87ea9469",
+ "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": "b12d3db0",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "data = ph.admin.users.create(config)\n",
+ "data"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "3a6e1e85",
+ "metadata": {},
+ "source": [
+ "### Get User Info\n",
+ "\n",
+ "Get the specified user information by the user's id."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "afea82c7",
+ "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": "c15d9017",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# get the user info\n",
+ "ph.admin.users.get(specified_user['id'])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "922c3b72",
+ "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": "643aba64",
+ "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": "73e3720c",
+ "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": "a489bde0",
+ "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": "ed39d164",
+ "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": "b56c150d",
+ "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": "e35c3e4c",
+ "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": "e9f8ddce",
+ "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": "2d89cb35",
+ "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": "349a1b83",
+ "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": "b978b8ee",
+ "metadata": {},
+ "source": [
+ "### Delete User\n",
+ "\n",
+ "Delete the specified user by the user's id."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "be2e456f",
+ "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": "f807f8a9",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ph.admin.users.delete(specified_user['id'])"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "0962247c",
+ "metadata": {},
+ "source": [
+ "## Common Operations "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "5a12e3d2",
+ "metadata": {},
+ "source": [
+ "### Get group list of a specified user"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "bb9f6cb9",
+ "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": "39a3102b",
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "ph.admin.users.get(specified_user['id'])['groups']"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "id": "c65d97c0",
+ "metadata": {},
+ "source": [
+ "### Get admin user list"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "89fb6547",
+ "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": "d3ec18ed",
+ "metadata": {},
+ "source": [
+ "### Get disabled user list"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "id": "59756b53",
+ "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/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/usecases/volume-wise-usercase.ipynb b/docs/usecases/volume-wise-usercase.ipynb
new file mode 100644
index 0000000..68ea2ee
--- /dev/null
+++ b/docs/usecases/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
+}