diff --git a/docs/notebook/admin-portal/01-groups.ipynb b/docs/notebook/admin-portal/01-groups.ipynb new file mode 100644 index 00000000..c7bc0967 --- /dev/null +++ b/docs/notebook/admin-portal/01-groups.ipynb @@ -0,0 +1,1496 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "34d82d1e", + "metadata": {}, + "source": [ + "# [admin] Groups command\n", + "\n", + "\n", + "The `groups` command in `admin` scope could help you manage groups.\n" + ] + }, + { + "cell_type": "markdown", + "id": "246eebe5", + "metadata": {}, + "source": [ + "## Setup PrimeHub Python SDK\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "3fb3ee1f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PrimeHub Python SDK setup successfully\n" + ] + } + ], + "source": [ + "from primehub import PrimeHub, PrimeHubConfig\n", + "ph = PrimeHub(PrimeHubConfig())\n", + "\n", + "if ph.is_ready():\n", + " print(\"PrimeHub Python SDK setup successfully\")\n", + "else:\n", + " print(\"PrimeHub Python SDK couldn't get the group information, follow the 00-getting-started.ipynb to complete it\")" + ] + }, + { + "cell_type": "markdown", + "id": "1b2f8751", + "metadata": {}, + "source": [ + "## Help documentation" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "b7895cdc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on AdminGroups in module primehub.admin_groups object:\n", + "\n", + "class AdminGroups(primehub.Helpful, primehub.Module, AdminGroupsUsers, AdminGroupsImages, AdminGroupsInstanceTypes, AdminGroupsVolumes)\n", + " | AdminGroups(primehub: primehub.PrimeHub, **kwargs)\n", + " | \n", + " | Method resolution order:\n", + " | AdminGroups\n", + " | primehub.Helpful\n", + " | primehub.Module\n", + " | AdminGroupsUsers\n", + " | AdminGroupsImages\n", + " | AdminGroupsInstanceTypes\n", + " | AdminGroupsVolumes\n", + " | primehub.HTTPSupport\n", + " | builtins.object\n", + " | \n", + " | Methods defined here:\n", + " | \n", + " | create(self, config: dict)\n", + " | Create a group\n", + " | \n", + " | :type config: dict\n", + " | :param config: the configurations of the created group\n", + " | \n", + " | :rtype: dict\n", + " | :return: the created group\n", + " | \n", + " | delete(self, id: str) -> dict\n", + " | Delete the group by id\n", + " | \n", + " | :type id: str\n", + " | :param id: the group id\n", + " | \n", + " | :rtype: dict\n", + " | :return: the deleted group\n", + " | \n", + " | get(self, id: str) -> dict\n", + " | Get the group info by id\n", + " | \n", + " | :type id: str\n", + " | :param id: the group id\n", + " | \n", + " | :rtype: dict\n", + " | :return: the group info\n", + " | \n", + " | help_description(self)\n", + " | one line description for all commands\n", + " | \n", + " | list(self, **kwargs) -> Iterator\n", + " | List groups\n", + " | \n", + " | :type page: int\n", + " | :param page: the page of all data\n", + " | \n", + " | :rtype: Iterator\n", + " | :return: groups iterator\n", + " | \n", + " | update(self, id: str, config: dict)\n", + " | Update the group\n", + " | \n", + " | :type id: str\n", + " | :param id: the group id\n", + " | :type config: dict\n", + " | :param config: the configurations for the updated group\n", + " | \n", + " | :rtype: dict\n", + " | :return: the group\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data and other attributes defined here:\n", + " | \n", + " | __abstractmethods__ = frozenset()\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors inherited from primehub.Helpful:\n", + " | \n", + " | __dict__\n", + " | dictionary for instance variables (if defined)\n", + " | \n", + " | __weakref__\n", + " | list of weak references to the object (if defined)\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Methods inherited from primehub.Module:\n", + " | \n", + " | __init__(self, primehub: primehub.PrimeHub, **kwargs)\n", + " | Initialize self. See help(type(self)) for accurate signature.\n", + " | \n", + " | display(self, action: dict, value: Any)\n", + " | \n", + " | get_display(self) -> primehub.utils.display.Displayable\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Static methods inherited from primehub.Module:\n", + " | \n", + " | output(result: dict, object_path: str)\n", + " | Give a dict {'data': {'a': {'b': 'c'}}}\n", + " | we could get the c by the path a.b\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors inherited from primehub.Module:\n", + " | \n", + " | current_group\n", + " | \n", + " | endpoint\n", + " | \n", + " | group_id\n", + " | \n", + " | group_name\n", + " | \n", + " | primehub_config\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Methods inherited from AdminGroupsUsers:\n", + " | \n", + " | connect_user(self, group_id: str, user_id: str, **kwargs)\n", + " | Add the user to the group\n", + " | \n", + " | :type group_id: str\n", + " | :param group_id: the group id\n", + " | \n", + " | :type user_id: str\n", + " | :param user_id: the user id\n", + " | \n", + " | :returns errors or group-id if the user was added\n", + " | :rtype dict\n", + " | \n", + " | disconnect_user(self, group_id: str, user_id: str, **kwargs)\n", + " | Add the user to the group\n", + " | \n", + " | :type group_id: str\n", + " | :param group_id: the group id\n", + " | \n", + " | :type user_id: str\n", + " | :param user_id: the user id\n", + " | \n", + " | :returns errors or group-id if the user was added\n", + " | :rtype dict\n", + " | \n", + " | list_users(self, group_id: str)\n", + " | List users in the group\n", + " | \n", + " | :type group_id: str\n", + " | :param group_id: the group id\n", + " | \n", + " | :returns errors or list\n", + " | :rtype dict, list\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Methods inherited from AdminGroupsImages:\n", + " | \n", + " | connect_image(self, group_id: str, image_id: str) -> Dict\n", + " | Make the image join the group\n", + " | \n", + " | :type group_id: str\n", + " | :param group_id: The group id\n", + " | \n", + " | :type image_id: str\n", + " | :param image_id: The image id\n", + " | \n", + " | :rtype dict\n", + " | :return The image\n", + " | \n", + " | create_image(self, group_id: str, config: Dict) -> Dict\n", + " | Create a new image and connect it to the group\n", + " | \n", + " | :type group_id: str\n", + " | :param group_id: The group id\n", + " | \n", + " | :type config: dict\n", + " | :param config: The configurations for creating an image\n", + " | \n", + " | :rtype dict\n", + " | :return The image\n", + " | \n", + " | disconnect_image(self, group_id: str, image_id: str) -> Dict\n", + " | Make the image leave the group\n", + " | \n", + " | :type group_id: str\n", + " | :param group_id: The group id\n", + " | \n", + " | :type image_id: str\n", + " | :param image_id: The image id\n", + " | \n", + " | :rtype dict\n", + " | :return The image\n", + " | \n", + " | list_images(self, group_id: str) -> List\n", + " | List images in the group\n", + " | \n", + " | :type group_id: str\n", + " | :param group_id: The group id\n", + " | \n", + " | :rtype list\n", + " | :return image list\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Methods inherited from AdminGroupsInstanceTypes:\n", + " | \n", + " | connect_instancetype(self, group_id: str, instancetype_id: str) -> Dict\n", + " | Make the instanceType join the group\n", + " | \n", + " | :type group_id: str\n", + " | :param group_id: The group id\n", + " | \n", + " | :type instancetype_id: str\n", + " | :param instancetype_id: The instanceType id\n", + " | \n", + " | :rtype dict\n", + " | :return The image\n", + " | \n", + " | create_instancetype(self, group_id: str, config: Dict) -> Dict\n", + " | Create a new instanceType and connect it to the group\n", + " | \n", + " | :type group_id: str\n", + " | :param group_id: The group id\n", + " | \n", + " | :type config: dict\n", + " | :param config: The configurations for creating an instanceType\n", + " | \n", + " | :rtype dict\n", + " | :return The instanceType\n", + " | \n", + " | disconnect_instancetype(self, group_id: str, instancetype_id: str) -> Dict\n", + " | Make the instanceType leave the group\n", + " | \n", + " | :type group_id: str\n", + " | :param group_id: The group id\n", + " | \n", + " | :type instancetype_id: str\n", + " | :param instancetype_id: The instanceType id\n", + " | \n", + " | :rtype dict\n", + " | :return The image\n", + " | \n", + " | list_instancetypes(self, group_id: str) -> List\n", + " | List instance-type in the group\n", + " | \n", + " | :type group_id: str\n", + " | :param group_id: The group id\n", + " | \n", + " | :rtype list\n", + " | :return instance-type list\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Methods inherited from AdminGroupsVolumes:\n", + " | \n", + " | connect_volume(self, group_id: str, volume_id: str) -> Dict\n", + " | Make the volume join the group\n", + " | \n", + " | :type group_id: str\n", + " | :param group_id: The group id\n", + " | \n", + " | :type volume_id: str\n", + " | :param volume_id: The volume id\n", + " | \n", + " | :rtype dict\n", + " | :return The volume\n", + " | \n", + " | create_volume(self, group_id: str, writable: bool, config: Dict) -> Dict\n", + " | Create a new volume and connect it to the group\n", + " | \n", + " | :type group_id: str\n", + " | :param group_id: The group id\n", + " | \n", + " | :type writable: bool\n", + " | :param writable: Set the writable for the connection\n", + " | \n", + " | :type config: dict\n", + " | :param config: The configurations for creating an instanceType\n", + " | \n", + " | :rtype dict\n", + " | :return The volume\n", + " | \n", + " | disconnect_volume(self, group_id: str, volume_id: str) -> Dict\n", + " | Make the volume leave the group\n", + " | \n", + " | :type group_id: str\n", + " | :param group_id: The group id\n", + " | \n", + " | :type volume_id: str\n", + " | :param volume_id: The volume id\n", + " | \n", + " | :rtype dict\n", + " | :return The volume\n", + " | \n", + " | list_volumes(self, group_id: str) -> List\n", + " | List volumes in the group\n", + " | \n", + " | :type group_id: str\n", + " | :param group_id: The group id\n", + " | \n", + " | :rtype list\n", + " | :return volumes list\n", + "\n" + ] + } + ], + "source": [ + "help(ph.admin.groups)" + ] + }, + { + "cell_type": "markdown", + "id": "d759718a", + "metadata": {}, + "source": [ + "## Group management\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "4ead7cc6", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Usage: \n", + " primehub admin groups \n", + "\n", + "Manage groups\n", + "\n", + "Available Commands:\n", + " connect-image Make the image join the group\n", + " connect-instancetype Make the instanceType join the group\n", + " connect-user Add the user to the group\n", + " connect-volume Make the volume join the group\n", + " create Create a group\n", + " create-image Add the image to the group\n", + " create-instancetype Create a new instanceType and connect it to the group\n", + " create-volume Create a new volume and connect it to the group\n", + " delete Delete the group by id\n", + " disconnect-image Make the image leave the group\n", + " disconnect-instancetype\n", + " Make the instanceType leave the group\n", + " disconnect-user Remove the user from the group\n", + " disconnect-volume Make the volume leave the group\n", + " get Get the group info by id\n", + " list List groups\n", + " list-images List images in the group\n", + " list-instancetypes List instanceTypes in the group\n", + " list-users List users in the group\n", + " list-volumes List volumes in the group\n", + " update Update the group\n", + "\n", + "Options:\n", + " -h, --help Show the help\n", + "\n", + "Global Options:\n", + " --config CONFIG Change the path of the config file (Default: ~/.primehub/config.json)\n", + " --endpoint ENDPOINT Override the GraphQL API endpoint\n", + " --token TOKEN Override the API Token\n", + " --group GROUP Override the current group\n", + " --json Output the json format (output human-friendly format by default)\n" + ] + } + ], + "source": [ + "!primehub admin groups help" + ] + }, + { + "cell_type": "markdown", + "id": "25473175", + "metadata": {}, + "source": [ + "For `create` and `update` actions are needed a configuration to mutate a group. Here is the fields table:\n", + "\n", + "\n", + "### Fields\n", + "\n", + "| field | required | type | description |\n", + "| --- | --- | --- | --- |\n", + "| name | required | string | must start with a letter or numeric, '-' and '_' are allowed, and the length should be more than 2. |\n", + "| displayName | optional | string | display name |\n", + "| quotaCpu | optional | float | how many CPU can be used by the user within this group, default: 0.5 |\n", + "| quotaGpu | optional | int | how many GPU can be used by the user within this group, default: 0 |\n", + "| quotaMemory | optional | float | how many memory can be used by the user within this group, default: unlimited GB |\n", + "| projectQuotaCpu | optional | float | how many CPU can be shared by all users in the group, default: unlimited |\n", + "| projectQuotaGpu | optional | int | how many GPU can be shared by all users in the group, default: unlimited |\n", + "| projectQuotaMemory| optional | float | how many memory can be shared by all users in the group, default: unlimited GB |\n", + "| admins | optional | string | assign admin user of the group, multiple users are able to be assigned (see [also](https://docs.primehub.io/docs/guide_manual/admin-group#group-admin)) |\n", + "| users | optional | assign / dissociate users to the group | please see the connect / disconnect examples |\n", + "\n", + "*Note: user resource quota should not greater than project resource quota. e.g., `quotaCpu <= projectQuotaCpu`*\n", + "\n", + "\n", + "#### Model Deployment\n", + "Groups with enabled model deployment are able to deploy/serve models. (see [also](https://docs.primehub.io/docs/guide_manual/admin-group#model-deployment))\n", + "\n", + "`maxDeploy` is used when `enabledDeployment` is enable:\n", + "\n", + "| field | required | type | description |\n", + "| --- | --- | --- | --- |\n", + "| enabledDeployment | optional | boolean | enable model deployment |\n", + "| maxDeploy | optional | int | limit on the amount of deployments for this group |\n", + "\n", + "#### Shared Volume\n", + "The created shared volume is shared among members in the group. (see [also](https://docs.primehub.io/docs/guide_manual/admin-group#shared-volume))\n", + "\n", + "`sharedVolumeCapacity` is used when `enabledSharedVolume` is enable:\n", + "\n", + "| field | required | type | description |\n", + "| --- | --- | --- | --- |\n", + "| enabledSharedVolume | optional | boolean | enable share volume |\n", + "| sharedVolumeCapacity | optional | int | the capacity of the shared volume in GB |\n" + ] + }, + { + "cell_type": "markdown", + "id": "523cbcf3", + "metadata": {}, + "source": [ + "## Examples" + ] + }, + { + "cell_type": "markdown", + "id": "e9d84bc9", + "metadata": {}, + "source": [ + "You could find [more examples on our github](https://github.com/InfuseAI/primehub-python-sdk/blob/main/docs/CLI/admin/groups.md)." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "df97cd8f", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "id": "a5b3e574", + "metadata": {}, + "source": [ + "### CRUD: Group" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "1c954f5d", + "metadata": {}, + "outputs": [], + "source": [ + "# Create a group with admin role\n", + "\n", + "config = {\n", + " \"name\": \"test_group_from_primehub_sdk\",\n", + " \"displayName\": \"test_group_sdk\",\n", + " \"enabledDeployment\": False,\n", + " \"enabledSharedVolume\": False,\n", + " \"quotaCpu\": 0.5,\n", + " \"quotaGpu\": 0,\n", + " \"admins\": \"\",\n", + " \"users\": {\n", + " \"connect\": []\n", + " }\n", + "}\n", + "\n", + "group = ph.admin.groups.create(config)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "92d6c349", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
iddisplayNamenameadminsquotaCpuquotaGpuquotaMemoryprojectQuotaCpuprojectQuotaGpuprojectQuotaMemorysharedVolumeCapacity
21c455ccde-3ed0-41d3-9962-5e7d8dd92f20test_group_sdktest_group_from_primehub_sdk0.50.0NaNNaNNaNNaNNaN
\n", + "
" + ], + "text/plain": [ + " id displayName \\\n", + "21 c455ccde-3ed0-41d3-9962-5e7d8dd92f20 test_group_sdk \n", + "\n", + " name admins quotaCpu quotaGpu quotaMemory \\\n", + "21 test_group_from_primehub_sdk 0.5 0.0 NaN \n", + "\n", + " projectQuotaCpu projectQuotaGpu projectQuotaMemory sharedVolumeCapacity \n", + "21 NaN NaN NaN NaN " + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# List groups\n", + "\n", + "groups_df = pd.DataFrame(ph.admin.groups.list())\n", + "groups_df[groups_df['name'] == config['name']]" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "58454fd1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'c455ccde-3ed0-41d3-9962-5e7d8dd92f20',\n", + " 'displayName': 'test_group_sdk',\n", + " 'name': 'test_group_from_primehub_sdk',\n", + " 'admins': '',\n", + " 'users': [],\n", + " 'quotaCpu': 0.5,\n", + " 'quotaGpu': 0,\n", + " 'quotaMemory': None,\n", + " 'projectQuotaCpu': None,\n", + " 'projectQuotaGpu': None,\n", + " 'projectQuotaMemory': None,\n", + " 'resourceStatus': {'cpuUsage': '0', 'memUsage': '0', 'gpuUsage': '0'},\n", + " 'enabledDeployment': False,\n", + " 'maxDeploy': None,\n", + " 'deploymentsUsage': None,\n", + " 'enabledSharedVolume': False,\n", + " 'jobDefaultActiveDeadlineSeconds': None,\n", + " 'sharedVolumeCapacity': None,\n", + " 'launchGroupOnly': None,\n", + " 'images': [],\n", + " 'instanceTypes': [],\n", + " 'volumes': []}" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Get the group info by id\n", + "\n", + "ph.admin.groups.get(group['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "33bfbf99", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'c455ccde-3ed0-41d3-9962-5e7d8dd92f20'}" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Delete the group by id\n", + "\n", + "ph.admin.groups.delete(group['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "94c17a4b", + "metadata": {}, + "source": [ + "### Connect, disconnect, list: Group -> Users" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "73f2f070", + "metadata": {}, + "outputs": [], + "source": [ + "# Create a group with admin role\n", + "config = {\n", + " \"name\": \"test_group_from_primehub_sdk_connect_users\",\n", + " \"displayName\": \"test_group_sdk_connect_users\",\n", + " \"enabledDeployment\": False,\n", + " \"enabledSharedVolume\": False,\n", + " \"quotaCpu\": 0.5,\n", + " \"quotaGpu\": 0,\n", + " \"admins\": \"\",\n", + " \"users\": {\n", + " \"connect\": []\n", + " }\n", + "}\n", + "\n", + "group = ph.admin.groups.create(config)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "e4338175", + "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", + " },\n", + " \"isAdmin\": True\n", + "}\n", + "user = ph.admin.users.create(config)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "13db9d0c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': '63eaf5f8-c063-4d06-a7e3-e48620a80a12'}" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Connect user with group\n", + "\n", + "ph.admin.groups.connect_user(group['id'], user['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "a8342398", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'id': '5d97832f-39a8-4f40-8631-1a2de57dd59e',\n", + " 'username': 'user-admin-from-jupyter',\n", + " 'group_admin': False}]" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# List the connection between group and user\n", + "\n", + "ph.admin.groups.list_users(group['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6611ad8e", + "metadata": {}, + "outputs": [], + "source": [ + "# Disconnect user with group\n", + "\n", + "ph.admin.groups.disconnect_user(group['id'], user['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "60b0a4e8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'id': '5d97832f-39a8-4f40-8631-1a2de57dd59e',\n", + " 'username': 'user-admin-from-jupyter',\n", + " 'group_admin': False}]" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# List the connection between group and user\n", + "\n", + "ph.admin.groups.list_users(group['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "3ebaf8c4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': '63eaf5f8-c063-4d06-a7e3-e48620a80a12'}" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Delete the group by id\n", + "\n", + "ph.admin.groups.delete(group['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "f3edbdff", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': '5d97832f-39a8-4f40-8631-1a2de57dd59e',\n", + " 'username': 'user-admin-from-jupyter'}" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Delete the user by id\n", + "\n", + "ph.admin.users.delete(user['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "b1c2922d", + "metadata": {}, + "source": [ + "### Connect, disconnect, list: Group -> instance type" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "afdd4486", + "metadata": {}, + "outputs": [], + "source": [ + "# Create a group with admin role\n", + "config = {\n", + " \"name\": \"test_group_from_primehub_sdk_connect_instance_type\",\n", + " \"displayName\": \"test_group_sdk_connect_instance_type\",\n", + " \"enabledDeployment\": False,\n", + " \"enabledSharedVolume\": False,\n", + " \"quotaCpu\": 0.5,\n", + " \"quotaGpu\": 0,\n", + " \"admins\": \"\",\n", + " \"users\": {\n", + " \"connect\": []\n", + " }\n", + "}\n", + "\n", + "group = ph.admin.groups.create(config)" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "712cfbb8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'cpu-instance-by-sdk-group'}" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# create an instance type\n", + "config = {\n", + " \"name\": \"cpu-instance-by-sdk-group\",\n", + " \"displayName\": \"CPU 1\",\n", + " \"description\": \"1 vCPU / 1G Memory\",\n", + " \"cpuLimit\": 1,\n", + " \"memoryLimit\": 1,\n", + " \"gpuLimit\": 0,\n", + " \"global\": False\n", + "}\n", + "\n", + "try:\n", + " instance_type = ph.admin.groups.create_instancetype(group['id'], config)\n", + "except:\n", + " instance_type = ph.admin.instancetypes.create(config)\n", + "instance_type" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "78b578b9", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'cpu-instance-by-sdk-group',\n", + " 'global': False,\n", + " 'cpuRequest': None,\n", + " 'memoryRequest': None,\n", + " 'groups': [{'id': 'df51c65d-ade9-483a-bf15-3289ce1a2055',\n", + " 'name': 'test_group_from_primehub_sdk_connect_instance_type',\n", + " 'displayName': 'test_group_sdk_connect_instance_type',\n", + " 'quotaCpu': 0.5,\n", + " 'quotaGpu': 0}],\n", + " 'nodeSelector': {}}" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Connect instance type with group\n", + "\n", + "ph.admin.groups.connect_instancetype(group['id'], instance_type['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "439a2181", + "metadata": {}, + "outputs": [], + "source": [ + "# List the connection between group and instance type\n", + "\n", + "ph.admin.groups.list_instancetypes(group['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "27ae5482", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'cpu-instance-by-sdk-group',\n", + " 'global': False,\n", + " 'cpuRequest': None,\n", + " 'memoryRequest': None,\n", + " 'groups': [],\n", + " 'nodeSelector': {}}" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Disconnect instance type with group\n", + "\n", + "ph.admin.groups.disconnect_instancetype(group['id'], instance_type['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f74b4c0b", + "metadata": {}, + "outputs": [], + "source": [ + "# List the connection between group and instance type\n", + "\n", + "ph.admin.groups.list_instancetypes(group['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "2c8fc148", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'df51c65d-ade9-483a-bf15-3289ce1a2055'}" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Delete the group by id\n", + "\n", + "ph.admin.groups.delete(group['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "bd0f4fc3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'cpu-instance-by-sdk-group'}" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Delete the instance type\n", + "\n", + "ph.admin.instancetypes.delete(instance_type['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "9400a2e7", + "metadata": {}, + "source": [ + "### Connect, disconnect, list: Group -> image" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "id": "2ec67caf", + "metadata": {}, + "outputs": [], + "source": [ + "# Create a group with admin role\n", + "config = {\n", + " \"name\": \"test_group_from_primehub_sdk_connect_image\",\n", + " \"displayName\": \"test_group_sdk_connect_image\",\n", + " \"enabledDeployment\": False,\n", + " \"enabledSharedVolume\": False,\n", + " \"quotaCpu\": 0.5,\n", + " \"quotaGpu\": 0,\n", + " \"admins\": \"\",\n", + " \"users\": {\n", + " \"connect\": []\n", + " }\n", + "}\n", + "\n", + "group = ph.admin.groups.create(config)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "7232cf73", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'image-by-sdk'}" + ] + }, + "execution_count": 27, + "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", + "}\n", + "\n", + "try:\n", + " image = ph.admin.groups.create_image(group['id'], config)\n", + "except:\n", + " image = ph.admin.images.create(config)\n", + "image" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "8ac96e70", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'image-by-sdk',\n", + " 'groups': [{'id': '85d1985e-c06b-412e-a181-25539fccf9f6',\n", + " 'name': 'test_group_from_primehub_sdk_connect_image',\n", + " 'displayName': 'test_group_sdk_connect_image'}],\n", + " 'displayName': 'Learning how to create an image from SDK',\n", + " 'description': 'base-notebook with python 3.7',\n", + " 'url': 'infuseai/docker-stacks:base-notebook-63fdf50a',\n", + " 'urlForGpu': 'infuseai/docker-stacks:base-notebook-63fdf50a-gpu',\n", + " 'name': 'image-by-sdk',\n", + " 'type': 'both',\n", + " 'groupName': None,\n", + " 'useImagePullSecret': None,\n", + " 'logEndpoint': 'https://c.demo.primehub.io/api/logs/images/image-by-sdk/job',\n", + " 'isReady': True,\n", + " 'spec': {'description': 'base-notebook with python 3.7',\n", + " 'displayName': 'Learning how to create an image from SDK',\n", + " 'type': 'both',\n", + " 'url': 'infuseai/docker-stacks:base-notebook-63fdf50a',\n", + " 'urlForGpu': 'infuseai/docker-stacks:base-notebook-63fdf50a-gpu'},\n", + " 'global': False,\n", + " 'jobStatus': None,\n", + " 'imageSpec': None}" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Connect image with group\n", + "ph.admin.groups.connect_image(group['id'], image['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fa14caa7", + "metadata": {}, + "outputs": [], + "source": [ + "# List the connection between group and image\n", + "ph.admin.groups.list_images(group['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "id": "cb8fd7c7", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'image-by-sdk',\n", + " 'groups': [],\n", + " 'displayName': 'Learning how to create an image from SDK',\n", + " 'description': 'base-notebook with python 3.7',\n", + " 'url': 'infuseai/docker-stacks:base-notebook-63fdf50a',\n", + " 'urlForGpu': 'infuseai/docker-stacks:base-notebook-63fdf50a-gpu',\n", + " 'name': 'image-by-sdk',\n", + " 'type': 'both',\n", + " 'groupName': None,\n", + " 'useImagePullSecret': None,\n", + " 'logEndpoint': 'https://c.demo.primehub.io/api/logs/images/image-by-sdk/job',\n", + " 'isReady': True,\n", + " 'spec': {'description': 'base-notebook with python 3.7',\n", + " 'displayName': 'Learning how to create an image from SDK',\n", + " 'type': 'both',\n", + " 'url': 'infuseai/docker-stacks:base-notebook-63fdf50a',\n", + " 'urlForGpu': 'infuseai/docker-stacks:base-notebook-63fdf50a-gpu'},\n", + " 'global': False,\n", + " 'jobStatus': None,\n", + " 'imageSpec': None}" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Disconnect image with group\n", + "\n", + "ph.admin.groups.disconnect_image(group['id'], image['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1962b7fe", + "metadata": {}, + "outputs": [], + "source": [ + "# List the connection between group and image\n", + "\n", + "ph.admin.groups.list_images(group['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "1bbfb77e", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': '85d1985e-c06b-412e-a181-25539fccf9f6'}" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Delete the group by id\n", + "\n", + "ph.admin.groups.delete(group['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "01ee9cc0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'image-by-sdk'}" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Delete the image\n", + "\n", + "ph.admin.images.delete(image['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "0d9534b9", + "metadata": {}, + "source": [ + "### Connect, disconnect, list: Group -> volumes" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "915ea781", + "metadata": {}, + "outputs": [], + "source": [ + "# Create a group with admin role\n", + "config = {\n", + " \"name\": \"test_group_from_primehub_sdk_connect_volume\",\n", + " \"displayName\": \"test_group_sdk_connect_volume\",\n", + " \"enabledDeployment\": False,\n", + " \"enabledSharedVolume\": False,\n", + " \"quotaCpu\": 0.5,\n", + " \"quotaGpu\": 0,\n", + " \"admins\": \"\",\n", + " \"users\": {\n", + " \"connect\": []\n", + " }\n", + "}\n", + "\n", + "group = ph.admin.groups.create(config)" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "0ffc7365", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'pv-volume-by-sdk'}" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Create an volume\n", + "config = {\n", + " \"name\": \"pv-volume-by-sdk\",\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", + "\n", + "try:\n", + " volume = ph.admin.groups.create_volume(group['id'], writable=True, config=config)\n", + "except:\n", + " volume = ph.admin.volumes.create(config)\n", + "volume" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "a704d75a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'pv-volume-by-sdk', 'uploadServerSecret': None}" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Connect user with group\n", + "ph.admin.groups.connect_volume(group['id'], volume['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "65823c8b", + "metadata": {}, + "outputs": [], + "source": [ + "# List the connection between group and volume\n", + "ph.admin.groups.list_volumes(group['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "e25c1a4d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'pv-volume-by-sdk', 'uploadServerSecret': None}" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Disconnect volume with group\n", + "\n", + "ph.admin.groups.disconnect_volume(group['id'], volume['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e01ecf58", + "metadata": {}, + "outputs": [], + "source": [ + "# List the connection between group and volume\n", + "\n", + "ph.admin.groups.list_volumes(group['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "16939b57", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': '10c632bd-f145-4631-b7bf-5ba8974339c4'}" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Delete the group by id\n", + "\n", + "ph.admin.groups.delete(group['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "0def952c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'pv-volume-by-sdk'}" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Delete the volume\n", + "\n", + "ph.admin.volumes.delete(volume['id'])" + ] + } + ], + "metadata": { + "interpreter": { + "hash": "6688a3817b6a9bf9af7edfccc04ec9238693f1be61c239ce0c4444a70d9a5fed" + }, + "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/notebook/admin-portal/02-users.ipynb b/docs/notebook/admin-portal/02-users.ipynb new file mode 100644 index 00000000..a2b52d07 --- /dev/null +++ b/docs/notebook/admin-portal/02-users.ipynb @@ -0,0 +1,829 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "98d093ab", + "metadata": {}, + "source": [ + "# [admin] Users command\n", + "\n", + "\n", + "The `users` command in `admin` scope could help you manage users.\n" + ] + }, + { + "cell_type": "markdown", + "id": "8332f76b", + "metadata": {}, + "source": [ + "## Setup PrimeHub Python SDK\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "b1ee0b97", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PrimeHub Python SDK setup successfully\n" + ] + } + ], + "source": [ + "from primehub import PrimeHub, PrimeHubConfig\n", + "ph = PrimeHub(PrimeHubConfig())\n", + "\n", + "if ph.is_ready():\n", + " print(\"PrimeHub Python SDK setup successfully\")\n", + "else:\n", + " print(\"PrimeHub Python SDK couldn't get the group information, follow the 00-getting-started.ipynb to complete it\")" + ] + }, + { + "cell_type": "markdown", + "id": "86e0b2c6", + "metadata": {}, + "source": [ + "## Help documentation" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "bff46e93", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on AdminUsers in module primehub.admin_users object:\n", + "\n", + "class AdminUsers(primehub.Helpful, primehub.Module)\n", + " | AdminUsers(primehub: primehub.PrimeHub, **kwargs)\n", + " | \n", + " | Method resolution order:\n", + " | AdminUsers\n", + " | primehub.Helpful\n", + " | primehub.Module\n", + " | primehub.HTTPSupport\n", + " | builtins.object\n", + " | \n", + " | Methods defined here:\n", + " | \n", + " | add_group(self, id: str, group_id)\n", + " | Add group connection to a user by id\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of a user\n", + " | :type group_id: str\n", + " | :param group_id: group id\n", + " | \n", + " | :rtype dict\n", + " | :return a user with groups only\n", + " | \n", + " | create(self, config)\n", + " | Create a user\n", + " | \n", + " | :type config: dict\n", + " | :param config: The configurations for creating a user\n", + " | \n", + " | :rtype dict\n", + " | :return The user\n", + " | \n", + " | delete(self, id: str) -> dict\n", + " | Delete an user by id\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of the user\n", + " | \n", + " | :rtype dict\n", + " | :return the user\n", + " | \n", + " | get(self, id: str) -> dict\n", + " | Get an user by id\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of an user\n", + " | \n", + " | :rtype dict\n", + " | :return the user\n", + " | \n", + " | help_description(self)\n", + " | one line description for all commands\n", + " | \n", + " | list(self, **kwargs) -> Iterator\n", + " | List users\n", + " | \n", + " | :type page: int\n", + " | :param page: the page of all data\n", + " | \n", + " | :rtype Iterator\n", + " | :return user iterator\n", + " | \n", + " | list_groups(self, id: str)\n", + " | List groups of a user by id\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of a user\n", + " | \n", + " | :rtype list\n", + " | :return groups\n", + " | \n", + " | remove_group(self, id: str, group_id)\n", + " | Remove group connection from a user by id\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of a user\n", + " | :type group_id: str\n", + " | :param group_id: group id\n", + " | \n", + " | :rtype dict\n", + " | :return a user with groups only\n", + " | \n", + " | reset_password(self, id: str, password: str, **kwargs) -> dict\n", + " | Reset password by id\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of the user\n", + " | \n", + " | :type id: str\n", + " | :param id: password\n", + " | \n", + " | :type temporary: bool\n", + " | :param temporary: make the password temporary\n", + " | \n", + " | :rtype dict\n", + " | :return the user\n", + " | \n", + " | update(self, id: str, config: dict)\n", + " | Update the user\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of the user\n", + " | \n", + " | :rtype: dict\n", + " | :returns: the user\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data and other attributes defined here:\n", + " | \n", + " | __abstractmethods__ = frozenset()\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors inherited from primehub.Helpful:\n", + " | \n", + " | __dict__\n", + " | dictionary for instance variables (if defined)\n", + " | \n", + " | __weakref__\n", + " | list of weak references to the object (if defined)\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Methods inherited from primehub.Module:\n", + " | \n", + " | __init__(self, primehub: primehub.PrimeHub, **kwargs)\n", + " | Initialize self. See help(type(self)) for accurate signature.\n", + " | \n", + " | display(self, action: dict, value: Any)\n", + " | \n", + " | get_display(self) -> primehub.utils.display.Displayable\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Static methods inherited from primehub.Module:\n", + " | \n", + " | output(result: dict, object_path: str)\n", + " | Give a dict {'data': {'a': {'b': 'c'}}}\n", + " | we could get the c by the path a.b\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors inherited from primehub.Module:\n", + " | \n", + " | current_group\n", + " | \n", + " | endpoint\n", + " | \n", + " | group_id\n", + " | \n", + " | group_name\n", + " | \n", + " | primehub_config\n", + "\n" + ] + } + ], + "source": [ + "help(ph.admin.users)" + ] + }, + { + "cell_type": "markdown", + "id": "92b69c96", + "metadata": {}, + "source": [ + "## User management" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "669a5261", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Usage: \n", + " primehub admin users \n", + "\n", + "Manage users\n", + "\n", + "Available Commands:\n", + " add-group Add group connection to a user by id\n", + " create Create a user\n", + " delete Delete an user by id\n", + " get Get an user by id\n", + " list List users\n", + " list-groups List groups of a user by id\n", + " remove-group Remove group connection from a user by id\n", + " reset-password Reset password by id\n", + " update Update the user\n", + "\n", + "Options:\n", + " -h, --help Show the help\n", + "\n", + "Global Options:\n", + " --config CONFIG Change the path of the config file (Default: ~/.primehub/config.json)\n", + " --endpoint ENDPOINT Override the GraphQL API endpoint\n", + " --token TOKEN Override the API Token\n", + " --group GROUP Override the current group\n", + " --json Output the json format (output human-friendly format by default)\n" + ] + } + ], + "source": [ + "!primehub admin users help" + ] + }, + { + "cell_type": "markdown", + "id": "6dd36d73", + "metadata": {}, + "source": [ + "For `create` and `update` actions are needed a configuration to mutate a user. Here is the fields table:\n", + "\n", + "\n", + "### Fields\n", + "\n", + "| field | required | type | description |\n", + "| --- | --- | --- | --- |\n", + "| username | required | string | lower case alphanumeric characters, '-', '.', and underscores (\"_\") are allowed, and must start with a letter or numeric.` |\n", + "| email | optional | string | a valid email |\n", + "| firstName | optional | string | |\n", + "| lastName | optional | string | |\n", + "| isAdmin | optional | boolean | grant the administrator role to the user |\n", + "| volumeCapacity | optional | int | customize the size of the user volume. unit: `GB`|\n", + "| groups | optional | assign the user to groups | please see the `connect` examples |\n", + "\n", + "These fields are only used with email activation (only for `create`):\n", + "\n", + "| field | required | type | description |\n", + "| --- | --- | --- | --- |\n", + "| sendEmail | optional | boolean | send an activation email to the user. (it worked if the smtp was set)|\n", + "| resetActions.set | optional | string[] | ask for actions, valid actions: `['VERIFY_EMAIL', 'UPDATE_PASSWORD']` |\n", + "| expiresIn | optional | int | expired duration for the activation email |\n" + ] + }, + { + "cell_type": "markdown", + "id": "20cd60b9", + "metadata": {}, + "source": [ + "## Examples" + ] + }, + { + "cell_type": "markdown", + "id": "a96338c5", + "metadata": {}, + "source": [ + "You could find [more examples on our github](https://github.com/InfuseAI/primehub-python-sdk/blob/main/docs/CLI/admin/users.md)." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "55b19105", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "id": "85e1005e", + "metadata": {}, + "source": [ + "#### CRUD: User" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "7681961b", + "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", + " },\n", + " \"isAdmin\": True\n", + "}\n", + "data = ph.admin.users.create(config)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "d178dcd4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idusernameemailfirstNamelastNameenabledisAdmin
2001711a38-da60-4840-91e0-68094105502fuser-admin-from-jupyterNoneNoneNoneTrueTrue
\n", + "
" + ], + "text/plain": [ + " id username email \\\n", + "20 01711a38-da60-4840-91e0-68094105502f user-admin-from-jupyter None \n", + "\n", + " firstName lastName enabled isAdmin \n", + "20 None None True True " + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# List users\n", + "user_df = pd.DataFrame(ph.admin.users.list())\n", + "user_df[user_df['username'] == config['username']]" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "b67e984b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': '01711a38-da60-4840-91e0-68094105502f',\n", + " 'username': 'user-admin-from-jupyter',\n", + " 'email': None,\n", + " 'firstName': None,\n", + " 'lastName': None,\n", + " 'enabled': True,\n", + " 'isAdmin': True,\n", + " 'volumeCapacity': None,\n", + " 'groups': [{'id': '0449b887-5c40-44ba-a945-41bc21c8d15a',\n", + " 'name': 'InfuseAI',\n", + " 'displayName': 'InfuseAI',\n", + " 'quotaCpu': 6,\n", + " 'quotaGpu': 2}]}" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Get the user details\n", + "ph.admin.users.get(data['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "e4ead361", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': '01711a38-da60-4840-91e0-68094105502f',\n", + " 'username': 'user-admin-from-jupyter',\n", + " 'email': None,\n", + " 'firstName': None,\n", + " 'lastName': None,\n", + " 'enabled': True,\n", + " 'isAdmin': False,\n", + " 'volumeCapacity': None,\n", + " 'groups': [{'id': '0449b887-5c40-44ba-a945-41bc21c8d15a',\n", + " 'name': 'InfuseAI',\n", + " 'displayName': 'InfuseAI',\n", + " 'quotaCpu': 6,\n", + " 'quotaGpu': 2}]}" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Update the user config setting.\n", + "update_config = {\"isAdmin\": False}\n", + "data = ph.admin.users.update(data['id'], update_config)\n", + "ph.admin.users.get(data['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "ceeb58be", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': '01711a38-da60-4840-91e0-68094105502f'}" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# reset_password\n", + "ph.admin.users.reset_password(id=data['id'], password=\"test_reset_password\", temporary=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "eb03657b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': '01711a38-da60-4840-91e0-68094105502f',\n", + " 'username': 'user-admin-from-jupyter'}" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Delete the user\n", + "ph.admin.users.delete(data['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "419e6d81", + "metadata": {}, + "source": [ + "#### CRUD: User <-> Group" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "6638468d", + "metadata": {}, + "outputs": [], + "source": [ + "# Create a user with admin role\n", + "config = {\n", + " \"username\": \"user-admin-from-jupyter-group\",\n", + " \"groups\": {\n", + " \"connect\": [\n", + " {\n", + " \"id\": ph.group_id\n", + " }\n", + " ]\n", + " },\n", + " \"isAdmin\": True\n", + "}\n", + "data = ph.admin.users.create(config)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "905f59c1", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idnamedisplayName
00449b887-5c40-44ba-a945-41bc21c8d15aInfuseAIInfuseAI
\n", + "
" + ], + "text/plain": [ + " id name displayName\n", + "0 0449b887-5c40-44ba-a945-41bc21c8d15a InfuseAI InfuseAI" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Show the user group list\n", + "\n", + "user_group_df = pd.DataFrame(ph.admin.users.list_groups(data[\"id\"]))\n", + "user_group_df" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "4ef09007", + "metadata": {}, + "outputs": [], + "source": [ + "# Add the user into group\n", + "groups_df = pd.DataFrame(ph.admin.groups.list())\n", + "groups_id = groups_df[\"id\"][0]\n", + "ph.admin.users.add_group(data[\"id\"], groups_id)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "7a0ef44f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idnamedisplayName
071ac1e32-65fa-4e8e-a735-ba282e3149b1AnotherTestGroupAnother Test Group
10449b887-5c40-44ba-a945-41bc21c8d15aInfuseAIInfuseAI
\n", + "
" + ], + "text/plain": [ + " id name displayName\n", + "0 71ac1e32-65fa-4e8e-a735-ba282e3149b1 AnotherTestGroup Another Test Group\n", + "1 0449b887-5c40-44ba-a945-41bc21c8d15a InfuseAI InfuseAI" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Show the user group list\n", + "\n", + "user_group_df = pd.DataFrame(ph.admin.users.list_groups(data[\"id\"]))\n", + "user_group_df" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "772962c2", + "metadata": {}, + "outputs": [], + "source": [ + "# Remove the user out of group\n", + "ph.admin.users.remove_group(data[\"id\"], groups_id)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "ca943be3", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idnamedisplayName
00449b887-5c40-44ba-a945-41bc21c8d15aInfuseAIInfuseAI
\n", + "
" + ], + "text/plain": [ + " id name displayName\n", + "0 0449b887-5c40-44ba-a945-41bc21c8d15a InfuseAI InfuseAI" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Show the user group list\n", + "\n", + "user_group_df = pd.DataFrame(ph.admin.users.list_groups(data[\"id\"]))\n", + "user_group_df" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "486f0c4f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': '29541eb1-42cd-4b94-ac93-04d798986885',\n", + " 'username': 'user-admin-from-jupyter-group'}" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Delete the user\n", + "ph.admin.users.delete(data['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/notebook/admin-portal/03-instancetypes.ipynb b/docs/notebook/admin-portal/03-instancetypes.ipynb new file mode 100644 index 00000000..cdcee5a4 --- /dev/null +++ b/docs/notebook/admin-portal/03-instancetypes.ipynb @@ -0,0 +1,757 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "e4a450cc", + "metadata": {}, + "source": [ + "# [admin] Instancetypes command\n", + "\n", + "\n", + "The `instancetypes` command in `admin` scope could help you manage instancetypes.\n" + ] + }, + { + "cell_type": "markdown", + "id": "a8cc7ae7", + "metadata": {}, + "source": [ + "## Setup PrimeHub Python SDK\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "a2cca202", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PrimeHub Python SDK setup successfully\n" + ] + } + ], + "source": [ + "from primehub import PrimeHub, PrimeHubConfig\n", + "ph = PrimeHub(PrimeHubConfig())\n", + "\n", + "if ph.is_ready():\n", + " print(\"PrimeHub Python SDK setup successfully\")\n", + "else:\n", + " print(\"PrimeHub Python SDK couldn't get the group information, follow the 00-getting-started.ipynb to complete it\")" + ] + }, + { + "cell_type": "markdown", + "id": "4985c74c", + "metadata": {}, + "source": [ + "## Help documentation" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "c689b716", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on AdminInstanceTypes in module primehub.admin_instancetypes object:\n", + "\n", + "class AdminInstanceTypes(primehub.Helpful, primehub.Module)\n", + " | AdminInstanceTypes(primehub: primehub.PrimeHub, **kwargs)\n", + " | \n", + " | Method resolution order:\n", + " | AdminInstanceTypes\n", + " | primehub.Helpful\n", + " | primehub.Module\n", + " | primehub.HTTPSupport\n", + " | builtins.object\n", + " | \n", + " | Methods defined here:\n", + " | \n", + " | add_group(self, id: str, group_id)\n", + " | Add group connection to an instance type by id.\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of an instance type\n", + " | :type group_id: str\n", + " | :param group_id: group id\n", + " | \n", + " | :rtype dict\n", + " | :return an instance type with groups only\n", + " | \n", + " | create(self, config)\n", + " | Create an instance type\n", + " | \n", + " | :type config: dict\n", + " | :param config: The configurations for creating an instance type\n", + " | \n", + " | :rtype dict\n", + " | :return The instance type\n", + " | \n", + " | delete(self, id)\n", + " | Delete an instance type by id\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of an instance type\n", + " | \n", + " | :rtype dict\n", + " | :return an instance type\n", + " | \n", + " | get(self, id: str) -> dict\n", + " | Get an instance type by id\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of an instance type\n", + " | \n", + " | :rtype dict\n", + " | :return an instance type\n", + " | \n", + " | help_description(self)\n", + " | one line description for all commands\n", + " | \n", + " | list(self, **kwargs) -> Iterator\n", + " | List instance type\n", + " | \n", + " | :type page: int\n", + " | :param page: the page of all data\n", + " | \n", + " | :rtype Iterator\n", + " | :return instance type iterator\n", + " | \n", + " | list_groups(self, id: str)\n", + " | List groups of an instance type by id. It will return empty list if the instance type is at the global scope.\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of an instance type\n", + " | \n", + " | :rtype list\n", + " | :return groups\n", + " | \n", + " | remove_group(self, id: str, group_id)\n", + " | Remove group connection from an instance type by id.\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of an instance type\n", + " | :type group_id: str\n", + " | :param group_id: group id\n", + " | \n", + " | :rtype dict\n", + " | :return an instance type with groups only\n", + " | \n", + " | update(self, id: str, config: dict)\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data and other attributes defined here:\n", + " | \n", + " | __abstractmethods__ = frozenset()\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors inherited from primehub.Helpful:\n", + " | \n", + " | __dict__\n", + " | dictionary for instance variables (if defined)\n", + " | \n", + " | __weakref__\n", + " | list of weak references to the object (if defined)\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Methods inherited from primehub.Module:\n", + " | \n", + " | __init__(self, primehub: primehub.PrimeHub, **kwargs)\n", + " | Initialize self. See help(type(self)) for accurate signature.\n", + " | \n", + " | display(self, action: dict, value: Any)\n", + " | \n", + " | get_display(self) -> primehub.utils.display.Displayable\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Static methods inherited from primehub.Module:\n", + " | \n", + " | output(result: dict, object_path: str)\n", + " | Give a dict {'data': {'a': {'b': 'c'}}}\n", + " | we could get the c by the path a.b\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors inherited from primehub.Module:\n", + " | \n", + " | current_group\n", + " | \n", + " | endpoint\n", + " | \n", + " | group_id\n", + " | \n", + " | group_name\n", + " | \n", + " | primehub_config\n", + "\n" + ] + } + ], + "source": [ + "help(ph.admin.instancetypes)" + ] + }, + { + "cell_type": "markdown", + "id": "1f094faa", + "metadata": {}, + "source": [ + "## InstanceTypes management" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "8e1ffe49", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Usage: \n", + " primehub admin instancetypes \n", + "\n", + "Manage instance type\n", + "\n", + "Available Commands:\n", + " add-group Add group connection to an instance type by id\n", + " create Create an instance type\n", + " delete Delete an instance type by id\n", + " get Get an instance type by id\n", + " list List instance type\n", + " list-groups List groups of an instance type by id\n", + " remove-group Remove group connection from an instance type by id\n", + " update Update the instance type\n", + "\n", + "Options:\n", + " -h, --help Show the help\n", + "\n", + "Global Options:\n", + " --config CONFIG Change the path of the config file (Default: ~/.primehub/config.json)\n", + " --endpoint ENDPOINT Override the GraphQL API endpoint\n", + " --token TOKEN Override the API Token\n", + " --group GROUP Override the current group\n", + " --json Output the json format (output human-friendly format by default)\n" + ] + } + ], + "source": [ + "!primehub admin instancetypes help" + ] + }, + { + "cell_type": "markdown", + "id": "3fbba456", + "metadata": {}, + "source": [ + "### Fields for creating or updating\n", + "\n", + "| field | required | type | description |\n", + "| --- | --- | --- | --- |\n", + "| name | required | string | it should be a valid resource name for kubernetes. `name` will be ignored when updating |\n", + "| displayName | optional | string | display name for the instance type |\n", + "| description | optional | string | |\n", + "| global | optional | boolean | when an instance type is global, it could be seen for each group |\n", + "| groups | optional | list of connected groups (dict) | please see the `connect` examples. default value: false |\n", + "| cpuLimit | required* | float | the maximum vCPU quantity. For example: `1` or `1.0` means 1 vCPU and `0.5` means half of vCPU |\n", + "| cpuRequest | optional | float | the initial vCPU quantity for CPU resource. cpuRequest can not be greater than cpuLimit |\n", + "| memoryLimit | required* | float | the maximum Memory size. For example: `1.5` means `1.5 GB` memory |\n", + "| memoryRequest | optional | float | the initial Memory size. memoryRequest can not be greater than memoryLimit |\n", + "| gpuLimit | optional | int | the count of GPU when an instance allocated |\n", + "| tolerations | optional | dict | kubernetes pod toleration in an instance (Pod) |\n", + "| nodeSelector | optional | dict | kubernetes pod nodeSelector in an instance (Pod) |\n", + "\n", + "#### Auto-filling Fields\n", + "Auto-filling will happen when the configuration omitted fields\n", + "\n", + "| field\t| value\t| description |\n", + "| --- | --- | --- |\n", + "| cpuLimit\t| 1\t| 1 vCPU |\n", + "| memoryLimit\t| 1\t| 1 GB memory |\n" + ] + }, + { + "cell_type": "markdown", + "id": "8b436c4b", + "metadata": {}, + "source": [ + "## Examples" + ] + }, + { + "cell_type": "markdown", + "id": "6f80e791", + "metadata": {}, + "source": [ + "You could find [more examples on our github](https://github.com/InfuseAI/primehub-python-sdk/blob/main/docs/CLI/admin/instancetypes.md)." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "9a24c0c7", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "id": "336080a3", + "metadata": {}, + "source": [ + "#### CRUD: instance type" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "0b51010b", + "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", + " \"gpuLimit\": 0,\n", + " \"global\": True\n", + "}\n", + "data = ph.admin.instancetypes.create(config)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "3f095cc6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idnamedisplayNamedescriptioncpuLimitmemoryLimitgpuLimit
6cpu-instance-by-sdkcpu-instance-by-sdkCPU 11 vCPU / 1G Memory1.010
\n", + "
" + ], + "text/plain": [ + " id name displayName description \\\n", + "6 cpu-instance-by-sdk cpu-instance-by-sdk CPU 1 1 vCPU / 1G Memory \n", + "\n", + " cpuLimit memoryLimit gpuLimit \n", + "6 1.0 1 0 " + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# List users\n", + "instance_type_df = pd.DataFrame(ph.admin.instancetypes.list())\n", + "instance_type_df[instance_type_df['name'] == config['name']]" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "caf6fb80", + "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": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# get deatils by id\n", + "ph.admin.instancetypes.get(data['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "bfbf1a5d", + "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': {},\n", + " 'name': 'cpu-instance-by-sdk',\n", + " 'displayName': 'CPU 1',\n", + " 'description': '1 vCPU / 1G Memory',\n", + " 'cpuLimit': 1,\n", + " 'memoryLimit': 2,\n", + " 'gpuLimit': 0}" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Update the user config setting.\n", + "update_config = {\"memoryLimit\": 2}\n", + "data = ph.admin.instancetypes.update(data['id'], update_config)\n", + "ph.admin.instancetypes.get(data['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "868ab9a0", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'cpu-instance-by-sdk'}" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# delete the instance type\n", + "ph.admin.instancetypes.delete(data['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "748e57d7", + "metadata": {}, + "source": [ + "#### CRUD: instance type <-> Group" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "5c96b542", + "metadata": {}, + "outputs": [], + "source": [ + "# create an instance type\n", + "config = {\n", + " \"name\": \"cpu-instance-by-sdk-group\",\n", + " \"displayName\": \"CPU 1\",\n", + " \"description\": \"1 vCPU / 1G Memory\",\n", + " \"cpuLimit\": 1,\n", + " \"memoryLimit\": 1,\n", + " \"gpuLimit\": 0,\n", + " \"global\": False\n", + "}\n", + "data = ph.admin.instancetypes.create(config)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "43e8e78a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
" + ], + "text/plain": [ + "Empty DataFrame\n", + "Columns: []\n", + "Index: []" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Show the instance type group list\n", + "\n", + "instance_type_group_df = pd.DataFrame(ph.admin.instancetypes.list_groups(data[\"id\"]))\n", + "instance_type_group_df" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "2b546baa", + "metadata": {}, + "outputs": [], + "source": [ + "# Add the instance type into group\n", + "groups_df = pd.DataFrame(ph.admin.groups.list())\n", + "groups_id = groups_df[\"id\"][0]\n", + "ph.admin.instancetypes.add_group(data[\"id\"], groups_id)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "de391154", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idnamedisplayName
071ac1e32-65fa-4e8e-a735-ba282e3149b1AnotherTestGroupAnother Test Group
\n", + "
" + ], + "text/plain": [ + " id name displayName\n", + "0 71ac1e32-65fa-4e8e-a735-ba282e3149b1 AnotherTestGroup Another Test Group" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Show the instance type group list\n", + "\n", + "user_group_df = pd.DataFrame(ph.admin.instancetypes.list_groups(data[\"id\"]))\n", + "user_group_df" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "09861e10", + "metadata": {}, + "outputs": [], + "source": [ + "# Remove the instance type out of group\n", + "ph.admin.instancetypes.remove_group(data[\"id\"], groups_id)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "f6f8c19f", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
" + ], + "text/plain": [ + "Empty DataFrame\n", + "Columns: []\n", + "Index: []" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Show the instance type group list\n", + "\n", + "user_group_df = pd.DataFrame(ph.admin.instancetypes.list_groups(data[\"id\"]))\n", + "user_group_df" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "a5a222af", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'cpu-instance-by-sdk-group'}" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Delete the instance type\n", + "ph.admin.instancetypes.delete(data['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/notebook/admin-portal/04-images.ipynb b/docs/notebook/admin-portal/04-images.ipynb new file mode 100644 index 00000000..f596d593 --- /dev/null +++ b/docs/notebook/admin-portal/04-images.ipynb @@ -0,0 +1,751 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "6c0774fa", + "metadata": {}, + "source": [ + "# [admin] Images command\n", + "\n", + "\n", + "The `images` command in `admin` scope could help you manage images.\n" + ] + }, + { + "cell_type": "markdown", + "id": "a685aa5a", + "metadata": {}, + "source": [ + "## Setup PrimeHub Python SDK\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "c3ef3937", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PrimeHub Python SDK setup successfully\n" + ] + } + ], + "source": [ + "from primehub import PrimeHub, PrimeHubConfig\n", + "ph = PrimeHub(PrimeHubConfig())\n", + "\n", + "if ph.is_ready():\n", + " print(\"PrimeHub Python SDK setup successfully\")\n", + "else:\n", + " print(\"PrimeHub Python SDK couldn't get the group information, follow the 00-getting-started.ipynb to complete it\")" + ] + }, + { + "cell_type": "markdown", + "id": "cfe89ae1", + "metadata": {}, + "source": [ + "## Help documentation" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "87e0c69f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on AdminImages in module primehub.admin_images object:\n", + "\n", + "class AdminImages(primehub.Helpful, primehub.Module)\n", + " | AdminImages(primehub: primehub.PrimeHub, **kwargs)\n", + " | \n", + " | Method resolution order:\n", + " | AdminImages\n", + " | primehub.Helpful\n", + " | primehub.Module\n", + " | primehub.HTTPSupport\n", + " | builtins.object\n", + " | \n", + " | Methods defined here:\n", + " | \n", + " | add_group(self, id: str, group_id)\n", + " | Add group connection to an image by id.\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of an image\n", + " | :type group_id: str\n", + " | :param group_id: group id\n", + " | \n", + " | :rtype dict\n", + " | :return an image with groups only\n", + " | \n", + " | create(self, config)\n", + " | Create an image\n", + " | \n", + " | :type config: dict\n", + " | :param config: The configurations for creating an image\n", + " | \n", + " | :rtype dict\n", + " | :return The image\n", + " | \n", + " | delete(self, id)\n", + " | Delete an image by id\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of an image\n", + " | \n", + " | :rtype dict\n", + " | :return an image\n", + " | \n", + " | get(self, id: str) -> dict\n", + " | Get an image by id\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of an image\n", + " | \n", + " | :rtype dict\n", + " | :return an image\n", + " | \n", + " | help_description(self)\n", + " | one line description for all commands\n", + " | \n", + " | list(self, **kwargs) -> Iterator\n", + " | List images\n", + " | \n", + " | :type page: int\n", + " | :param page: the page of all data\n", + " | \n", + " | :rtype Iterator\n", + " | :return image iterator\n", + " | \n", + " | list_groups(self, id: str)\n", + " | List groups of an image by id. It will return empty list if the image is at the global scope.\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of an image\n", + " | \n", + " | :rtype list\n", + " | :return groups\n", + " | \n", + " | remove_group(self, id: str, group_id)\n", + " | Remove group connection from an image by id.\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of an image\n", + " | :type group_id: str\n", + " | :param group_id: group id\n", + " | \n", + " | :rtype dict\n", + " | :return an image with groups only\n", + " | \n", + " | update(self, id: str, config: dict)\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data and other attributes defined here:\n", + " | \n", + " | __abstractmethods__ = frozenset()\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors inherited from primehub.Helpful:\n", + " | \n", + " | __dict__\n", + " | dictionary for instance variables (if defined)\n", + " | \n", + " | __weakref__\n", + " | list of weak references to the object (if defined)\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Methods inherited from primehub.Module:\n", + " | \n", + " | __init__(self, primehub: primehub.PrimeHub, **kwargs)\n", + " | Initialize self. See help(type(self)) for accurate signature.\n", + " | \n", + " | display(self, action: dict, value: Any)\n", + " | \n", + " | get_display(self) -> primehub.utils.display.Displayable\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Static methods inherited from primehub.Module:\n", + " | \n", + " | output(result: dict, object_path: str)\n", + " | Give a dict {'data': {'a': {'b': 'c'}}}\n", + " | we could get the c by the path a.b\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors inherited from primehub.Module:\n", + " | \n", + " | current_group\n", + " | \n", + " | endpoint\n", + " | \n", + " | group_id\n", + " | \n", + " | group_name\n", + " | \n", + " | primehub_config\n", + "\n" + ] + } + ], + "source": [ + "help(ph.admin.images)" + ] + }, + { + "cell_type": "markdown", + "id": "d413779c", + "metadata": {}, + "source": [ + "## Images management" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "2e67f9d2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Usage: \n", + " primehub admin images \n", + "\n", + "Manage images\n", + "\n", + "Available Commands:\n", + " add-group Add group connection to an image by id\n", + " create Create an image\n", + " delete Delete an image by id\n", + " get Get an image by id\n", + " list List images\n", + " list-groups List groups of an image by id\n", + " remove-group Remove group connection from an image by id\n", + " update Update the image\n", + "\n", + "Options:\n", + " -h, --help Show the help\n", + "\n", + "Global Options:\n", + " --config CONFIG Change the path of the config file (Default: ~/.primehub/config.json)\n", + " --endpoint ENDPOINT Override the GraphQL API endpoint\n", + " --token TOKEN Override the API Token\n", + " --group GROUP Override the current group\n", + " --json Output the json format (output human-friendly format by default)\n" + ] + } + ], + "source": [ + "!primehub admin images help" + ] + }, + { + "cell_type": "markdown", + "id": "939bf77e", + "metadata": {}, + "source": [ + "### Fields for creating or updating\n", + "\n", + "| field | required | type | description |\n", + "| --- | --- | --- | --- |\n", + "| name | required | string | it should be a valid resource name for kubernetes. `name` will be ignored when updating |\n", + "| displayName | optional | string | |\n", + "| description | optional | string | |\n", + "| type | optional | string | one of ['cpu', 'gpu', 'both'], default value: 'both' |\n", + "| global | optional | boolean | |\n", + "| groups | optional | object | |\n", + "| url | optional | string | container image url |\n", + "| urlForGpu | optional | string | container image url for GPU optimized |\n", + "| imageSpec | optional | object | the specification for customization |\n", + "| useImagePullSecret | optional | string | the id of a secret |\n", + "\n", + "*Note: imageSpec cannot use with url and urlForGpu*\n" + ] + }, + { + "cell_type": "markdown", + "id": "c37e1a5b", + "metadata": {}, + "source": [ + "## Examples" + ] + }, + { + "cell_type": "markdown", + "id": "477b8bd2", + "metadata": {}, + "source": [ + "You could find [more examples on our github](https://github.com/InfuseAI/primehub-python-sdk/blob/main/docs/CLI/admin/images.md)." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "a9dfc2fe", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "id": "e960389b", + "metadata": {}, + "source": [ + "#### CRUD: Jupyter environment images" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "eee37f8e", + "metadata": {}, + "outputs": [], + "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", + "}\n", + "\n", + "data = ph.admin.images.create(config)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "d12b2674", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idnamedisplayNamedescriptiontypeisReady
8image-by-sdkimage-by-sdkLearning how to create an image from SDKbase-notebook with python 3.7bothTrue
\n", + "
" + ], + "text/plain": [ + " id name displayName \\\n", + "8 image-by-sdk image-by-sdk Learning how to create an image from SDK \n", + "\n", + " description type isReady \n", + "8 base-notebook with python 3.7 both True " + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# List images\n", + "images_df = pd.DataFrame(ph.admin.images.list())\n", + "images_df[images_df['name'] == config['name']]" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "d20403a2", + "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': '',\n", + " 'global': True,\n", + " 'groups': [],\n", + " 'isReady': True,\n", + " 'imageSpec': None,\n", + " 'jobStatus': None,\n", + " 'logEndpoint': 'https://c.demo.primehub.io/api/logs/images/image-by-sdk/job'}" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Get the image details\n", + "ph.admin.images.get(data['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "269a80c9", + "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': [],\n", + " 'isReady': True,\n", + " 'imageSpec': None,\n", + " 'jobStatus': None,\n", + " 'logEndpoint': 'https://c.demo.primehub.io/api/logs/images/image-by-sdk/job'}" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Update the image config setting.\n", + "update_config = {'global': False}\n", + "data = ph.admin.images.update(data['id'], update_config)\n", + "ph.admin.images.get(data['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "888dfb18", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'image-by-sdk'}" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Delete the image\n", + "ph.admin.images.delete(data['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "6b411190", + "metadata": {}, + "source": [ + "#### CRUD: image <-> Group" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "bbcd07c4", + "metadata": {}, + "outputs": [], + "source": [ + "# Create an image\n", + "config = {\n", + " \"name\": \"image-by-sdk-group\",\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\": False\n", + "}\n", + "\n", + "data = ph.admin.images.create(config)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "e299d4c6", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
" + ], + "text/plain": [ + "Empty DataFrame\n", + "Columns: []\n", + "Index: []" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Show the image group list\n", + "\n", + "images_df = pd.DataFrame(ph.admin.images.list_groups(data[\"id\"]))\n", + "images_df" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "d7d59c74", + "metadata": {}, + "outputs": [], + "source": [ + "# Add the image into group\n", + "groups_df = pd.DataFrame(ph.admin.groups.list())\n", + "groups_id = groups_df[\"id\"][0]\n", + "ph.admin.images.add_group(data[\"id\"], groups_id)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "d7567728", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idnamedisplayName
071ac1e32-65fa-4e8e-a735-ba282e3149b1AnotherTestGroupAnother Test Group
\n", + "
" + ], + "text/plain": [ + " id name displayName\n", + "0 71ac1e32-65fa-4e8e-a735-ba282e3149b1 AnotherTestGroup Another Test Group" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Show the image group list\n", + "\n", + "images_df = pd.DataFrame(ph.admin.images.list_groups(data[\"id\"]))\n", + "images_df" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "44c4841f", + "metadata": {}, + "outputs": [], + "source": [ + "# Remove the image out of group\n", + "ph.admin.images.remove_group(data[\"id\"], groups_id)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "689f0378", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
" + ], + "text/plain": [ + "Empty DataFrame\n", + "Columns: []\n", + "Index: []" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Show the image group list\n", + "\n", + "images_df = pd.DataFrame(ph.admin.images.list_groups(data[\"id\"]))\n", + "images_df" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "1ecfe8fb", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'image-by-sdk-group'}" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Delete the image\n", + "ph.admin.images.delete(data['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/notebook/admin-portal/05-volumes.ipynb b/docs/notebook/admin-portal/05-volumes.ipynb new file mode 100644 index 00000000..58820694 --- /dev/null +++ b/docs/notebook/admin-portal/05-volumes.ipynb @@ -0,0 +1,815 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "43fa6341", + "metadata": {}, + "source": [ + "# [admin] Volumes command\n", + "\n", + "\n", + "The `volumes` command in `admin` scope could help you manage volumes.\n" + ] + }, + { + "cell_type": "markdown", + "id": "409f870b", + "metadata": {}, + "source": [ + "## Setup PrimeHub Python SDK\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "d5ff3ca5", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PrimeHub Python SDK setup successfully\n" + ] + } + ], + "source": [ + "from primehub import PrimeHub, PrimeHubConfig\n", + "ph = PrimeHub(PrimeHubConfig())\n", + "\n", + "if ph.is_ready():\n", + " print(\"PrimeHub Python SDK setup successfully\")\n", + "else:\n", + " print(\"PrimeHub Python SDK couldn't get the group information, follow the 00-getting-started.ipynb to complete it\")" + ] + }, + { + "cell_type": "markdown", + "id": "f1beae31", + "metadata": {}, + "source": [ + "## Help documentation" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "2ba16f28", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on AdminVolumes in module primehub.admin_volumes object:\n", + "\n", + "class AdminVolumes(primehub.Helpful, primehub.Module)\n", + " | AdminVolumes(primehub: primehub.PrimeHub, **kwargs)\n", + " | \n", + " | Method resolution order:\n", + " | AdminVolumes\n", + " | primehub.Helpful\n", + " | primehub.Module\n", + " | primehub.HTTPSupport\n", + " | builtins.object\n", + " | \n", + " | Methods defined here:\n", + " | \n", + " | add_group(self, id: str, group_id, writable=False)\n", + " | Add group connection to a volume by id\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of a volume\n", + " | :type group_id: str\n", + " | :param group_id: group id\n", + " | :type writable: bool, optional\n", + " | :param writable: `True` if the group has write permission to the volume, and `False` otherwise, defaults to False\n", + " | \n", + " | :rtype dict\n", + " | :return a volume with id only\n", + " | \n", + " | create(self, config) -> list\n", + " | Create a volume\n", + " | \n", + " | :rtype: dict\n", + " | :returns: the volume\n", + " | \n", + " | delete(self, id)\n", + " | Delete a volume by id\n", + " | \n", + " | :type id: str\n", + " | :param id: The volume id\n", + " | \n", + " | :rtype dict\n", + " | :return the result of the deleted volume\n", + " | \n", + " | get(self, name) -> Union[dict, NoneType]\n", + " | Get a volume from the current group\n", + " | \n", + " | :type name: str\n", + " | :param name: the name of a volume\n", + " | \n", + " | :rtype: Optional[dict]\n", + " | :returns: a volume\n", + " | \n", + " | help_description(self)\n", + " | one line description for all commands\n", + " | \n", + " | list(self, **kwargs)\n", + " | \n", + " | list_groups(self, id: str)\n", + " | List groups of a volume by id. It will return writable groups only if the volume is at the global scope.\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of a volume\n", + " | \n", + " | :rtype list\n", + " | :return groups\n", + " | \n", + " | regenerate_upload_server_secret(self, id)\n", + " | Regenerate the secret of the upload server\n", + " | \n", + " | :type id: str\n", + " | :param id: The volume id or name\n", + " | \n", + " | :rtype dict\n", + " | :return the result of the deleted volume\n", + " | \n", + " | remove_group(self, id: str, group_id)\n", + " | Remove group connection from a volume by id\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of a volume\n", + " | :type group_id: str\n", + " | :param group_id: group id\n", + " | \n", + " | :rtype dict\n", + " | :return a volume with id only\n", + " | \n", + " | update(self, name: str, config: dict) -> list\n", + " | Update the volume\n", + " | \n", + " | :type name: str\n", + " | :type config: dict\n", + " | :rtype: dict\n", + " | \n", + " | :returns: the volume\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data and other attributes defined here:\n", + " | \n", + " | __abstractmethods__ = frozenset()\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors inherited from primehub.Helpful:\n", + " | \n", + " | __dict__\n", + " | dictionary for instance variables (if defined)\n", + " | \n", + " | __weakref__\n", + " | list of weak references to the object (if defined)\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Methods inherited from primehub.Module:\n", + " | \n", + " | __init__(self, primehub: primehub.PrimeHub, **kwargs)\n", + " | Initialize self. See help(type(self)) for accurate signature.\n", + " | \n", + " | display(self, action: dict, value: Any)\n", + " | \n", + " | get_display(self) -> primehub.utils.display.Displayable\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Static methods inherited from primehub.Module:\n", + " | \n", + " | output(result: dict, object_path: str)\n", + " | Give a dict {'data': {'a': {'b': 'c'}}}\n", + " | we could get the c by the path a.b\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors inherited from primehub.Module:\n", + " | \n", + " | current_group\n", + " | \n", + " | endpoint\n", + " | \n", + " | group_id\n", + " | \n", + " | group_name\n", + " | \n", + " | primehub_config\n", + "\n" + ] + } + ], + "source": [ + "help(ph.admin.volumes)" + ] + }, + { + "cell_type": "markdown", + "id": "62d4d2e7", + "metadata": {}, + "source": [ + "## PrimeHub Admin Volume Management\n", + "Old name: PrimeHub admin Dataset" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "a68e19de", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Usage: \n", + " primehub admin volumes \n", + "\n", + "Manage volumes\n", + "\n", + "Available Commands:\n", + " add-group Add group connection to a volume by id\n", + " create Create a volume\n", + " delete Delete a volume by id\n", + " get Get a volume by name\n", + " list List volumes\n", + " list-groups List groups of a volume by id\n", + " regen-upload-secret Regenerate the secret of the upload server\n", + " remove-group Remove group connection from a volume by id\n", + " update Update the volume\n", + "\n", + "Options:\n", + " -h, --help Show the help\n", + "\n", + "Global Options:\n", + " --config CONFIG Change the path of the config file (Default: ~/.primehub/config.json)\n", + " --endpoint ENDPOINT Override the GraphQL API endpoint\n", + " --token TOKEN Override the API Token\n", + " --group GROUP Override the current group\n", + " --json Output the json format (output human-friendly format by default)\n" + ] + } + ], + "source": [ + "!primehub admin volumes help" + ] + }, + { + "cell_type": "markdown", + "id": "00cff52d", + "metadata": {}, + "source": [ + "## Dataset configuration\n", + "\n", + "You need a configuration `create` and `update` to operate. Here is an example to create a `pv-volume`:\n", + "\n", + "```json\n", + "{\n", + " \"name\": \"pv-volume\",\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", + "```\n", + "\n", + "In our system, there are 5 types for volumes: `['pv', 'nfs', 'hostPath', 'git', 'env']`. Please check the fields reference to give a proper configuration to create your own volume.\n", + "\n", + "\n", + "### Fields for creating or updating\n", + "\n", + "| field | required | type | description |\n", + "| --- | --- | --- | --- |\n", + "| name | required | string | it should be a valid resource name for kubernetes |\n", + "| displayName | optional | string | display name for this volume |\n", + "| description | optional | string | |\n", + "| global | optional | boolean | when a volume is global, it could be seen for each group |\n", + "| type | required | string | one of ['pv', 'nfs', 'hostPath', 'git', 'env'] |\n", + "| url | conditional | string | **MUST** use with `git` type |\n", + "| pvProvisioning | conditional | string | onf of ['auto', 'manual'], **MUST** use with `pv` type. This field only uses in `CREATE` action |\n", + "| nfsServer | conditional | string | **MUST** use with `nfs` type |\n", + "| nfsPath | conditional | string | **MUST** use with `nfs` type |\n", + "| hostPath | conditional | string | **MUST** use with `hostPath` type |\n", + "| variables | optional | dict | **MAY** use with `env` type. It is key value pairs. All values have to a string value. For example: `{\"key1\":\"value1\",\"key2\":\"value2\"}`. |\n", + "| groups | optional | list of connected groups (dict) | please see the `connect` examples |\n", + "| secret | optional | dict | **MAY** use with `git` type, it binds a `secret` id to the `git` volume. The secret can be found with `primehub admin secrets list` |\n", + "| volumeSize | conditional | integer | **MUST** use with `pv` type and 'auto' provisioning. The unit is `GB`.|\n", + "| enableUploadServer | optional | boolean | it only works with one of ['pv', 'nfs', 'hostPath'] writable types |\n", + "\n", + "> There is a simple rule to use fields for `UPDATE`. All required fields should not be in the payload.\n", + "\n", + "For example, there is a configuration for creating env volume:\n", + "\n", + "```bash\n", + "primehub admin volumes create <\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idnamedisplayNamedescriptiontypeuploadServerLink
13pv-volume-by-sdkpv-volume-by-sdkthe volume created by SDKIt is a PV volumepvNone
\n", + "" + ], + "text/plain": [ + " id name displayName \\\n", + "13 pv-volume-by-sdk pv-volume-by-sdk the volume created by SDK \n", + "\n", + " description type uploadServerLink \n", + "13 It is a PV volume pv None " + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# List volumes\n", + "volumes_df = pd.DataFrame(ph.admin.volumes.list())\n", + "volumes_df[volumes_df['name'] == config['name']]" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "3cb3d7bd", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'pv-volume-by-sdk',\n", + " 'name': 'pv-volume-by-sdk',\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": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Get the volume details\n", + "ph.admin.volumes.get(data['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "04a886ea", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'pv-volume-by-sdk',\n", + " 'name': 'pv-volume-by-sdk',\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': False,\n", + " 'groups': []}" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Update the volume config setting.\n", + "update_config = {'global': False}\n", + "data = ph.admin.volumes.update(data['id'], update_config)\n", + "ph.admin.volumes.get(data['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "18341261", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'pv-volume-by-sdk'}" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Delete the volume\n", + "ph.admin.volumes.delete(data['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "4dcd55ac", + "metadata": {}, + "source": [ + "#### CRUD: volume <-> Group" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "d61f7dcb", + "metadata": {}, + "outputs": [], + "source": [ + "# Create an volume\n", + "config = {\n", + " \"name\": \"pv-volume-by-sdk-group\",\n", + " \"displayName\": \"the volume created by SDK\",\n", + " \"description\": \"It is a PV volume\",\n", + " \"type\": \"pv\",\n", + " \"global\": False,\n", + " \"pvProvisioning\": \"auto\",\n", + " \"volumeSize\": 1\n", + "}\n", + "\n", + "data = ph.admin.volumes.create(config)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "38816075", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
" + ], + "text/plain": [ + "Empty DataFrame\n", + "Columns: []\n", + "Index: []" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Show the volume group list\n", + "\n", + "volumes_df = pd.DataFrame(ph.admin.volumes.list_groups(data[\"id\"]))\n", + "volumes_df" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "848f939f", + "metadata": {}, + "outputs": [], + "source": [ + "# Add the volume into group\n", + "groups_df = pd.DataFrame(ph.admin.groups.list())\n", + "groups_id = groups_df[\"id\"][0]\n", + "ph.admin.volumes.add_group(data[\"id\"], groups_id)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "5e705003", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idnamedisplayNamewritable
071ac1e32-65fa-4e8e-a735-ba282e3149b1AnotherTestGroupAnother Test GroupFalse
\n", + "
" + ], + "text/plain": [ + " id name displayName \\\n", + "0 71ac1e32-65fa-4e8e-a735-ba282e3149b1 AnotherTestGroup Another Test Group \n", + "\n", + " writable \n", + "0 False " + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Show the volume group list\n", + "\n", + "volumes_df = pd.DataFrame(ph.admin.volumes.list_groups(data[\"id\"]))\n", + "volumes_df" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "32146409", + "metadata": {}, + "outputs": [], + "source": [ + "# Remove the volume out of group\n", + "ph.admin.volumes.remove_group(data[\"id\"], groups_id)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "f554c42a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
\n", + "
" + ], + "text/plain": [ + "Empty DataFrame\n", + "Columns: []\n", + "Index: []" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Show the volume group list\n", + "\n", + "volumes_df = pd.DataFrame(ph.admin.volumes.list_groups(data[\"id\"]))\n", + "volumes_df" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "91aa5cc4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'pv-volume-by-sdk-group'}" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Delete the volume\n", + "ph.admin.volumes.delete(data['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/notebook/admin-portal/06-secrets.ipynb b/docs/notebook/admin-portal/06-secrets.ipynb new file mode 100644 index 00000000..9be8c06f --- /dev/null +++ b/docs/notebook/admin-portal/06-secrets.ipynb @@ -0,0 +1,470 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "6b2f8e5b", + "metadata": {}, + "source": [ + "# [admin] Secrets command\n", + "\n", + "\n", + "The `secrets` command in `admin` scope could help you manage secrets.\n" + ] + }, + { + "cell_type": "markdown", + "id": "ec3778da", + "metadata": {}, + "source": [ + "## Setup PrimeHub Python SDK\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "97da879e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PrimeHub Python SDK setup successfully\n" + ] + } + ], + "source": [ + "from primehub import PrimeHub, PrimeHubConfig\n", + "ph = PrimeHub(PrimeHubConfig())\n", + "\n", + "if ph.is_ready():\n", + " print(\"PrimeHub Python SDK setup successfully\")\n", + "else:\n", + " print(\"PrimeHub Python SDK couldn't get the group information, follow the 00-getting-started.ipynb to complete it\")" + ] + }, + { + "cell_type": "markdown", + "id": "30a94330", + "metadata": {}, + "source": [ + "## Help documentation" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "509a999c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on AdminSecrets in module primehub.admin_secrets object:\n", + "\n", + "class AdminSecrets(primehub.Helpful, primehub.Module)\n", + " | AdminSecrets(primehub: primehub.PrimeHub, **kwargs)\n", + " | \n", + " | Method resolution order:\n", + " | AdminSecrets\n", + " | primehub.Helpful\n", + " | primehub.Module\n", + " | primehub.HTTPSupport\n", + " | builtins.object\n", + " | \n", + " | Methods defined here:\n", + " | \n", + " | create(self, config)\n", + " | Create a secret\n", + " | \n", + " | :type config: dict\n", + " | :param config: The configurations for creating a secret\n", + " | \n", + " | :rtype dict\n", + " | :return The id of a secret\n", + " | \n", + " | delete(self, id: str, **kwargs) -> dict\n", + " | Delete a secret by id\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of the secret\n", + " | \n", + " | :rtype dict\n", + " | :return the secret\n", + " | \n", + " | get(self, id: str) -> dict\n", + " | Get an secret by id\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of a secret\n", + " | \n", + " | :rtype dict\n", + " | :return the secret\n", + " | \n", + " | help_description(self)\n", + " | one line description for all commands\n", + " | \n", + " | list(self, **kwargs) -> Iterator\n", + " | List secrets\n", + " | \n", + " | :type page: int\n", + " | :param page: the page of all data\n", + " | \n", + " | :rtype Iterator\n", + " | :return secret iterator\n", + " | \n", + " | update(self, id: str, config: dict)\n", + " | Update the secret\n", + " | \n", + " | :type id: str\n", + " | :param id: the id of the secret\n", + " | \n", + " | :rtype: dict\n", + " | :returns: the secret\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data and other attributes defined here:\n", + " | \n", + " | __abstractmethods__ = frozenset()\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors inherited from primehub.Helpful:\n", + " | \n", + " | __dict__\n", + " | dictionary for instance variables (if defined)\n", + " | \n", + " | __weakref__\n", + " | list of weak references to the object (if defined)\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Methods inherited from primehub.Module:\n", + " | \n", + " | __init__(self, primehub: primehub.PrimeHub, **kwargs)\n", + " | Initialize self. See help(type(self)) for accurate signature.\n", + " | \n", + " | display(self, action: dict, value: Any)\n", + " | \n", + " | get_display(self) -> primehub.utils.display.Displayable\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Static methods inherited from primehub.Module:\n", + " | \n", + " | output(result: dict, object_path: str)\n", + " | Give a dict {'data': {'a': {'b': 'c'}}}\n", + " | we could get the c by the path a.b\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors inherited from primehub.Module:\n", + " | \n", + " | current_group\n", + " | \n", + " | endpoint\n", + " | \n", + " | group_id\n", + " | \n", + " | group_name\n", + " | \n", + " | primehub_config\n", + "\n" + ] + } + ], + "source": [ + "help(ph.admin.secrets)" + ] + }, + { + "cell_type": "markdown", + "id": "18b8a4a4", + "metadata": {}, + "source": [ + "## Secrets management" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "959615fc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Usage: \n", + " primehub admin secrets \n", + "\n", + "Manage secrets\n", + "\n", + "Available Commands:\n", + " create Create a secret\n", + " delete Delete a secret by id\n", + " get Get an secret by id\n", + " list List secrets\n", + " update Update the secret\n", + "\n", + "Options:\n", + " -h, --help Show the help\n", + "\n", + "Global Options:\n", + " --config CONFIG Change the path of the config file (Default: ~/.primehub/config.json)\n", + " --endpoint ENDPOINT Override the GraphQL API endpoint\n", + " --token TOKEN Override the API Token\n", + " --group GROUP Override the current group\n", + " --json Output the json format (output human-friendly format by default)\n" + ] + } + ], + "source": [ + "!primehub admin secrets help" + ] + }, + { + "cell_type": "markdown", + "id": "b8564274", + "metadata": {}, + "source": [ + "### Fields for creating or updating\n", + "\n", + "| field | required | type | description |\n", + "| --- | --- | --- | --- |\n", + "| name | required | string | The name of secret. It is only used when creating. |\n", + "| type | required | string | one of ['opaque', 'kubernetes']. `opaque` is used for Git Sync secrets (SSH Public Key). `kubernetes` is used for Container Registry. |\n", + "| displayName | optional | string | |\n", + "\n", + "* `type` can not be changed after created.\n", + "\n", + "Fields for `opaque`\n", + "\n", + "| field | required | type | description |\n", + "| --- | --- | --- | --- |\n", + "| secret | conditional | string | when type is opaque, secret field become required for the SSH Public Key. |\n", + "\n", + "Fields for `kubernetes`\n", + "\n", + "You should put container registry credentials to these fields:\n", + "\n", + "| field | required | type | description |\n", + "| --- | --- | --- | --- |\n", + "| registryHost | conditional | string | |\n", + "| username | conditional | string | |\n", + "| password | conditional | string | |\n" + ] + }, + { + "cell_type": "markdown", + "id": "4d71c57a", + "metadata": {}, + "source": [ + "## Examples" + ] + }, + { + "cell_type": "markdown", + "id": "bac62f15", + "metadata": {}, + "source": [ + "You could find [more examples on our github](https://github.com/InfuseAI/primehub-python-sdk/blob/main/docs/CLI/admin/secrets.md)." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "155e2620", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "id": "2b2bd4ec", + "metadata": {}, + "source": [ + "#### CRUD: primehub secrets" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "2ea36364", + "metadata": {}, + "outputs": [], + "source": [ + "# Create an secrets\n", + "config = {\n", + " 'name': 'create-secret-by-sdk',\n", + " \"type\": 'opaque',\n", + " \"secret\": 'keep it secret'\n", + "}\n", + "\n", + "data = ph.admin.secrets.create(config)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "b77cdf7d", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
idnamedisplayNametyperegistryHostusername
0gitsync-secret-create-secret-by-sdkcreate-secret-by-sdkcreate-secret-by-sdkopaqueNoneNone
\n", + "
" + ], + "text/plain": [ + " id name \\\n", + "0 gitsync-secret-create-secret-by-sdk create-secret-by-sdk \n", + "\n", + " displayName type registryHost username \n", + "0 create-secret-by-sdk opaque None None " + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# List secrets\n", + "secrets_df = pd.DataFrame(ph.admin.secrets.list())\n", + "secrets_df[secrets_df['name'] == config['name']]" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "e2442f4c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'gitsync-secret-create-secret-by-sdk',\n", + " 'name': 'create-secret-by-sdk',\n", + " 'displayName': 'create-secret-by-sdk',\n", + " 'type': 'opaque'}" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Get the secret details\n", + "ph.admin.secrets.get(data['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "7b7d4380", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'gitsync-secret-create-secret-by-sdk',\n", + " 'name': 'create-secret-by-sdk',\n", + " 'displayName': 'gitsync-sdk-test',\n", + " 'type': 'opaque'}" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Update the secret config setting.\n", + "update_config = {'displayName': 'gitsync-sdk-test'}\n", + "data = ph.admin.secrets.update(data['id'], update_config)\n", + "ph.admin.secrets.get(data['id'])" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "68b5f9a4", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'id': 'gitsync-secret-create-secret-by-sdk'}" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Delete the secret\n", + "ph.admin.secrets.delete(data['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/notebook/admin-portal/07-usage-reports.ipynb b/docs/notebook/admin-portal/07-usage-reports.ipynb new file mode 100644 index 00000000..b4e10ed4 --- /dev/null +++ b/docs/notebook/admin-portal/07-usage-reports.ipynb @@ -0,0 +1,329 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "b8a41dda", + "metadata": {}, + "source": [ + "# [admin] Usage Reports command\n", + "\n", + "\n", + "The `reports` command in `admin` scope could help you manage groups.\n" + ] + }, + { + "cell_type": "markdown", + "id": "740039bc", + "metadata": {}, + "source": [ + "## Setup PrimeHub Python SDK\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "effe3482", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PrimeHub Python SDK setup successfully\n" + ] + } + ], + "source": [ + "from primehub import PrimeHub, PrimeHubConfig\n", + "ph = PrimeHub(PrimeHubConfig())\n", + "\n", + "if ph.is_ready():\n", + " print(\"PrimeHub Python SDK setup successfully\")\n", + "else:\n", + " print(\"PrimeHub Python SDK couldn't get the group information, follow the 00-getting-started.ipynb to complete it\")" + ] + }, + { + "cell_type": "markdown", + "id": "bfb99744", + "metadata": {}, + "source": [ + "## Help documentation" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "9dd7964e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Help on AdminReport in module primehub.admin_reports object:\n", + "\n", + "class AdminReport(primehub.Helpful, primehub.Module)\n", + " | AdminReport(primehub: primehub.PrimeHub, **kwargs)\n", + " | \n", + " | Method resolution order:\n", + " | AdminReport\n", + " | primehub.Helpful\n", + " | primehub.Module\n", + " | primehub.HTTPSupport\n", + " | builtins.object\n", + " | \n", + " | Methods defined here:\n", + " | \n", + " | download(self, url, **kwargs)\n", + " | Download a report csv file from the given url.\n", + " | \n", + " | It will convert the URI to filename by default. For example, there are summary url and details url\n", + " | * https://primehub-python-sdk.primehub.io/api/report/monthly/2022/12\n", + " | * https://primehub-python-sdk.primehub.io/api/report/monthly/details/2022/12\n", + " | \n", + " | Will save to\n", + " | * 202212.csv\n", + " | * 202212_details.csv\n", + " | \n", + " | If you give a dest, it will use the given dest as the filename.\n", + " | \n", + " | :type url: str\n", + " | :param url: The report url.\n", + " | \n", + " | :type dest: str\n", + " | :param dest: The local path to save the report csv file\n", + " | \n", + " | :type recusive: bool\n", + " | :param recusive: Copy recursively, it works when a path is a directory.\n", + " | \n", + " | help_description(self)\n", + " | one line description for all commands\n", + " | \n", + " | list(self, **kwargs) -> Iterator\n", + " | List reports\n", + " | \n", + " | :type page: int\n", + " | :param page: the page of all data\n", + " | \n", + " | :rtype Iterator\n", + " | :return user iterator\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data and other attributes defined here:\n", + " | \n", + " | __abstractmethods__ = frozenset()\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors inherited from primehub.Helpful:\n", + " | \n", + " | __dict__\n", + " | dictionary for instance variables (if defined)\n", + " | \n", + " | __weakref__\n", + " | list of weak references to the object (if defined)\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Methods inherited from primehub.Module:\n", + " | \n", + " | __init__(self, primehub: primehub.PrimeHub, **kwargs)\n", + " | Initialize self. See help(type(self)) for accurate signature.\n", + " | \n", + " | display(self, action: dict, value: Any)\n", + " | \n", + " | get_display(self) -> primehub.utils.display.Displayable\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Static methods inherited from primehub.Module:\n", + " | \n", + " | output(result: dict, object_path: str)\n", + " | Give a dict {'data': {'a': {'b': 'c'}}}\n", + " | we could get the c by the path a.b\n", + " | \n", + " | ----------------------------------------------------------------------\n", + " | Data descriptors inherited from primehub.Module:\n", + " | \n", + " | current_group\n", + " | \n", + " | endpoint\n", + " | \n", + " | group_id\n", + " | \n", + " | group_name\n", + " | \n", + " | primehub_config\n", + "\n" + ] + } + ], + "source": [ + "help(ph.admin.reports)" + ] + }, + { + "cell_type": "markdown", + "id": "19b1d67f", + "metadata": {}, + "source": [ + "## Usage reports management" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "9633fcc5", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Usage: \n", + " primehub admin reports \n", + "\n", + "Get reports\n", + "\n", + "Available Commands:\n", + " download Download a report by url\n", + " list List reports\n", + "\n", + "Options:\n", + " -h, --help Show the help\n", + "\n", + "Global Options:\n", + " --config CONFIG Change the path of the config file (Default: ~/.primehub/config.json)\n", + " --endpoint ENDPOINT Override the GraphQL API endpoint\n", + " --token TOKEN Override the API Token\n", + " --group GROUP Override the current group\n", + " --json Output the json format (output human-friendly format by default)\n" + ] + } + ], + "source": [ + "!primehub admin reports help" + ] + }, + { + "cell_type": "markdown", + "id": "a903cc39", + "metadata": {}, + "source": [ + "## Examples" + ] + }, + { + "cell_type": "markdown", + "id": "eb6dc413", + "metadata": {}, + "source": [ + "You could find [more examples on our github](https://github.com/InfuseAI/primehub-python-sdk/blob/main/docs/CLI/admin/groups.md)." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "fab56243", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "id": "461d85cf", + "metadata": {}, + "source": [ + "#### List all usage reports" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "fa172bf3", + "metadata": {}, + "outputs": [], + "source": [ + "reports_df = pd.DataFrame(ph.admin.reports.list())\n", + "reports_df" + ] + }, + { + "cell_type": "markdown", + "id": "c93324ed", + "metadata": {}, + "source": [ + "#### Download usage reports" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "6ef6faa8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'filename': '/home/jovyan/primehub-python-sdk/docs/notebook/admin-portal/latest-summary-reports.csv'}" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Summary Reports\n", + "latest_summary_url = reports_df[\"summaryUrl\"][0]\n", + "\n", + "ph.admin.reports.download(latest_summary_url, dest=\"./latest-summary-reports.csv\")" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "3593537a", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'filename': '/home/jovyan/primehub-python-sdk/docs/notebook/admin-portal/latest-detailed-reports.csv'}" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Detailed Reports\n", + "latest_detailed_url = reports_df[\"detailedUrl\"][0]\n", + "\n", + "ph.admin.reports.download(latest_detailed_url, dest=\"./latest-detailed-reports.csv\")" + ] + } + ], + "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/notebook/admin/groups.ipynb b/docs/notebook/admin/groups.ipynb deleted file mode 100644 index 11853ff0..00000000 --- a/docs/notebook/admin/groups.ipynb +++ /dev/null @@ -1,290 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# [admin] Groups command\n", - "\n", - "\n", - "The `groups` command in `admin` scope could help you manage groups.\n" - ] - }, - { - "cell_type": "markdown", - "id": "0e684e90", - "metadata": {}, - "source": [ - "## Setup PrimeHub Python SDK\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2ed0bf22", - "metadata": {}, - "outputs": [], - "source": [ - "from primehub import PrimeHub, PrimeHubConfig\n", - "ph = PrimeHub(PrimeHubConfig())\n", - "\n", - "if ph.is_ready():\n", - " print(\"PrimeHub Python SDK setup successfully\")\n", - "else:\n", - " print(\"PrimeHub Python SDK couldn't get the group information, follow the 00-getting-started.ipynb to complete it\")" - ] - }, - { - "cell_type": "markdown", - "id": "3720ad82", - "metadata": {}, - "source": [ - "## Help documentation" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2055801e", - "metadata": {}, - "outputs": [], - "source": [ - "help(ph.admin.groups)" - ] - }, - { - "cell_type": "markdown", - "id": "ac0e2516", - "metadata": {}, - "source": [ - "## Group management\n", - "\n", - "---\n", - "\n", - "\n", - "```\n", - "Usage:\n", - " primehub admin groups \n", - "\n", - "Manage groups\n", - "\n", - "Available Commands:\n", - " create Create a group\n", - " delete Delete the group by id\n", - " get Get the group info by id\n", - " list List groups\n", - " update Update the group\n", - "\n", - "Options:\n", - " -h, --help Show the help\n", - "\n", - "Global Options:\n", - " --config CONFIG Change the path of the config file (Default: ~/.primehub/config.json)\n", - " --endpoint ENDPOINT Override the GraphQL API endpoint\n", - " --token TOKEN Override the API Token\n", - " --group GROUP Override the current group\n", - " --json Output the json format (output human-friendly format by default)\n", - "```\n", - "\n", - "---\n", - "\n", - "For `create` and `update` actions are needed a configuration to mutate a group. Here is the fields table:\n", - "\n", - "\n", - "### Fields\n", - "\n", - "| field | required | type | description |\n", - "| --- | --- | --- | --- |\n", - "| name | required | string | must start with a letter or numeric, '-' and '_' are allowed, and the length should be more than 2. |\n", - "| displayName | optional | string | display name |\n", - "| quotaCpu | optional | float | how many CPU can be used by the user within this group, default: 0.5 |\n", - "| quotaGpu | optional | int | how many GPU can be used by the user within this group, default: 0 |\n", - "| quotaMemory | optional | float | how many memory can be used by the user within this group, default: unlimited GB |\n", - "| projectQuotaCpu | optional | float | how many CPU can be shared by all users in the group, default: unlimited |\n", - "| projectQuotaGpu | optional | int | how many GPU can be shared by all users in the group, default: unlimited |\n", - "| projectQuotaMemory| optional | float | how many memory can be shared by all users in the group, default: unlimited GB |\n", - "| admins | optional | string | assign admin user of the group, multiple users are able to be assigned (see [also](https://docs.primehub.io/docs/guide_manual/admin-group#group-admin)) |\n", - "| users | optional | assign / dissociate users to the group | please see the connect / disconnect examples |\n", - "\n", - "*Note: user resource quota should not greater than project resource quota. e.g., `quotaCpu <= projectQuotaCpu`*\n", - "\n", - "\n", - "#### Model Deployment\n", - "Groups with enabled model deployment are able to deploy/serve models. (see [also](https://docs.primehub.io/docs/guide_manual/admin-group#model-deployment))\n", - "\n", - "`maxDeploy` is used when `enabledDeployment` is enable:\n", - "\n", - "| field | required | type | description |\n", - "| --- | --- | --- | --- |\n", - "| enabledDeployment | optional | boolean | enable model deployment |\n", - "| maxDeploy | optional | int | limit on the amount of deployments for this group |\n", - "\n", - "#### Shared Volume\n", - "The created shared volume is shared among members in the group. (see [also](https://docs.primehub.io/docs/guide_manual/admin-group#shared-volume))\n", - "\n", - "`sharedVolumeCapacity` is used when `enabledSharedVolume` is enable:\n", - "\n", - "| field | required | type | description |\n", - "| --- | --- | --- | --- |\n", - "| enabledSharedVolume | optional | boolean | enable share volume |\n", - "| sharedVolumeCapacity | optional | int | the capacity of the shared volume in GB |\n" - ] - }, - { - "cell_type": "markdown", - "id": "dcb77e3d", - "metadata": {}, - "source": [ - "## Examples" - ] - }, - { - "cell_type": "markdown", - "id": "b4eb5746", - "metadata": {}, - "source": [ - "You could find [more examples on our github](https://github.com/InfuseAI/primehub-python-sdk/blob/main/docs/CLI/admin/groups.md)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "908759a6", - "metadata": {}, - "outputs": [], - "source": [ - "# Create a user 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": null, - "id": "639e6281", - "metadata": {}, - "outputs": [], - "source": [ - "# List groups\n", - "list(ph.admin.groups.list())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ef3c1a91", - "metadata": {}, - "outputs": [], - "source": [ - "# Get the group details\n", - "ph.admin.groups.get(data['id'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "bd697b8b", - "metadata": {}, - "outputs": [], - "source": [ - "# Delete the group\n", - "ph.admin.groups.delete(data['id'])" - ] - }, - { - "cell_type": "markdown", - "source": [ - "### Manage users\n" - ], - "metadata": { - "collapsed": false - } - }, - { - "cell_type": "code", - "execution_count": null, - "outputs": [], - "source": [ - "group_id = ''\n", - "user_id = ''" - ], - "metadata": { - "collapsed": false, - "pycharm": { - "is_executing": true - } - } - }, - { - "cell_type": "code", - "execution_count": null, - "outputs": [], - "source": [ - "ph.admin.groups.list_users(group_id)" - ], - "metadata": { - "collapsed": false - } - }, - { - "cell_type": "code", - "execution_count": null, - "outputs": [], - "source": [ - "ph.admin.add_user(group_id, user_id)\n", - "ph.admin.add_user(group_id, user_id, enable_group_admin=True)" - ], - "metadata": { - "collapsed": false - } - }, - { - "cell_type": "code", - "execution_count": null, - "outputs": [], - "source": [ - "ph.admin.remove_user(group_id, user_id)\n", - "\n", - "# only remove the permission not the user\n", - "ph.admin.remove_user(group_id, user_id, disalbe_group_admin=True)\n" - ], - "metadata": { - "collapsed": false - } - } - ], - "metadata": { - "interpreter": { - "hash": "6688a3817b6a9bf9af7edfccc04ec9238693f1be61c239ce0c4444a70d9a5fed" - }, - "kernelspec": { - "display_name": "Python 3.9.7 64-bit ('venv': venv)", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.7" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/docs/notebook/admin/images.ipynb b/docs/notebook/admin/images.ipynb deleted file mode 100644 index 2861a6dd..00000000 --- a/docs/notebook/admin/images.ipynb +++ /dev/null @@ -1,208 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "52772ffa", - "metadata": {}, - "source": [ - "# [admin] Images command\n", - "\n", - "\n", - "The `images` command in `admin` scope could help you manage images.\n" - ] - }, - { - "cell_type": "markdown", - "id": "5ebd5158", - "metadata": {}, - "source": [ - "## Setup PrimeHub Python SDK\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1b84ef0f", - "metadata": {}, - "outputs": [], - "source": [ - "from primehub import PrimeHub, PrimeHubConfig\n", - "ph = PrimeHub(PrimeHubConfig())\n", - "\n", - "if ph.is_ready():\n", - " print(\"PrimeHub Python SDK setup successfully\")\n", - "else:\n", - " print(\"PrimeHub Python SDK couldn't get the group information, follow the 00-getting-started.ipynb to complete it\")" - ] - }, - { - "cell_type": "markdown", - "id": "5ae057ba", - "metadata": {}, - "source": [ - "## Help documentation" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "fa55f480", - "metadata": {}, - "outputs": [], - "source": [ - "help(ph.admin.images)" - ] - }, - { - "cell_type": "markdown", - "id": "73eae411", - "metadata": {}, - "source": [ - "## Images management\n", - "\n", - "---\n", - "\n", - "\n", - "```\n", - "$ primehub admin images\n", - "\n", - "Usage: \n", - " primehub admin images \n", - "\n", - "Manage images\n", - "\n", - "Available Commands:\n", - " create Create an image\n", - " delete Delete an image by id\n", - " get Get an image by id\n", - " list List images\n", - " update Update the image\n", - "```\n", - "\n", - "---\n", - "\n", - "### Fields for creating or updating\n", - "\n", - "| field | required | type | description |\n", - "| --- | --- | --- | --- |\n", - "| name | required | string | it should be a valid resource name for kubernetes. `name` will be ignored when updating |\n", - "| displayName | optional | string | |\n", - "| description | optional | string | |\n", - "| type | optional | string | one of ['cpu', 'gpu', 'both'], default value: 'both' |\n", - "| global | optional | boolean | |\n", - "| groups | optional | object | |\n", - "| url | optional | string | container image url |\n", - "| urlForGpu | optional | string | container image url for GPU optimized |\n", - "| imageSpec | optional | object | the specification for customization |\n", - "| useImagePullSecret | optional | string | the id of a secret |\n", - "\n", - "*Note: imageSpec cannot use with url and urlForGpu*\n" - ] - }, - { - "cell_type": "markdown", - "id": "eea61de7", - "metadata": {}, - "source": [ - "## Examples" - ] - }, - { - "cell_type": "markdown", - "id": "9becc7e1", - "metadata": {}, - "source": [ - "You could find [more examples on our github](https://github.com/InfuseAI/primehub-python-sdk/blob/main/docs/CLI/admin/images.md)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2f09c119", - "metadata": {}, - "outputs": [], - "source": [ - "# List images\n", - "list(ph.admin.images.list())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "0961aebb", - "metadata": {}, - "outputs": [], - "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", - "}\n", - "ph.admin.images.create(config)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "687b6b59", - "metadata": {}, - "outputs": [], - "source": [ - "# Update an image\n", - "update = {\n", - " \"description\": \"base-notebook with python 3.7, only cpu\",\n", - " \"type\": \"cpu\"\n", - "}\n", - "ph.admin.images.update(config['name'], update)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1d1f177c", - "metadata": {}, - "outputs": [], - "source": [ - "# Get deatils by id\n", - "ph.admin.images.get(config['name'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "3b08571c", - "metadata": {}, - "outputs": [], - "source": [ - "# Delete the instance type\n", - "ph.admin.images.delete(config['name'])" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.6" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/docs/notebook/admin/instancetypes.ipynb b/docs/notebook/admin/instancetypes.ipynb deleted file mode 100644 index 154011d5..00000000 --- a/docs/notebook/admin/instancetypes.ipynb +++ /dev/null @@ -1,201 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "3365d96c", - "metadata": {}, - "source": [ - "# [admin] Instancetypes command\n", - "\n", - "\n", - "The `instancetypes` command in `admin` scope could help you manage instancetypes.\n" - ] - }, - { - "cell_type": "markdown", - "id": "0e684e90", - "metadata": {}, - "source": [ - "## Setup PrimeHub Python SDK\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2ed0bf22", - "metadata": {}, - "outputs": [], - "source": [ - "from primehub import PrimeHub, PrimeHubConfig\n", - "ph = PrimeHub(PrimeHubConfig())\n", - "\n", - "if ph.is_ready():\n", - " print(\"PrimeHub Python SDK setup successfully\")\n", - "else:\n", - " print(\"PrimeHub Python SDK couldn't get the group information, follow the 00-getting-started.ipynb to complete it\")" - ] - }, - { - "cell_type": "markdown", - "id": "3720ad82", - "metadata": {}, - "source": [ - "## Help documentation" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2055801e", - "metadata": {}, - "outputs": [], - "source": [ - "help(ph.admin.instancetypes)" - ] - }, - { - "cell_type": "markdown", - "id": "ac0e2516", - "metadata": {}, - "source": [ - "## InstanceTypes management\n", - "\n", - "---\n", - "\n", - "\n", - "```\n", - "$ primehub admin instancetypes\n", - "\n", - "Usage:\n", - " primehub admin instancetypes \n", - "\n", - "Manage instance type\n", - "\n", - "Available Commands:\n", - " create Create an instance type\n", - " delete Delete an instance type by id\n", - " get Get an instance type by id\n", - " list List instance type\n", - " update Update the instance type\n", - "```\n", - "\n", - "---\n", - "\n", - "### Fields for creating or updating\n", - "\n", - "| field | required | type | description |\n", - "| --- | --- | --- | --- |\n", - "| name | required | string | it should be a valid resource name for kubernetes. `name` will be ignored when updating |\n", - "| displayName | optional | string | display name for the instance type |\n", - "| description | optional | string | |\n", - "| global | optional | boolean | when an instance type is global, it could be seen for each group |\n", - "| groups | optional | list of connected groups (dict) | please see the `connect` examples. default value: false |\n", - "| cpuLimit | required* | float | the maximum vCPU quantity. For example: `1` or `1.0` means 1 vCPU and `0.5` means half of vCPU |\n", - "| cpuRequest | optional | float | the initial vCPU quantity for CPU resource. cpuRequest can not be greater than cpuLimit |\n", - "| memoryLimit | required* | float | the maximum Memory size. For example: `1.5` means `1.5 GB` memory |\n", - "| memoryRequest | optional | float | the initial Memory size. memoryRequest can not be greater than memoryLimit |\n", - "| gpuLimit | optional | int | the count of GPU when an instance allocated |\n", - "| tolerations | optional | dict | kubernetes pod toleration in an instance (Pod) |\n", - "| nodeSelector | optional | dict | kubernetes pod nodeSelector in an instance (Pod) |\n", - "\n", - "#### Auto-filling Fields\n", - "Auto-filling will happen when the configuration omitted fields\n", - "\n", - "| field\t| value\t| description |\n", - "| --- | --- | --- |\n", - "| cpuLimit\t| 1\t| 1 vCPU |\n", - "| memoryLimit\t| 1\t| 1 GB memory |\n" - ] - }, - { - "cell_type": "markdown", - "id": "dcb77e3d", - "metadata": {}, - "source": [ - "## Examples" - ] - }, - { - "cell_type": "markdown", - "id": "b4eb5746", - "metadata": {}, - "source": [ - "You could find [more examples on our github](https://github.com/InfuseAI/primehub-python-sdk/blob/main/docs/CLI/admin/instancetypes.md)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "639e6281", - "metadata": {}, - "outputs": [], - "source": [ - "# List instance types\n", - "list(ph.admin.instancetypes.list())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "908759a6", - "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", - " \"gpuLimit\": 0,\n", - " \"global\": True\n", - "}\n", - "ph.admin.instancetypes.create(config)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ef3c1a91", - "metadata": {}, - "outputs": [], - "source": [ - "# get deatils by id\n", - "ph.admin.instancetypes.get(config['name'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "fb242b3d", - "metadata": {}, - "outputs": [], - "source": [ - "# delete the instance type\n", - "ph.admin.instancetypes.delete(config['name'])" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "PrimeHub SDK", - "language": "python", - "name": "myenv" - }, - "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.6" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/docs/notebook/admin/secrets.ipynb b/docs/notebook/admin/secrets.ipynb deleted file mode 100644 index 845c6941..00000000 --- a/docs/notebook/admin/secrets.ipynb +++ /dev/null @@ -1,210 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "3365d96c", - "metadata": {}, - "source": [ - "# [admin] Secrets command\n", - "\n", - "\n", - "The `secrets` command in `admin` scope could help you manage secrets.\n" - ] - }, - { - "cell_type": "markdown", - "id": "0e684e90", - "metadata": {}, - "source": [ - "## Setup PrimeHub Python SDK\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2ed0bf22", - "metadata": {}, - "outputs": [], - "source": [ - "from primehub import PrimeHub, PrimeHubConfig\n", - "ph = PrimeHub(PrimeHubConfig())\n", - "\n", - "if ph.is_ready():\n", - " print(\"PrimeHub Python SDK setup successfully\")\n", - "else:\n", - " print(\"PrimeHub Python SDK couldn't get the group information, follow the 00-getting-started.ipynb to complete it\")" - ] - }, - { - "cell_type": "markdown", - "id": "3720ad82", - "metadata": {}, - "source": [ - "## Help documentation" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2055801e", - "metadata": {}, - "outputs": [], - "source": [ - "help(ph.admin.secrets)" - ] - }, - { - "cell_type": "markdown", - "id": "ac0e2516", - "metadata": {}, - "source": [ - "## Secrets management\n", - "\n", - "---\n", - "\n", - "\n", - "```\n", - "$ primehub admin secrets\n", - "\n", - "Usage:\n", - " primehub admin secrets \n", - "\n", - "Manage secrets\n", - "\n", - "Available Commands:\n", - " create Create a secret\n", - " delete Delete a secret by id\n", - " get Get an secret by id\n", - " list List secrets\n", - " update Update the secret\n", - "```\n", - "\n", - "---\n", - "\n" - ] - }, - { - "cell_type": "markdown", - "id": "dcb77e3d", - "metadata": {}, - "source": [ - "## Examples" - ] - }, - { - "cell_type": "markdown", - "id": "b4eb5746", - "metadata": {}, - "source": [ - "You could find [more examples on our github](https://github.com/InfuseAI/primehub-python-sdk/blob/main/docs/CLI/admin/secrets.md)." - ] - }, - { - "cell_type": "markdown", - "id": "97458424", - "metadata": {}, - "source": [ - "### Fields for creating or updating\n", - "\n", - "| field | required | type | description |\n", - "| --- | --- | --- | --- |\n", - "| name | required | string | The name of secret. It is only used when creating. |\n", - "| type | required | string | one of ['opaque', 'kubernetes']. `opaque` is used for Git Sync Volume (SSH Public Key). `kubernetes` is used for Container Registry. |\n", - "| displayName | optional | string | |\n", - "\n", - "* `type` can not be changed after created.\n", - "\n", - "Fields for `opaque`\n", - "\n", - "| field | required | type | description |\n", - "| --- | --- | --- | --- |\n", - "| secret | conditional | string | when type is opaque, secret field become required for the SSH Public Key. |\n", - "\n", - "Fields for `kubernetes`\n", - "\n", - "You should put container registry credentials to these fields:\n", - "\n", - "| field | required | type | description |\n", - "| --- | --- | --- | --- |\n", - "| registryHost | conditional | string | |\n", - "| username | conditional | string | |\n", - "| password | conditional | string | |\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "639e6281", - "metadata": {}, - "outputs": [], - "source": [ - "# Create secrets\n", - "secret = ph.admin.secrets.create(dict(name='create-secret-by-sdk', type='opaque', secret='keep it secret'))\n", - "secret" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ef3c1a91", - "metadata": {}, - "outputs": [], - "source": [ - "# List secrets\n", - "list(ph.admin.secrets.list())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "6a1a1f49", - "metadata": {}, - "outputs": [], - "source": [ - "# Get the secret\n", - "ph.admin.secrets.get(secret['id'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "bd697b8b", - "metadata": {}, - "outputs": [], - "source": [ - "# Delete the secret\n", - "print(f'delete secret by id: {secret[\"id\"]}')\n", - "ph.admin.secrets.delete(secret['id'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a0ffa881", - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "PrimeHub SDK", - "language": "python", - "name": "myenv" - }, - "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.6" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/docs/notebook/admin/users.ipynb b/docs/notebook/admin/users.ipynb deleted file mode 100644 index f7ea53a2..00000000 --- a/docs/notebook/admin/users.ipynb +++ /dev/null @@ -1,204 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "3365d96c", - "metadata": {}, - "source": [ - "# [admin] Users command\n", - "\n", - "\n", - "The `users` command in `admin` scope could help you manage users.\n" - ] - }, - { - "cell_type": "markdown", - "id": "0e684e90", - "metadata": {}, - "source": [ - "## Setup PrimeHub Python SDK\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2ed0bf22", - "metadata": {}, - "outputs": [], - "source": [ - "from primehub import PrimeHub, PrimeHubConfig\n", - "ph = PrimeHub(PrimeHubConfig())\n", - "\n", - "if ph.is_ready():\n", - " print(\"PrimeHub Python SDK setup successfully\")\n", - "else:\n", - " print(\"PrimeHub Python SDK couldn't get the group information, follow the 00-getting-started.ipynb to complete it\")" - ] - }, - { - "cell_type": "markdown", - "id": "3720ad82", - "metadata": {}, - "source": [ - "## Help documentation" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2055801e", - "metadata": {}, - "outputs": [], - "source": [ - "help(ph.admin.users)" - ] - }, - { - "cell_type": "markdown", - "id": "ac0e2516", - "metadata": {}, - "source": [ - "## User management\n", - "\n", - "---\n", - "\n", - "\n", - "```\n", - "$ primehub admin users\n", - "\n", - "Usage:\n", - " primehub admin users \n", - "\n", - "Manage users\n", - "\n", - "Available Commands:\n", - " create Create a user\n", - " delete Delete an user by id\n", - " get Get an user by id\n", - " list List users\n", - " reset-password Reset password by id\n", - " update Update the user\n", - "```\n", - "\n", - "---\n", - "\n", - "For `create` and `update` actions are needed a configuration to mutate a user. Here is the fields table:\n", - "\n", - "\n", - "### Fields\n", - "\n", - "| field | required | type | description |\n", - "| --- | --- | --- | --- |\n", - "| username | required | string | lower case alphanumeric characters, '-', '.', and underscores (\"_\") are allowed, and must start with a letter or numeric.` |\n", - "| email | optional | string | a valid email |\n", - "| firstName | optional | string | |\n", - "| lastName | optional | string | |\n", - "| isAdmin | optional | boolean | grant the administrator role to the user |\n", - "| volumeCapacity | optional | int | customize the size of the user volume. unit: `GB`|\n", - "| groups | optional | assign the user to groups | please see the `connect` examples |\n", - "\n", - "These fields are only used with email activation (only for `create`):\n", - "\n", - "| field | required | type | description |\n", - "| --- | --- | --- | --- |\n", - "| sendEmail | optional | boolean | send an activation email to the user. (it worked if the smtp was set)|\n", - "| resetActions.set | optional | string[] | ask for actions, valid actions: `['VERIFY_EMAIL', 'UPDATE_PASSWORD']` |\n", - "| expiresIn | optional | int | expired duration for the activation email |\n", - "\n", - "\n" - ] - }, - { - "cell_type": "markdown", - "id": "dcb77e3d", - "metadata": {}, - "source": [ - "## Examples" - ] - }, - { - "cell_type": "markdown", - "id": "b4eb5746", - "metadata": {}, - "source": [ - "You could find [more examples on our github](https://github.com/InfuseAI/primehub-python-sdk/blob/main/docs/CLI/admin/users.md)." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "908759a6", - "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", - " },\n", - " \"isAdmin\": True\n", - "}\n", - "data = ph.admin.users.create(config)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "639e6281", - "metadata": {}, - "outputs": [], - "source": [ - "# List users\n", - "list(ph.admin.users.list())" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "ef3c1a91", - "metadata": {}, - "outputs": [], - "source": [ - "# Get the user details\n", - "ph.admin.users.get(data['id'])" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "bd697b8b", - "metadata": {}, - "outputs": [], - "source": [ - "# Delete the user\n", - "ph.admin.users.delete(data['id'])" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "PrimeHub SDK", - "language": "python", - "name": "myenv" - }, - "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.6" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/docs/notebook/admin/volumes.ipynb b/docs/notebook/admin/volumes.ipynb deleted file mode 100644 index 6b972ae9..00000000 --- a/docs/notebook/admin/volumes.ipynb +++ /dev/null @@ -1,227 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "id": "3365d96c", - "metadata": {}, - "source": [ - "# [admin] Volumes command\n", - "\n", - "\n", - "The `volumes` command in `admin` scope could help you manage volumes.\n" - ] - }, - { - "cell_type": "markdown", - "id": "0e684e90", - "metadata": {}, - "source": [ - "## Setup PrimeHub Python SDK\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2ed0bf22", - "metadata": {}, - "outputs": [], - "source": [ - "from primehub import PrimeHub, PrimeHubConfig\n", - "ph = PrimeHub(PrimeHubConfig())\n", - "\n", - "if ph.is_ready():\n", - " print(\"PrimeHub Python SDK setup successfully\")\n", - "else:\n", - " print(\"PrimeHub Python SDK couldn't get the group information, follow the 00-getting-started.ipynb to complete it\")" - ] - }, - { - "cell_type": "markdown", - "id": "3720ad82", - "metadata": {}, - "source": [ - "## Help documentation" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2055801e", - "metadata": {}, - "outputs": [], - "source": [ - "help(ph.admin.volumes)" - ] - }, - { - "cell_type": "markdown", - "id": "ac0e2516", - "metadata": {}, - "source": [ - "## Dataset management\n", - "\n", - "---\n", - "\n", - "\n", - "```\n", - "$ primehub admin volumes\n", - "\n", - "Usage:\n", - " primehub admin volumes \n", - "\n", - "Manage volumes\n", - "\n", - "Available Commands:\n", - " create Create a volume\n", - " delete Delete a volume by id\n", - " get Get a volume by name\n", - " list list volumes\n", - " update Update the volume\n", - " upload_secret Regenerate the secret of the upload server\n", - "```\n", - "\n", - "---\n", - "\n", - "\n", - "## Dataset configuration\n", - "\n", - "You need a configuration `create` and `update` to operate. Here is an example to create a `pv-volume`:\n", - "\n", - "```json\n", - "{\n", - " \"name\": \"pv-volume\",\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", - "```\n", - "\n", - "In our system, there are 5 types for volumes: `['pv', 'nfs', 'hostPath', 'git', 'env']`. Please check the fields reference to give a proper configuration to create your own volume.\n", - "\n", - "\n", - "### Fields for creating or updating\n", - "\n", - "| field | required | type | description |\n", - "| --- | --- | --- | --- |\n", - "| name | required | string | it should be a valid resource name for kubernetes |\n", - "| displayName | optional | string | display name for this volume |\n", - "| description | optional | string | |\n", - "| global | optional | boolean | when a volume is global, it could be seen for each group |\n", - "| type | required | string | one of ['pv', 'nfs', 'hostPath', 'git', 'env'] |\n", - "| url | conditional | string | **MUST** use with `git` type |\n", - "| pvProvisioning | conditional | string | onf of ['auto', 'manual'], **MUST** use with `pv` type. This field only uses in `CREATE` action |\n", - "| nfsServer | conditional | string | **MUST** use with `nfs` type |\n", - "| nfsPath | conditional | string | **MUST** use with `nfs` type |\n", - "| hostPath | conditional | string | **MUST** use with `hostPath` type |\n", - "| variables | optional | dict | **MAY** use with `env` type. It is key value pairs. All values have to a string value. For example: `{\"key1\":\"value1\",\"key2\":\"value2\"}`. |\n", - "| groups | optional | list of connected groups (dict) | please see the `connect` examples |\n", - "| secret | optional | dict | **MAY** use with `git` type, it binds a `secret` id to the `git` volume. The secret can be found with `primehub admin secrets list` |\n", - "| volumeSize | conditional | integer | **MUST** use with `pv` type and 'auto' provisioning. The unit is `GB`.|\n", - "| enableUploadServer | optional | boolean | it only works with one of ['pv', 'nfs', 'hostPath'] writable types |\n", - "\n", - "> There is a simple rule to use fields for `UPDATE`. All required fields should not be in the payload.\n", - "\n", - "For example, there is a configuration for creating env volume:\n", - "\n", - "```bash\n", - "primehub admin volumes create <')" - ] - }, - { - "cell_type": "markdown", - "id": "903009c2", - "metadata": {}, - "source": [ - "### Get detail information of model versions" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "1ce5ad39", - "metadata": {}, - "outputs": [], - "source": [ - "# List all versions of a model\n", - "model_versions = ph.models.list_versions('')\n", - "for version in model_versions:\n", - " print(version)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "e0bfb3ad", - "metadata": {}, - "outputs": [], - "source": [ - "# Get detail information by model name and version number\n", - "ph.models.get_version('', '')" - ] - }, - { - "cell_type": "markdown", - "id": "a1970e9c", - "metadata": {}, - "source": [ - "### Deploy a model to existing deployments" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "9464702e", - "metadata": {}, - "outputs": [], - "source": [ - "# Deploy the model with specific version \n", - "ph.models.deploy('', '', '')" - ] - } - ], - "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/notebook/00-getting-started.ipynb b/docs/notebook/user-portal/00-getting-started.ipynb similarity index 50% rename from docs/notebook/00-getting-started.ipynb rename to docs/notebook/user-portal/00-getting-started.ipynb index 315ba6c2..623df12f 100644 --- a/docs/notebook/00-getting-started.ipynb +++ b/docs/notebook/user-portal/00-getting-started.ipynb @@ -6,7 +6,7 @@ "source": [ "# Getting Started with PrimeHub Python SDK\n", "\n", - "PrimeHub Python SDK makes you automation with PrimeHub Platform.\n" + "PrimeHub Python SDK makes you automation with PrimeHub Platform." ] }, { @@ -29,9 +29,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Collecting primehub-python-sdk\n", + " Using cached primehub_python_sdk-0.4.0-py3-none-any.whl (110 kB)\n", + "Collecting types-tabulate==0.8.2\n", + " Using cached types_tabulate-0.8.2-py3-none-any.whl (2.4 kB)\n", + "Requirement already satisfied: requests in /opt/conda/lib/python3.7/site-packages (from primehub-python-sdk) (2.27.1)\n", + "Collecting types-requests\n", + " Downloading types_requests-2.28.11.17-py3-none-any.whl (14 kB)\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: charset-normalizer~=2.0.0 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (2.0.12)\n", + "Requirement already satisfied: idna<4,>=2.5 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (3.3)\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.27,>=1.21.1 in /opt/conda/lib/python3.7/site-packages (from requests->primehub-python-sdk) (1.26.9)\n", + "Collecting types-urllib3<1.27\n", + " Downloading types_urllib3-1.26.25.10-py3-none-any.whl (15 kB)\n", + "Installing collected packages: types-urllib3, types-tabulate, types-requests, primehub-python-sdk\n", + "Successfully installed primehub-python-sdk-0.4.0 types-requests-2.28.11.17 types-tabulate-0.8.2 types-urllib3-1.26.25.10\n" + ] + } + ], "source": [ "!pip install primehub-python-sdk" ] @@ -49,15 +72,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ + "# Please modify the variable of PrimeHub Cluster URL\n", "PRIMEHUB_CLUSTER = 'http://primehub-python-sdk.primehub.io'\n", "\n", + "# Force change the config.json\n", + "CHANGE_CONFIG_FILE = False" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "import os\n", "from primehub import PrimeHub, PrimeHubConfig\n", + "\n", "ph = PrimeHub(PrimeHubConfig())\n", - "ph.config.generate(PRIMEHUB_CLUSTER)" + "if not os.path.isfile(os.path.join(os.getenv(\"HOME\"), \".primehub/config.json\")) or CHANGE_CONFIG_FILE:\n", + " ph.config.generate(PRIMEHUB_CLUSTER)" ] }, { @@ -73,6 +110,7 @@ "metadata": {}, "outputs": [], "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", @@ -84,7 +122,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Here is all available commands in the PrimeHub SDK\n", + "## Here is all available commands in the PrimeHub Python SDK\n", "\n", "We will talk each command in the individual notebook. Commands call convention are:\n", "\n", @@ -95,37 +133,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "admin\n", + "apps\n", + "apptemplates\n", + "config\n", + "datasets\n", + "deployments\n", + "files\n", + "groups\n", + "images\n", + "instancetypes\n", + "jobs\n", + "me\n", + "models\n", + "notebooks\n", + "recurring-jobs\n", + "secrets\n", + "version\n", + "volumes\n" + ] + } + ], "source": [ "for cmd in ph.get_all_commands():\n", " print(cmd)" ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Please check command details \n", - "\n", - "* Configuration and account resources\n", - " * config.ipynb\n", - " * groups.ipynb\n", - " * me.ipynb\n", - " \n", - "* Group resource(group-resources.ipynb):\n", - " * datasets\n", - " * images\n", - " * instancetypes\n", - "\n", - "* Job related\n", - " * files\n", - " * jobs\n", - " * schedules\n", - "\n", - "* notebooks command\n" - ] } ], "metadata": { @@ -133,9 +172,9 @@ "hash": "b2ec084f4af1cfdda5df94d11be181b9273da0e6177ccab952b78bb7bed491ac" }, "kernelspec": { - "display_name": "PrimeHub SDK", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": "myenv" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -147,7 +186,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.7.12" } }, "nbformat": 4, diff --git a/docs/notebook/me.ipynb b/docs/notebook/user-portal/01-1-me.ipynb similarity index 64% rename from docs/notebook/me.ipynb rename to docs/notebook/user-portal/01-1-me.ipynb index 336c668d..11b212e4 100644 --- a/docs/notebook/me.ipynb +++ b/docs/notebook/user-portal/01-1-me.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "b7f33587", + "id": "45440ca7", "metadata": {}, "source": [ "# Me command\n", @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "e0e0168b", + "id": "64b99d2a", "metadata": {}, "source": [ "## Setup PrimeHub Python SDK\n" @@ -23,7 +23,7 @@ { "cell_type": "code", "execution_count": null, - "id": "bb88d3e0", + "id": "a29399d6", "metadata": {}, "outputs": [], "source": [ @@ -38,7 +38,7 @@ }, { "cell_type": "markdown", - "id": "f5b3f866", + "id": "b6b74c23", "metadata": {}, "source": [ "## Help documentation" @@ -47,7 +47,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e62a8003", + "id": "1bd0de79", "metadata": {}, "outputs": [], "source": [ @@ -56,7 +56,7 @@ }, { "cell_type": "markdown", - "id": "7c478689", + "id": "24ba4c10", "metadata": {}, "source": [ "## Examples" @@ -65,26 +65,62 @@ { "cell_type": "code", "execution_count": null, - "id": "3af5ca83", + "id": "540919ce", "metadata": {}, "outputs": [], "source": [ - "# Show account information\n", + "# Show PrimeHub account information\n", "ph.me.me()" ] }, { "cell_type": "code", "execution_count": null, - "id": "13ab410f", + "id": "5d3ae0f4", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# Show PrimeHub current group\n", + "ph.me.current_group" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "159361c1", + "metadata": {}, + "outputs": [], + "source": [ + "# Show PrimeHub endpoint\n", + "ph.me.endpoint" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c85d4531", + "metadata": {}, + "outputs": [], + "source": [ + "# Show PrimeHub group id\n", + "ph.me.group_id" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b97cb152", + "metadata": {}, + "outputs": [], + "source": [ + "# Show Primehub\n", + "ph.me.group_name" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -98,7 +134,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.10" + "version": "3.7.12" } }, "nbformat": 4, diff --git a/docs/notebook/config.ipynb b/docs/notebook/user-portal/01-2-config.ipynb similarity index 92% rename from docs/notebook/config.ipynb rename to docs/notebook/user-portal/01-2-config.ipynb index d57bfe39..527e33fe 100644 --- a/docs/notebook/config.ipynb +++ b/docs/notebook/user-portal/01-2-config.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "1dbeaa6f", + "id": "fe4e0d0e", "metadata": {}, "source": [ "# Config command\n", @@ -31,7 +31,7 @@ }, { "cell_type": "markdown", - "id": "167524ce", + "id": "4a2dc0fa", "metadata": {}, "source": [ "## Setup PrimeHub Python SDK\n" @@ -40,7 +40,7 @@ { "cell_type": "code", "execution_count": null, - "id": "2374e1ba", + "id": "e8e3f07d", "metadata": {}, "outputs": [], "source": [ @@ -55,7 +55,7 @@ }, { "cell_type": "markdown", - "id": "e9ad2a22", + "id": "fc770ed1", "metadata": {}, "source": [ "## Help documentation" @@ -64,7 +64,7 @@ { "cell_type": "code", "execution_count": null, - "id": "dafdff57", + "id": "b365bb49", "metadata": {}, "outputs": [], "source": [ @@ -73,7 +73,7 @@ }, { "cell_type": "markdown", - "id": "08dad975", + "id": "7f3128d5", "metadata": {}, "source": [ "## Examples" @@ -82,7 +82,7 @@ { "cell_type": "code", "execution_count": null, - "id": "26bc550d", + "id": "50c4243b", "metadata": {}, "outputs": [], "source": [ @@ -93,7 +93,7 @@ { "cell_type": "code", "execution_count": null, - "id": "b123a21b", + "id": "aadaa38e", "metadata": {}, "outputs": [], "source": [ @@ -104,7 +104,7 @@ { "cell_type": "code", "execution_count": null, - "id": "67b77f0e", + "id": "c9d41aa1", "metadata": {}, "outputs": [], "source": [ @@ -116,7 +116,7 @@ { "cell_type": "code", "execution_count": null, - "id": "da92b72a", + "id": "156d5ce2", "metadata": {}, "outputs": [], "source": [] @@ -124,7 +124,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -138,7 +138,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.10" + "version": "3.7.12" } }, "nbformat": 4, diff --git a/docs/notebook/instancetypes.ipynb b/docs/notebook/user-portal/01-3-instancetypes.ipynb similarity index 88% rename from docs/notebook/instancetypes.ipynb rename to docs/notebook/user-portal/01-3-instancetypes.ipynb index 1d37c89a..6920c579 100644 --- a/docs/notebook/instancetypes.ipynb +++ b/docs/notebook/user-portal/01-3-instancetypes.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "b8f26dad", + "id": "4e437853", "metadata": {}, "source": [ "# Instancetypes command\n", @@ -13,7 +13,7 @@ }, { "cell_type": "markdown", - "id": "d24e7630", + "id": "90b5a29e", "metadata": {}, "source": [ "## Setup PrimeHub Python SDK\n" @@ -22,7 +22,7 @@ { "cell_type": "code", "execution_count": null, - "id": "3cdb5c40", + "id": "d4c5d0ed", "metadata": {}, "outputs": [], "source": [ @@ -37,7 +37,7 @@ }, { "cell_type": "markdown", - "id": "6b2300e0", + "id": "b8562a84", "metadata": {}, "source": [ "## Help documentation" @@ -46,7 +46,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d055cccd", + "id": "d565a120", "metadata": {}, "outputs": [], "source": [ @@ -55,7 +55,7 @@ }, { "cell_type": "markdown", - "id": "2d052f37", + "id": "8423bb5e", "metadata": {}, "source": [ "## Examples" @@ -64,7 +64,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c3ccfad7", + "id": "5569449b", "metadata": {}, "outputs": [], "source": [ @@ -75,7 +75,7 @@ { "cell_type": "code", "execution_count": null, - "id": "477469f7", + "id": "76617b8b", "metadata": {}, "outputs": [], "source": [ @@ -86,7 +86,7 @@ { "cell_type": "code", "execution_count": null, - "id": "5976f3ba", + "id": "148f027a", "metadata": {}, "outputs": [], "source": [] @@ -94,7 +94,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -108,7 +108,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.10" + "version": "3.7.12" } }, "nbformat": 4, diff --git a/docs/notebook/secrets.ipynb b/docs/notebook/user-portal/01-4-secrets.ipynb similarity index 91% rename from docs/notebook/secrets.ipynb rename to docs/notebook/user-portal/01-4-secrets.ipynb index 2639165c..b12da72f 100644 --- a/docs/notebook/secrets.ipynb +++ b/docs/notebook/user-portal/01-4-secrets.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "6f94585c", + "id": "85d076d5", "metadata": {}, "source": [ "# Secrets command\n", @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "e035ff8a", + "id": "e4e37b28", "metadata": {}, "source": [ "## Setup PrimeHub Python SDK\n" @@ -23,7 +23,7 @@ { "cell_type": "code", "execution_count": null, - "id": "14d61c20", + "id": "8a1cade7", "metadata": {}, "outputs": [], "source": [ @@ -38,7 +38,7 @@ }, { "cell_type": "markdown", - "id": "99b72e74", + "id": "67b1fd00", "metadata": {}, "source": [ "## Help documentation" @@ -47,7 +47,7 @@ { "cell_type": "code", "execution_count": null, - "id": "5c19aff9", + "id": "c99949c2", "metadata": {}, "outputs": [], "source": [ @@ -56,7 +56,7 @@ }, { "cell_type": "markdown", - "id": "fa526193", + "id": "8e40caf4", "metadata": {}, "source": [ "## Examples" @@ -65,7 +65,7 @@ { "cell_type": "code", "execution_count": null, - "id": "99019b63", + "id": "dc41769b", "metadata": {}, "outputs": [], "source": [ @@ -77,7 +77,7 @@ { "cell_type": "code", "execution_count": null, - "id": "40162ded", + "id": "f008a514", "metadata": {}, "outputs": [], "source": [ @@ -89,7 +89,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e97cc2f6", + "id": "4b2ba647", "metadata": {}, "outputs": [], "source": [] @@ -111,7 +111,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.7.12" } }, "nbformat": 4, diff --git a/docs/notebook/volumes.ipynb b/docs/notebook/user-portal/01-5-volumes.ipynb similarity index 88% rename from docs/notebook/volumes.ipynb rename to docs/notebook/user-portal/01-5-volumes.ipynb index 3b18b991..7162b7ea 100644 --- a/docs/notebook/volumes.ipynb +++ b/docs/notebook/user-portal/01-5-volumes.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "3365d96c", + "id": "2667b870", "metadata": {}, "source": [ "# Volumes command\n", @@ -13,7 +13,7 @@ }, { "cell_type": "markdown", - "id": "0e684e90", + "id": "6ad2b427", "metadata": {}, "source": [ "## Setup PrimeHub Python SDK\n" @@ -22,7 +22,7 @@ { "cell_type": "code", "execution_count": null, - "id": "2ed0bf22", + "id": "68163d73", "metadata": {}, "outputs": [], "source": [ @@ -37,7 +37,7 @@ }, { "cell_type": "markdown", - "id": "3720ad82", + "id": "83c13fa7", "metadata": {}, "source": [ "## Help documentation" @@ -46,7 +46,7 @@ { "cell_type": "code", "execution_count": null, - "id": "2055801e", + "id": "d1e80796", "metadata": {}, "outputs": [], "source": [ @@ -55,7 +55,7 @@ }, { "cell_type": "markdown", - "id": "dcb77e3d", + "id": "394c5599", "metadata": {}, "source": [ "## Examples" @@ -64,7 +64,7 @@ { "cell_type": "code", "execution_count": null, - "id": "639e6281", + "id": "ad1d336a", "metadata": {}, "outputs": [], "source": [ @@ -75,7 +75,7 @@ { "cell_type": "code", "execution_count": null, - "id": "908759a6", + "id": "dcb704ae", "metadata": {}, "outputs": [], "source": [ @@ -86,7 +86,7 @@ { "cell_type": "code", "execution_count": null, - "id": "4b9f9704", + "id": "b16e2ff3", "metadata": {}, "outputs": [], "source": [] @@ -94,7 +94,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -108,7 +108,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.10" + "version": "3.7.12" } }, "nbformat": 4, diff --git a/docs/notebook/notebooks.ipynb b/docs/notebook/user-portal/02-notebooks.ipynb similarity index 54% rename from docs/notebook/notebooks.ipynb rename to docs/notebook/user-portal/02-notebooks.ipynb index e3669423..c4789f3f 100644 --- a/docs/notebook/notebooks.ipynb +++ b/docs/notebook/user-portal/02-notebooks.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "87382334", + "id": "b453f118", "metadata": {}, "source": [ "# Notebooks command\n", @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "d7e67662", + "id": "988cd4af", "metadata": {}, "source": [ "## Setup PrimeHub Python SDK\n" @@ -22,10 +22,18 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "fef8aff5", + "execution_count": 1, + "id": "0d842b64", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PrimeHub Python SDK setup successfully\n" + ] + } + ], "source": [ "from primehub import PrimeHub, PrimeHubConfig\n", "ph = PrimeHub(PrimeHubConfig())\n", @@ -38,7 +46,7 @@ }, { "cell_type": "markdown", - "id": "ae63b2af", + "id": "ce3b8452", "metadata": {}, "source": [ "## Help documentation" @@ -47,7 +55,7 @@ { "cell_type": "code", "execution_count": null, - "id": "7c8e9e31", + "id": "33fd6a5f", "metadata": {}, "outputs": [], "source": [ @@ -56,7 +64,7 @@ }, { "cell_type": "markdown", - "id": "45f1a0e5", + "id": "d6b6e5db", "metadata": {}, "source": [ "## Examples" @@ -64,7 +72,7 @@ }, { "cell_type": "markdown", - "id": "96a0c2fb", + "id": "cff57109", "metadata": {}, "source": [ "### Get detail information of notebook" @@ -72,34 +80,54 @@ }, { "cell_type": "code", - "execution_count": null, - "id": "fd9f0a64", + "execution_count": 2, + "id": "7e43fb4e", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Traceback (most recent call last):\n", + " File \"/opt/conda/lib/python3.7/site-packages/jupyterhub/singleuser/mixins.py\", line 518, in notify\n", + " await client.fetch(req)\n", + " File \"/opt/conda/lib/python3.7/asyncio/tasks.py\", line 318, in __wakeup\n", + " future.result()\n", + " tornado.httpclient.HTTPClientError: HTTP 403: Forbidden\n", + "[WARNING 2023-03-30 09:35:00.856 SingleUserLabApp manager:510] Notebook primehub-python-sdk/docs/notebook/me.ipynb is not trusted\n", + "Websocket closed\n", + "[WARNING 2023-03-30 09:42:50.189 SingleUserLabApp manager:510] Notebook primehub-python-sdk/docs/notebook/notebooks.ipynb is not trusted\n", + "[WARNING 2023-03-30 09:48:30.080 SingleUserLabApp handlers:236] delete /primehub-python-sdk/docs/notebook/Untitled.ipynb\n", + "\n" + ] + } + ], "source": [ - "# Get logs\n", + "# Show the Current log\n", + "\n", "logs = ph.notebooks.logs()\n", "for l in logs:\n", - " print(l)" + " print(l.decode('utf-8'))" ] }, { "cell_type": "code", "execution_count": null, - "id": "8fef781f", + "id": "eb4c0868", "metadata": {}, "outputs": [], "source": [ - "# Get logs in stream mode\n", + "# Streaming Mode: Show the log\n", + "\n", "logs = ph.notebooks.logs(follow=True)\n", "for l in logs:\n", - " print(l)" + " print(l.decode('utf-8'))" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -113,7 +141,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.10" + "version": "3.7.12" } }, "nbformat": 4, diff --git a/docs/notebook/jobs.ipynb b/docs/notebook/user-portal/03-1-jobs.ipynb similarity index 66% rename from docs/notebook/jobs.ipynb rename to docs/notebook/user-portal/03-1-jobs.ipynb index 6e4f0718..fb507115 100644 --- a/docs/notebook/jobs.ipynb +++ b/docs/notebook/user-portal/03-1-jobs.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "c21ec6cb", + "id": "3d0bef17", "metadata": {}, "source": [ "# Jobs command\n", @@ -24,7 +24,7 @@ }, { "cell_type": "markdown", - "id": "65d28291", + "id": "4feaec2f", "metadata": {}, "source": [ "## Setup PrimeHub Python SDK\n" @@ -33,7 +33,7 @@ { "cell_type": "code", "execution_count": null, - "id": "41ab0564", + "id": "c20ba346", "metadata": {}, "outputs": [], "source": [ @@ -46,9 +46,19 @@ " print(\"PrimeHub Python SDK couldn't get the group information, follow the 00-getting-started.ipynb to complete it\")" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "a7f05141", + "metadata": {}, + "outputs": [], + "source": [ + "ph.config.set_group('InfuseAI')" + ] + }, { "cell_type": "markdown", - "id": "4495f6db", + "id": "5119e951", "metadata": {}, "source": [ "## Help documentation" @@ -57,7 +67,7 @@ { "cell_type": "code", "execution_count": null, - "id": "22303d24", + "id": "40701baa", "metadata": {}, "outputs": [], "source": [ @@ -66,7 +76,7 @@ }, { "cell_type": "markdown", - "id": "97735451", + "id": "a54dad1a", "metadata": {}, "source": [ "## Examples" @@ -74,31 +84,78 @@ }, { "cell_type": "markdown", - "id": "b60126b5", + "id": "2630ffb0", "metadata": {}, "source": [ - "### Get detail information of jobs" + "### submit: submit a job from a file or a recurring job" ] }, { "cell_type": "code", "execution_count": null, - "id": "027a5b54", + "id": "6fbdc675", "metadata": {}, "outputs": [], "source": [ - "# List all jobs or with page number\n", + "# Submit a job\n", + "config = {\n", + " \"instanceType\": \"cpu-1\",\n", + " \"image\": \"base-notebook\",\n", + " \"displayName\": \"short-job\",\n", + " \"command\": \"\"\"echo 'test1' \"\"\",\n", + "}\n", + "\n", + "short_job = ph.jobs.submit(config)\n", + "print(short_job)" + ] + }, + { + "cell_type": "markdown", + "id": "02e6c101", + "metadata": {}, + "source": [ + "### List: list all jobs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7668b6c0", + "metadata": {}, + "outputs": [], + "source": [ + "# List all jobs\n", + "\n", "all_jobs = ph.jobs.list()\n", + "for job in all_jobs:\n", + " print(job)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "93d8d17c", + "metadata": {}, + "outputs": [], + "source": [ + "# List the jobs in page 1\n", "job_page_1 = ph.jobs.list(page = 1)\n", - "\n", - "print(\"Number of all jobs:\", len(all_jobs))\n", - "print(\"Number of jobs at page 1:\", len(job_page_1))" + "for job in job_page_1:\n", + " print(job)" + ] + }, + { + "cell_type": "markdown", + "id": "90a00c07", + "metadata": {}, + "source": [ + "### Get: Get detail information of jobs" ] }, { "cell_type": "code", "execution_count": null, - "id": "4b6f6f09", + "id": "de6a9e35", "metadata": {}, "outputs": [], "source": [ @@ -108,16 +165,16 @@ }, { "cell_type": "markdown", - "id": "74d368b5", + "id": "5136552e", "metadata": {}, "source": [ - "### Submit jobs and get the logs" + "### Wait: wait a job until timeout or finish" ] }, { "cell_type": "code", "execution_count": null, - "id": "c4627c3a", + "id": "de3d49c4", "metadata": {}, "outputs": [], "source": [ @@ -126,36 +183,50 @@ " \"instanceType\": \"cpu-1\",\n", " \"image\": \"base-notebook\",\n", " \"displayName\": \"short-job\",\n", - " \"command\": \"echo \\\"test1\\\"\\necho \\\"test2\\\"\",\n", + " \"command\": \"\"\"echo 'test1' \"\"\",\n", "}\n", "\n", "short_job = ph.jobs.submit(config)\n", - "print(short_job)" + "print('[ Done: Submit the new job ]')\n", + "\n", + "# Wait the job to be done\n", + "print('[ Waiting ]')\n", + "ph.jobs.wait(short_job['id'])\n", + "print('[ Job Done ]')\n", + "\n", + "# Get logs\n", + "logs = ph.jobs.logs(short_job['id'])\n", + "print('[ Job Logs ]')\n", + "for l in logs:\n", + " print(l)" + ] + }, + { + "cell_type": "markdown", + "id": "61e98393", + "metadata": {}, + "source": [ + "### logs: get job logs by id" ] }, { "cell_type": "code", "execution_count": null, - "id": "f88c3700", + "id": "1bdccbe0", "metadata": {}, "outputs": [], "source": [ - "# Wait the job to be done\n", - "print('[ Waiting ]')\n", - "ph.jobs.wait(short_job['id'])\n", - "print('[ Job Done ]')\n", - "\n", "# Get logs\n", "logs = ph.jobs.logs(short_job['id'])\n", "print('[ Job Logs ]')\n", "for l in logs:\n", - " print(l)" + " print(l.decode('utf-8'))" ] }, { "cell_type": "code", "execution_count": null, - "id": "067bb7fa", + "id": "093e9a62", "metadata": {}, "outputs": [], "source": [ @@ -166,44 +237,57 @@ " 'displayName': 'long-job',\n", " 'command': 'for i in {1..10}; do echo $i; sleep 1; done',\n", "}\n", - "long_job = ph.jobs.submit(config)\n", + "long_job = ph.jobs.submit(config)\n", "\n", - "##\n", - "## TODO: need a way to wait unitl the job is running before get the logs\n", - "##\n", + "print('[ Waiting ]')\n", "ph.jobs.wait(long_job['id'], timeout=10)\n", + "print('[ Job Done ]')\n", + "\n", "\n", "logs = ph.jobs.logs(long_job['id'], follow=True)\n", "print('[ Job Logs ]')\n", "for l in logs:\n", - " print(l)" + " print(l.decode('utf-8'))" ] }, { "cell_type": "markdown", - "id": "74009ccf", + "id": "bbed769e", "metadata": {}, "source": [ - "### Rerun and cancel the job" + "### rerun: rerun a job by id" ] }, { "cell_type": "code", "execution_count": null, - "id": "31eb4160", + "id": "c918d245", "metadata": {}, "outputs": [], "source": [ "# Rerun the job\n", "rerun_job = ph.jobs.rerun(long_job['id'])\n", "print('Rerun Job:')\n", - "print(rerun_job)\n", - "\n", - "##\n", - "## TODO: need a way to wait unitl the job is running before get the logs\n", - "##\n", - "import time\n", - "ph.jobs.wait(rerun_job['id'], timeout=10)\n", + "print(rerun_job)" + ] + }, + { + "cell_type": "markdown", + "id": "76537ec3", + "metadata": {}, + "source": [ + "### cancel: cancel a job by id" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "223a9df5", + "metadata": {}, + "outputs": [], + "source": [ + "# import time\n", + "# ph.jobs.wait(rerun_job['id'], timeout=10)\n", "\n", "# Cancel the job\n", "cancel_job = ph.jobs.cancel(rerun_job['id'])\n", @@ -213,17 +297,17 @@ }, { "cell_type": "markdown", - "id": "fb8075ef", + "id": "08d02dd7", "metadata": {}, "source": [ - "### Job Artifacts\n", - "more information: https://docs.primehub.io/docs/job-artifact-feature" + "### Job Artifacts: List and download\n", + "more information: https://docs-v4.primehub.io/user-guide/jobs-recurring-jobs/job-artifacts" ] }, { "cell_type": "code", "execution_count": null, - "id": "12c7d57d", + "id": "34656d8e", "metadata": {}, "outputs": [], "source": [ @@ -243,7 +327,7 @@ { "cell_type": "code", "execution_count": null, - "id": "4188c445", + "id": "89e72220", "metadata": {}, "outputs": [], "source": [ @@ -254,7 +338,7 @@ { "cell_type": "code", "execution_count": null, - "id": "4715b7bf", + "id": "edc1da2c", "metadata": {}, "outputs": [], "source": [ @@ -266,7 +350,7 @@ { "cell_type": "code", "execution_count": null, - "id": "918d7233", + "id": "97e77a58", "metadata": {}, "outputs": [], "source": [ @@ -278,7 +362,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -292,7 +376,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.10" + "version": "3.7.12" } }, "nbformat": 4, diff --git a/docs/notebook/recurring-jobs.ipynb b/docs/notebook/user-portal/03-2-recurring-jobs.ipynb similarity index 66% rename from docs/notebook/recurring-jobs.ipynb rename to docs/notebook/user-portal/03-2-recurring-jobs.ipynb index 9601dd86..34c9f364 100644 --- a/docs/notebook/recurring-jobs.ipynb +++ b/docs/notebook/user-portal/03-2-recurring-jobs.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "f65cec1f", + "id": "77691722", "metadata": {}, "source": [ "# RecurringJobs command\n", @@ -20,7 +20,7 @@ }, { "cell_type": "markdown", - "id": "500f0bcf", + "id": "d8a41b52", "metadata": {}, "source": [ "## Setup PrimeHub Python SDK\n" @@ -29,7 +29,7 @@ { "cell_type": "code", "execution_count": null, - "id": "1b11685e", + "id": "7e9f851e", "metadata": {}, "outputs": [], "source": [ @@ -42,82 +42,54 @@ " print(\"PrimeHub Python SDK couldn't get the group information, follow the 00-getting-started.ipynb to complete it\")" ] }, - { - "cell_type": "markdown", - "id": "85a6c027", - "metadata": {}, - "source": [ - "## Help documentation" - ] - }, { "cell_type": "code", "execution_count": null, - "id": "660d7c60", + "id": "3f695331", "metadata": {}, "outputs": [], "source": [ - "help(ph.recurring_jobs)" + "ph.config.set_group('InfuseAI')" ] }, { "cell_type": "markdown", - "id": "77cc00ee", + "id": "aa7156e4", "metadata": {}, "source": [ - "## Examples" - ] - }, - { - "cell_type": "markdown", - "id": "45bfcd08", - "metadata": {}, - "source": [ - "### Get detail information of recurring jobs" + "## Help documentation" ] }, { "cell_type": "code", "execution_count": null, - "id": "36ab06e9", + "id": "cd8716c6", "metadata": {}, "outputs": [], "source": [ - "# List all jobs or with page number\n", - "all_recurring_jobs = ph.recurring_jobs.list()\n", - "recurring_job_page_1 = ph.recurring_jobs.list(page = 1)\n", - "\n", - "all_recurring_jobs = list(all_recurring_jobs)\n", - "recurring_job_page_1 = list(recurring_job_page_1)\n", - "print(\"Number of all jobs:\", len(all_recurring_jobs))\n", - "print(\"Number of jobs at page 1:\", len(recurring_job_page_1))" + "help(ph.recurring_jobs)" ] }, { - "cell_type": "code", - "execution_count": null, - "id": "8e3e4380", + "cell_type": "markdown", + "id": "4eba8887", "metadata": {}, - "outputs": [], "source": [ - "# Get detail information by id\n", - "# ph.recurring_jobs.get(id='')\n", - "\n", - "ph.recurring_jobs.get(id=all_recurring_jobs[0]['id'])\n" + "## Examples" ] }, { "cell_type": "markdown", - "id": "e8ab61f1", + "id": "436a87e0", "metadata": {}, "source": [ - "### Create, Update, and Delete Recurring Jobs" + "### create: create a recurring job" ] }, { "cell_type": "code", "execution_count": null, - "id": "6e51432e", + "id": "240e930d", "metadata": {}, "outputs": [], "source": [ @@ -133,14 +105,22 @@ " }\n", "}\n", "\n", - "recurring_job = ph.recurring_jobs.create(config)\n", + "recurring_job_submit = ph.recurring_jobs.create(config)\n", "print(recurring_job)" ] }, + { + "cell_type": "markdown", + "id": "c9af9f94", + "metadata": {}, + "source": [ + "### update: update a recurring job" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "8fb60dec", + "id": "6e714d85", "metadata": {}, "outputs": [], "source": [ @@ -151,25 +131,90 @@ " \"cron\":\"0 2 * * *\"\n", " }\n", "}\n", - "recurring_job = ph.recurring_jobs.update(recurring_job['id'], config)\n", - "print(recurring_job)" + "recurring_job_submit = ph.recurring_jobs.update(recurring_job_submit['id'], config)\n", + "print(recurring_job_submit)" + ] + }, + { + "cell_type": "markdown", + "id": "051ea78f", + "metadata": {}, + "source": [ + "### list: list all recurring jobs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "69afd847", + "metadata": {}, + "outputs": [], + "source": [ + "# List all recurring jobs\n", + "all_recurring_jobs = ph.recurring_jobs.list()\n", + "\n", + "for recurring_job in all_recurring_jobs:\n", + " print(recurring_job)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "615d2cd7", + "metadata": {}, + "outputs": [], + "source": [ + "# List the recurring jobs in page 1\n", + "\n", + "recurring_job_page_1 = ph.recurring_jobs.list(page = 1)\n", + "\n", + "for recurring_job in recurring_job_page_1:\n", + " print(recurring_job)" + ] + }, + { + "cell_type": "markdown", + "id": "3c94517e", + "metadata": {}, + "source": [ + "### get: get a recurring job information by id" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "997305e9", + "metadata": {}, + "outputs": [], + "source": [ + "# Get detail information by id\n", + "# ph.recurring_jobs.get(id='')\n", + "ph.recurring_jobs.get(id=recurring_job_submit['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "8385a6b9", + "metadata": {}, + "source": [ + "### delete: delete a recurring job" ] }, { "cell_type": "code", "execution_count": null, - "id": "483be712", + "id": "b543afbf", "metadata": {}, "outputs": [], "source": [ "# Delete a recurring_job by id\n", - "ph.recurring_jobs.delete(recurring_job['id'])" + "ph.recurring_jobs.delete(recurring_job_submit['id'])" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -183,7 +228,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.10" + "version": "3.7.12" } }, "nbformat": 4, diff --git a/docs/notebook/user-portal/04-models.ipynb b/docs/notebook/user-portal/04-models.ipynb new file mode 100644 index 00000000..b0a3f5b3 --- /dev/null +++ b/docs/notebook/user-portal/04-models.ipynb @@ -0,0 +1,375 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "9c8e2ef1", + "metadata": {}, + "source": [ + "# Models command\n", + "\n", + "### Introduction\n", + "\n", + "The `models` command can manage models in the current group.\n", + "\n", + "\n", + "* deploy: Deploy the model version to the speific deployment\n", + "* get: Get the model\n", + "* get-version: Get a version of the model\n", + "* list: List models\n", + "* list-versions: List versions of the model" + ] + }, + { + "cell_type": "markdown", + "id": "06bfb770", + "metadata": {}, + "source": [ + "## Setup PrimeHub Python SDK\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "141a5d41", + "metadata": {}, + "outputs": [], + "source": [ + "from primehub import PrimeHub, PrimeHubConfig\n", + "ph = PrimeHub(PrimeHubConfig())\n", + "\n", + "if ph.is_ready():\n", + " print(\"PrimeHub Python SDK setup successfully\")\n", + "else:\n", + " print(\"PrimeHub Python SDK couldn't get the group information, follow the 00-getting-started.ipynb to complete it\")" + ] + }, + { + "cell_type": "markdown", + "id": "8f921b8d", + "metadata": {}, + "source": [ + "## Help documentation" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "13e7149a", + "metadata": {}, + "outputs": [], + "source": [ + "help(ph.models)" + ] + }, + { + "cell_type": "markdown", + "id": "8329e793", + "metadata": {}, + "source": [ + "## Examples" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ee8fb3f4", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bc0fa5e3", + "metadata": {}, + "outputs": [], + "source": [ + "# Please change the mlflow experence name\n", + "MLFLOW_EXPERIENCE_NAME = ''" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b63eb412", + "metadata": {}, + "outputs": [], + "source": [ + "# Please change the register model name\n", + "REGISTER_MODEL_NAME = ''" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "895c0fed", + "metadata": {}, + "outputs": [], + "source": [ + "# Please change the register model folder name\n", + "REGISTER_MODEL_FOLDER = ''" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2b2f098a", + "metadata": {}, + "outputs": [], + "source": [ + "# Please change the register version tag\n", + "VERSION_TAG = '1'" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "24ebfdb6", + "metadata": {}, + "outputs": [], + "source": [ + "# Please change the Primehub deployment id for model deploy\n", + "DEPLOYMENT_ID = ''" + ] + }, + { + "cell_type": "markdown", + "id": "289cea8b", + "metadata": {}, + "source": [ + "### List MLFlow Experiments runs" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0afc7694", + "metadata": {}, + "outputs": [], + "source": [ + "list_runs = ph.models.list_runs(MLFLOW_EXPERIENCE_NAME)\n", + "\n", + "df = pd.DataFrame(list_runs)\n", + "df.head()" + ] + }, + { + "cell_type": "markdown", + "id": "8c8a9c24", + "metadata": {}, + "source": [ + "### List artifacts by run id" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7d7bfa33", + "metadata": {}, + "outputs": [], + "source": [ + "# Note: df['runId'][0] means the latest run id.\n", + "latest_run_id = df['runId'][0]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "31b3b5e3", + "metadata": {}, + "outputs": [], + "source": [ + "df_artifacts = pd.DataFrame(ph.models.list_artifacts(latest_run_id))\n", + "df_artifacts" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "56914969", + "metadata": {}, + "outputs": [], + "source": [ + "df_artifacts = pd.DataFrame(ph.models.list_artifacts(latest_run_id, path=REGISTER_MODEL_FOLDER))\n", + "df_artifacts" + ] + }, + { + "cell_type": "markdown", + "id": "d627e4a7", + "metadata": {}, + "source": [ + "### Register model\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "10bbfa14", + "metadata": {}, + "outputs": [], + "source": [ + "ph.models.register(REGISTER_MODEL_NAME, latest_run_id, REGISTER_MODEL_FOLDER)" + ] + }, + { + "cell_type": "markdown", + "id": "a5847dbd", + "metadata": {}, + "source": [ + "### List the created model" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bc53ca01", + "metadata": {}, + "outputs": [], + "source": [ + "# List all models\n", + "models = ph.models.list()\n", + "pd.DataFrame(models)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "3d46ac6b", + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
nameversioncreationTimestamplastUpdatedTimestampsourcedeployedBy
0screw-detection-model12023-03-30 10:41:552023-03-30 10:41:55/project/infuseai/phapplications/mlflow-4jjdy/...[]
\n", + "
" + ], + "text/plain": [ + " name version creationTimestamp lastUpdatedTimestamp \\\n", + "0 screw-detection-model 1 2023-03-30 10:41:55 2023-03-30 10:41:55 \n", + "\n", + " source deployedBy \n", + "0 /project/infuseai/phapplications/mlflow-4jjdy/... [] " + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# List model version content\n", + "pd.DataFrame(ph.models.list_versions(REGISTER_MODEL_NAME))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ce9951a8", + "metadata": {}, + "outputs": [], + "source": [ + "ph.models.get_version(REGISTER_MODEL_NAME, VERSION_TAG)" + ] + }, + { + "cell_type": "markdown", + "id": "45f22a98", + "metadata": {}, + "source": [ + "### Get detail information of models" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6388445e", + "metadata": {}, + "outputs": [], + "source": [ + "# Get detail information by model name\n", + "ph.models.get(REGISTER_MODEL_NAME)" + ] + }, + { + "cell_type": "markdown", + "id": "4a809989", + "metadata": {}, + "source": [ + "### Deploy a model to existing deployments" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1609d47d", + "metadata": {}, + "outputs": [], + "source": [ + "# Deploy the model with specific version \n", + "ph.models.deploy(REGISTER_MODEL_NAME, VERSION_TAG, DEPLOYMENT_ID)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/docs/notebook/deployments.ipynb b/docs/notebook/user-portal/05-deployments.ipynb similarity index 89% rename from docs/notebook/deployments.ipynb rename to docs/notebook/user-portal/05-deployments.ipynb index 7c5c2e17..3e15565e 100644 --- a/docs/notebook/deployments.ipynb +++ b/docs/notebook/user-portal/05-deployments.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "ee9de151", + "id": "a4a76d9e", "metadata": {}, "source": [ "# Deployments command\n", @@ -25,7 +25,7 @@ }, { "cell_type": "markdown", - "id": "ec110dfc", + "id": "5fce5c26", "metadata": {}, "source": [ "## Setup PrimeHub Python SDK\n" @@ -34,7 +34,7 @@ { "cell_type": "code", "execution_count": null, - "id": "582cf4cf", + "id": "377307ae", "metadata": {}, "outputs": [], "source": [ @@ -49,7 +49,7 @@ }, { "cell_type": "markdown", - "id": "c1e305c3", + "id": "217bd200", "metadata": {}, "source": [ "## Help documentation" @@ -58,7 +58,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ea3abe15", + "id": "91d2d326", "metadata": {}, "outputs": [], "source": [ @@ -67,7 +67,7 @@ }, { "cell_type": "markdown", - "id": "1a1ff9ad", + "id": "6ee4ba07", "metadata": {}, "source": [ "## Examples\n", @@ -110,7 +110,7 @@ }, { "cell_type": "markdown", - "id": "aad2b7f0", + "id": "82be5c0e", "metadata": {}, "source": [ "### Get detail information of deployments" @@ -119,18 +119,28 @@ { "cell_type": "code", "execution_count": null, - "id": "394482dc", + "id": "b506bcfd", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c360bc73", "metadata": {}, "outputs": [], "source": [ "# List all deployments\n", - "ph.deployments.list()" + "pd.DataFrame(ph.deployments.list())" ] }, { "cell_type": "code", "execution_count": null, - "id": "be35a6d4", + "id": "d79fbfe2", "metadata": {}, "outputs": [], "source": [ @@ -138,9 +148,20 @@ "ph.deployments.get('')" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "3bf20745", + "metadata": {}, + "outputs": [], + "source": [ + "# Get detail information by id\n", + "ph.deployments.get_history('')" + ] + }, { "cell_type": "markdown", - "id": "d3805adc", + "id": "f945a6d0", "metadata": {}, "source": [ "### Create, update, and delete deployments" @@ -149,7 +170,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d4f8b107", + "id": "dd181cd1", "metadata": {}, "outputs": [], "source": [ @@ -170,7 +191,7 @@ { "cell_type": "code", "execution_count": null, - "id": "8b3eff75", + "id": "56393318", "metadata": {}, "outputs": [], "source": [ @@ -185,7 +206,7 @@ { "cell_type": "code", "execution_count": null, - "id": "31b19ea2", + "id": "eb9a0491", "metadata": {}, "outputs": [], "source": [ @@ -195,7 +216,7 @@ }, { "cell_type": "markdown", - "id": "072d0ab8", + "id": "e1661ab4", "metadata": {}, "source": [ "### Start, stop, and wait deployments" @@ -204,7 +225,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c420dfb2", + "id": "f133b3c4", "metadata": {}, "outputs": [], "source": [ @@ -215,7 +236,7 @@ { "cell_type": "code", "execution_count": null, - "id": "1d99431b", + "id": "a0133e57", "metadata": {}, "outputs": [], "source": [ @@ -226,7 +247,7 @@ { "cell_type": "code", "execution_count": null, - "id": "f780e2fe", + "id": "843cde39", "metadata": {}, "outputs": [], "source": [ @@ -239,7 +260,7 @@ { "cell_type": "code", "execution_count": null, - "id": "ff7211e0", + "id": "b116d3f2", "metadata": {}, "outputs": [], "source": [ @@ -249,7 +270,7 @@ }, { "cell_type": "markdown", - "id": "c66ef1a1", + "id": "a294ac50", "metadata": {}, "source": [ "### Get deployment logs" @@ -258,7 +279,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c6e0a818", + "id": "2be80bcb", "metadata": {}, "outputs": [], "source": [ @@ -272,7 +293,7 @@ { "cell_type": "code", "execution_count": null, - "id": "65b85bf7", + "id": "6cd5b889", "metadata": {}, "outputs": [], "source": [ @@ -286,7 +307,7 @@ { "cell_type": "code", "execution_count": null, - "id": "e2cd18d8", + "id": "90ac98a5", "metadata": {}, "outputs": [], "source": [ @@ -314,7 +335,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.7.12" } }, "nbformat": 4, diff --git a/docs/notebook/files.ipynb b/docs/notebook/user-portal/06-shared-files.ipynb similarity index 83% rename from docs/notebook/files.ipynb rename to docs/notebook/user-portal/06-shared-files.ipynb index 16745824..f45b582d 100644 --- a/docs/notebook/files.ipynb +++ b/docs/notebook/user-portal/06-shared-files.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "81faa403", + "id": "f976ff4f", "metadata": {}, "source": [ "# Files command\n", @@ -19,7 +19,7 @@ }, { "cell_type": "markdown", - "id": "17fe5031", + "id": "38a549d6", "metadata": {}, "source": [ "## Setup PrimeHub Python SDK\n" @@ -28,7 +28,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d096d6e9", + "id": "79c79d04", "metadata": {}, "outputs": [], "source": [ @@ -43,7 +43,7 @@ }, { "cell_type": "markdown", - "id": "1e6f600f", + "id": "79358abe", "metadata": {}, "source": [ "## Help documentation" @@ -52,7 +52,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c0c4858d", + "id": "41d387cb", "metadata": {}, "outputs": [], "source": [ @@ -61,7 +61,7 @@ }, { "cell_type": "markdown", - "id": "6d67de85", + "id": "0ee3f1f8", "metadata": {}, "source": [ "## Examples" @@ -69,7 +69,7 @@ }, { "cell_type": "markdown", - "id": "20a4a878", + "id": "b75ebe2b", "metadata": {}, "source": [ "### List files and folders in a path\n", @@ -82,18 +82,28 @@ { "cell_type": "code", "execution_count": null, - "id": "a631005f", + "id": "a2274180", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a257b817", "metadata": {}, "outputs": [], "source": [ "# List files and folders in a path\n", "files = ph.files.list('/')\n", - "print(files)" + "pd.DataFrame(files)" ] }, { "cell_type": "markdown", - "id": "8c2ffb2a", + "id": "de550c74", "metadata": {}, "source": [ "### Upload a file or directory \n", @@ -107,7 +117,7 @@ { "cell_type": "code", "execution_count": null, - "id": "13d0be70", + "id": "7e7d6f71", "metadata": {}, "outputs": [], "source": [ @@ -128,7 +138,25 @@ }, { "cell_type": "markdown", - "id": "81049e29", + "id": "d658f7ac", + "metadata": {}, + "source": [ + "### Get the phfs file path" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "58a4234c", + "metadata": {}, + "outputs": [], + "source": [ + "ph.files.get_phfs_uri('')" + ] + }, + { + "cell_type": "markdown", + "id": "0b9a2be8", "metadata": {}, "source": [ "### Download a file or a directory\n", @@ -139,7 +167,7 @@ { "cell_type": "code", "execution_count": null, - "id": "bff42f30", + "id": "0bc61788", "metadata": {}, "outputs": [], "source": [ @@ -151,7 +179,7 @@ }, { "cell_type": "markdown", - "id": "5d1e97f4", + "id": "c09425b1", "metadata": {}, "source": [ "### Delete a file or a directory\n", @@ -162,7 +190,7 @@ { "cell_type": "code", "execution_count": null, - "id": "074a267c", + "id": "9aebda72", "metadata": {}, "outputs": [], "source": [ @@ -184,7 +212,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -198,7 +226,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.5" + "version": "3.7.12" } }, "nbformat": 4, diff --git a/docs/notebook/datasets.ipynb b/docs/notebook/user-portal/07-datasets.ipynb similarity index 93% rename from docs/notebook/datasets.ipynb rename to docs/notebook/user-portal/07-datasets.ipynb index 9b20612c..24409940 100644 --- a/docs/notebook/datasets.ipynb +++ b/docs/notebook/user-portal/07-datasets.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "81faa403", + "id": "c7f78123", "metadata": {}, "source": [ "# PrimeHub Datasets\n", @@ -14,7 +14,7 @@ }, { "cell_type": "markdown", - "id": "17fe5031", + "id": "e50096c8", "metadata": {}, "source": [ "## Setup PrimeHub Python SDK\n" @@ -23,7 +23,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d096d6e9", + "id": "cdf4e091", "metadata": {}, "outputs": [], "source": [ @@ -38,7 +38,7 @@ }, { "cell_type": "markdown", - "id": "1e6f600f", + "id": "9131bc63", "metadata": {}, "source": [ "## Help documentation" @@ -47,7 +47,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c0c4858d", + "id": "e8a4beb6", "metadata": {}, "outputs": [], "source": [ @@ -56,7 +56,7 @@ }, { "cell_type": "markdown", - "id": "874146fb", + "id": "39ad3dcb", "metadata": {}, "source": [ "## Datasets management\n", @@ -105,7 +105,7 @@ }, { "cell_type": "markdown", - "id": "6d67de85", + "id": "baf09118", "metadata": {}, "source": [ "## Examples" @@ -113,7 +113,7 @@ }, { "cell_type": "markdown", - "id": "20a4a878", + "id": "10682bb1", "metadata": {}, "source": [ "### Create a datasets\n", @@ -124,7 +124,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a631005f", + "id": "dbf67072", "metadata": {}, "outputs": [], "source": [ @@ -138,7 +138,7 @@ }, { "cell_type": "markdown", - "id": "934556de", + "id": "885cd057", "metadata": {}, "source": [ "### List datasets or get the dataset\n", @@ -148,7 +148,7 @@ { "cell_type": "code", "execution_count": null, - "id": "227e26ba", + "id": "b69b625a", "metadata": {}, "outputs": [], "source": [ @@ -164,7 +164,7 @@ }, { "cell_type": "markdown", - "id": "8c2ffb2a", + "id": "24207bae", "metadata": {}, "source": [ "### Update a dataset\n", @@ -175,7 +175,7 @@ { "cell_type": "code", "execution_count": null, - "id": "13d0be70", + "id": "16d02076", "metadata": {}, "outputs": [], "source": [ @@ -188,28 +188,7 @@ }, { "cell_type": "markdown", - "id": "ddaeda83", - "metadata": {}, - "source": [ - "### Delete a dataset\n", - "\n", - "With `delete`, we could delete the whole dataset with its files." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "bdf1fb6a", - "metadata": {}, - "outputs": [], - "source": [ - "result = ph.datasets.delete(dataset['name'])\n", - "print(result)" - ] - }, - { - "cell_type": "markdown", - "id": "81049e29", + "id": "2dc043a3", "metadata": {}, "source": [ "### Upload files to the dataset with given path\n", @@ -222,7 +201,7 @@ { "cell_type": "code", "execution_count": null, - "id": "bff42f30", + "id": "58491dd4", "metadata": {}, "outputs": [], "source": [ @@ -239,7 +218,7 @@ }, { "cell_type": "markdown", - "id": "bc737d79", + "id": "5c69be13", "metadata": {}, "source": [ "### List files of the dataset with given path\n", @@ -251,7 +230,7 @@ { "cell_type": "code", "execution_count": null, - "id": "5bdb7589", + "id": "5b8a5218", "metadata": {}, "outputs": [], "source": [ @@ -265,7 +244,7 @@ }, { "cell_type": "markdown", - "id": "9faefaa0", + "id": "d45b277e", "metadata": {}, "source": [ "### Download files from the dataset with given path\n", @@ -275,7 +254,7 @@ { "cell_type": "code", "execution_count": null, - "id": "9cb329d9", + "id": "1f15041b", "metadata": {}, "outputs": [], "source": [ @@ -285,7 +264,7 @@ }, { "cell_type": "markdown", - "id": "e6796ee0", + "id": "65d6e4ad", "metadata": {}, "source": [ "### Delete a single file or a specific directory from the dataset with given path\n", @@ -295,7 +274,7 @@ { "cell_type": "code", "execution_count": null, - "id": "94580374", + "id": "d2708df0", "metadata": {}, "outputs": [], "source": [ @@ -310,11 +289,32 @@ "files = ph.datasets.files_list('test-dataset', '/')\n", "print(files) # empty" ] + }, + { + "cell_type": "markdown", + "id": "46d97c8a", + "metadata": {}, + "source": [ + "### Delete a dataset\n", + "\n", + "With `delete`, we could delete the whole dataset with its files." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7bf6ec07", + "metadata": {}, + "outputs": [], + "source": [ + "result = ph.datasets.delete(dataset['name'])\n", + "print(result)" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -328,7 +328,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.7" + "version": "3.7.12" } }, "nbformat": 4, diff --git a/docs/notebook/apps.ipynb b/docs/notebook/user-portal/08-1-apps.ipynb similarity index 73% rename from docs/notebook/apps.ipynb rename to docs/notebook/user-portal/08-1-apps.ipynb index 2c942f2d..5b225a05 100644 --- a/docs/notebook/apps.ipynb +++ b/docs/notebook/user-portal/08-1-apps.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "c21ec6cb", + "id": "01d701c2", "metadata": {}, "source": [ "# Apps command\n", @@ -22,7 +22,7 @@ }, { "cell_type": "markdown", - "id": "65d28291", + "id": "4e53afd5", "metadata": {}, "source": [ "## Setup PrimeHub Python SDK\n" @@ -31,7 +31,7 @@ { "cell_type": "code", "execution_count": null, - "id": "41ab0564", + "id": "3c26a109", "metadata": {}, "outputs": [], "source": [ @@ -46,7 +46,7 @@ }, { "cell_type": "markdown", - "id": "4495f6db", + "id": "2df0b154", "metadata": {}, "source": [ "## Help documentation" @@ -55,7 +55,7 @@ { "cell_type": "code", "execution_count": null, - "id": "22303d24", + "id": "387cd023", "metadata": {}, "outputs": [], "source": [ @@ -64,7 +64,7 @@ }, { "cell_type": "markdown", - "id": "97735451", + "id": "d1f12e60", "metadata": {}, "source": [ "## Examples\n", @@ -103,75 +103,84 @@ }, { "cell_type": "markdown", - "id": "4d26b524", + "id": "3c58ab8e", "metadata": {}, "source": [ - "### List apps" + "### create: Install an application" ] }, { "cell_type": "code", "execution_count": null, - "id": "22e1502d", + "id": "c4464734", "metadata": {}, "outputs": [], "source": [ - "apps = ph.apps.list()\n", - "print(f'Number of apps: {len(list(apps))}')" + "# create an application\n", + "import uuid\n", + "random_id = uuid.uuid4().hex[:5]\n", + "\n", + "config = {\n", + " \"templateId\": \"code-server\",\n", + " \"id\": f\"code-server-{random_id}\",\n", + " \"displayName\": f\"my-code-server-{random_id}\",\n", + " \"env\": [\n", + " {\n", + " \"name\": \"key1\",\n", + " \"value\": \"value1\"\n", + " }\n", + " ],\n", + " \"instanceType\": \"cpu-1\",\n", + " \"scope\": \"primehub\"\n", + "}\n", + "result = ph.apps.create(config)\n", + "app = result['id']\n", + "print(result)\n" ] }, { "cell_type": "markdown", - "id": "e4dee3c3", + "id": "1b2ca98c", "metadata": {}, "source": [ - "### operate an app" + "### list: List PrimeHub Applications" ] }, { "cell_type": "code", "execution_count": null, - "id": "995ab764", + "id": "4a22b0f9", "metadata": {}, "outputs": [], "source": [ - "# see the configuration example with `create`\n", - "!primehub apps create" + "apps = ph.apps.list()\n", + "print(f'Number of apps: {len(list(apps))}')" ] }, { "cell_type": "code", "execution_count": null, - "id": "8930a390", + "id": "61a97518", "metadata": {}, "outputs": [], "source": [ - "# create an application\n", - "import uuid\n", - "random_id = uuid.uuid4().hex[:5]\n", - "\n", - "config = {\n", - " \"templateId\": \"code-server\",\n", - " \"id\": f\"code-server-{random_id}\",\n", - " \"displayName\": f\"my-code-server-{random_id}\",\n", - " \"env\": [\n", - " {\n", - " \"name\": \"key1\",\n", - " \"value\": \"value1\"\n", - " }\n", - " ],\n", - " \"instanceType\": \"cpu-1\",\n", - " \"scope\": \"primehub\"\n", - "}\n", - "result = ph.apps.create(config)\n", - "app = result['id']\n", - "print(result)\n" + "import pandas as pd\n", + "apps = ph.apps.list()\n", + "pd.DataFrame(apps)" + ] + }, + { + "cell_type": "markdown", + "id": "7d9f994c", + "metadata": {}, + "source": [ + "#### Note: Remove appIcon because the appIcon value is too long.\n" ] }, { "cell_type": "code", "execution_count": null, - "id": "e82e45fa", + "id": "4ac19bf6", "metadata": {}, "outputs": [], "source": [ @@ -181,39 +190,77 @@ " return result" ] }, + { + "cell_type": "markdown", + "id": "4f86f6d8", + "metadata": {}, + "source": [ + "### get: Get one PrimeHub Application Information" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "f3b94a7a", + "id": "872ea6d3", "metadata": {}, "outputs": [], "source": [ - "# show app icon\n", "result = ph.apps.get(app)\n", + "result_without_icon(result)" + ] + }, + { + "cell_type": "markdown", + "id": "1e7463ab", + "metadata": {}, + "source": [ + "### update: Update an application" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b60fb125", + "metadata": {}, + "outputs": [], + "source": [ + "config = {'scope': 'public'}\n", "\n", - "from IPython import display\n", - "from base64 import b64decode\n", - "\n", - "icon_data = result['appIcon']\n", - "icon_data = icon_data[len('data:image/png;base64,'):]\n", - "display.Image(b64decode(icon_data))" + "ph.apps.update(app, config)\n", + "result = ph.apps.get(app)\n", + "result_without_icon(result)" + ] + }, + { + "cell_type": "markdown", + "id": "c0adeda6", + "metadata": {}, + "source": [ + "### logs: Get logs of the PrimeHub Application by id" ] }, { "cell_type": "code", "execution_count": null, - "id": "aa0472c2", + "id": "e70f4bea", "metadata": {}, "outputs": [], "source": [ - "# get the application\n", - "result_without_icon(ph.apps.get(app))" + "result_without_icon(ph.apps.logs(app))" + ] + }, + { + "cell_type": "markdown", + "id": "9460e1c1", + "metadata": {}, + "source": [ + "### stop: Stop the PrimeHub Application" ] }, { "cell_type": "code", "execution_count": null, - "id": "74724d03", + "id": "370fa3be", "metadata": {}, "outputs": [], "source": [ @@ -221,42 +268,50 @@ "result_without_icon(ph.apps.stop(app))" ] }, + { + "cell_type": "markdown", + "id": "70211c6f", + "metadata": {}, + "source": [ + "### start: Start the PrimeHub Application" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "ed53abb0", + "id": "599a26ed", "metadata": {}, "outputs": [], "source": [ - "# start the application\n", + "# stop the application\n", "result_without_icon(ph.apps.start(app))" ] }, { - "cell_type": "code", - "execution_count": null, - "id": "0bc9f4e5", + "cell_type": "markdown", + "id": "2cc996cc", "metadata": {}, - "outputs": [], "source": [ - "# delete the application\n", - "result_without_icon(ph.apps.delete(app))" + "### delete: Stop the PrimeHub Application" ] }, { "cell_type": "code", "execution_count": null, - "id": "8ef60389", + "id": "73bf1eef", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# delete the application\n", + "result_without_icon(ph.apps.delete(app))" + ] } ], "metadata": { "kernelspec": { - "display_name": "PrimeHub SDK", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": "myenv" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -268,7 +323,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.7.12" } }, "nbformat": 4, diff --git a/docs/notebook/apptemplates.ipynb b/docs/notebook/user-portal/08-2-apptemplates.ipynb similarity index 81% rename from docs/notebook/apptemplates.ipynb rename to docs/notebook/user-portal/08-2-apptemplates.ipynb index 1506ea5e..e67635f8 100644 --- a/docs/notebook/apptemplates.ipynb +++ b/docs/notebook/user-portal/08-2-apptemplates.ipynb @@ -2,6 +2,7 @@ "cells": [ { "cell_type": "markdown", + "id": "2f2e22c0", "metadata": {}, "source": [ "# Apptemplates command\n", @@ -16,6 +17,7 @@ }, { "cell_type": "markdown", + "id": "f777a31b", "metadata": {}, "source": [ "## Setup PrimeHub Python SDK\n" @@ -24,6 +26,7 @@ { "cell_type": "code", "execution_count": null, + "id": "b02264cf", "metadata": {}, "outputs": [], "source": [ @@ -38,6 +41,7 @@ }, { "cell_type": "markdown", + "id": "d4a29fa1", "metadata": {}, "source": [ "## Help documentation" @@ -46,6 +50,7 @@ { "cell_type": "code", "execution_count": null, + "id": "136c920d", "metadata": {}, "outputs": [], "source": [ @@ -54,6 +59,7 @@ }, { "cell_type": "markdown", + "id": "cce0f7dd", "metadata": {}, "source": [ "## Examples" @@ -61,6 +67,7 @@ }, { "cell_type": "markdown", + "id": "d321a828", "metadata": {}, "source": [ "### List PhApp templates" @@ -69,6 +76,7 @@ { "cell_type": "code", "execution_count": null, + "id": "915be906", "metadata": {}, "outputs": [], "source": [ @@ -77,8 +85,20 @@ " print(f'id: {template[\"id\"]}\\ndescription: {template[\"description\"]}\\n')\n" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "b6b06402", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "pd.DataFrame(ph.apptemplates.list())" + ] + }, { "cell_type": "markdown", + "id": "2fb2e7aa", "metadata": {}, "source": [ "### Get a template by id" @@ -87,6 +107,7 @@ { "cell_type": "code", "execution_count": null, + "id": "2586930a", "metadata": {}, "outputs": [], "source": [ @@ -96,9 +117,9 @@ ], "metadata": { "kernelspec": { - "display_name": "PrimeHub SDK", + "display_name": "Python 3 (ipykernel)", "language": "python", - "name": "myenv" + "name": "python3" }, "language_info": { "codemirror_mode": { @@ -110,7 +131,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.6" + "version": "3.7.12" } }, "nbformat": 4, diff --git a/docs/notebook/images.ipynb b/docs/notebook/user-portal/09-images.ipynb similarity index 80% rename from docs/notebook/images.ipynb rename to docs/notebook/user-portal/09-images.ipynb index 453a3776..d7e84ede 100644 --- a/docs/notebook/images.ipynb +++ b/docs/notebook/user-portal/09-images.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "markdown", - "id": "71088394", + "id": "4e5ec511", "metadata": {}, "source": [ "# Images command\n", @@ -13,7 +13,7 @@ }, { "cell_type": "markdown", - "id": "40b1d75f", + "id": "c4d616d4", "metadata": {}, "source": [ "## Setup PrimeHub Python SDK\n" @@ -22,7 +22,7 @@ { "cell_type": "code", "execution_count": null, - "id": "d9e72f69", + "id": "ab45708f", "metadata": {}, "outputs": [], "source": [ @@ -37,7 +37,7 @@ }, { "cell_type": "markdown", - "id": "6b484dbc", + "id": "140cbcbb", "metadata": {}, "source": [ "## Help documentation" @@ -46,7 +46,7 @@ { "cell_type": "code", "execution_count": null, - "id": "c05ba53f", + "id": "79ff8f59", "metadata": {}, "outputs": [], "source": [ @@ -55,7 +55,7 @@ }, { "cell_type": "markdown", - "id": "fb755a49", + "id": "89eda888", "metadata": {}, "source": [ "## Examples" @@ -64,7 +64,7 @@ { "cell_type": "code", "execution_count": null, - "id": "a963cad4", + "id": "55346ee8", "metadata": {}, "outputs": [], "source": [ @@ -75,7 +75,18 @@ { "cell_type": "code", "execution_count": null, - "id": "ba7d2f80", + "id": "6e661f85", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "pd.DataFrame(ph.images.list())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1e85a889", "metadata": {}, "outputs": [], "source": [ @@ -86,7 +97,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -100,7 +111,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.10" + "version": "3.7.12" } }, "nbformat": 4, diff --git a/docs/notebook/user-portal/10-groups.ipynb b/docs/notebook/user-portal/10-groups.ipynb new file mode 100644 index 00000000..3f0f53b5 --- /dev/null +++ b/docs/notebook/user-portal/10-groups.ipynb @@ -0,0 +1,332 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "642b70c5", + "metadata": {}, + "source": [ + "# Groups command\n", + "\n", + "### Introduction\n", + "\n", + "Groups command can show the available groups for your account.\n" + ] + }, + { + "cell_type": "markdown", + "id": "1b2805e2", + "metadata": {}, + "source": [ + "## Setup PrimeHub Python SDK\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3d0faae9", + "metadata": {}, + "outputs": [], + "source": [ + "from primehub import PrimeHub, PrimeHubConfig\n", + "ph = PrimeHub(PrimeHubConfig())\n", + "\n", + "if ph.is_ready():\n", + " print(\"PrimeHub Python SDK setup successfully\")\n", + "else:\n", + " print(\"PrimeHub Python SDK couldn't get the group information, follow the 00-getting-started.ipynb to complete it\")" + ] + }, + { + "cell_type": "markdown", + "id": "66831901", + "metadata": {}, + "source": [ + "## Help documentation" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cca09429", + "metadata": {}, + "outputs": [], + "source": [ + "help(ph.groups)" + ] + }, + { + "cell_type": "markdown", + "id": "53b4e32f", + "metadata": {}, + "source": [ + "## Examples" + ] + }, + { + "cell_type": "markdown", + "id": "a86d1bcf", + "metadata": {}, + "source": [ + "### Group Information" + ] + }, + { + "cell_type": "markdown", + "id": "81ba2c23", + "metadata": {}, + "source": [ + "#### Get Group Information" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6e1721bf", + "metadata": {}, + "outputs": [], + "source": [ + "# Get a group\n", + "group_info = ph.groups.get(ph.me.group_name)\n", + "group_info" + ] + }, + { + "cell_type": "markdown", + "id": "7b427a51", + "metadata": {}, + "source": [ + "#### List Group Information" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "7de8f8fe", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "user_df = pd.DataFrame(ph.admin.users.list())\n", + "user_df.head()" + ] + }, + { + "cell_type": "markdown", + "id": "b61ce606", + "metadata": {}, + "source": [ + "### Group Member Setting" + ] + }, + { + "cell_type": "markdown", + "id": "8be8a90b", + "metadata": {}, + "source": [ + "#### Filter the specific user" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d220d0dc", + "metadata": {}, + "outputs": [], + "source": [ + "# Need to change the specific username.\n", + "USERNAME = \"\"" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "78af6ca4", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "user_df = pd.DataFrame(ph.admin.users.list())\n", + "user_df[user_df['username'] == USERNAME]" + ] + }, + { + "cell_type": "markdown", + "id": "741fcd83", + "metadata": {}, + "source": [ + "#### Get User id" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4686f979", + "metadata": {}, + "outputs": [], + "source": [ + "user_id = list(user_df[user_df['username']==USERNAME][\"id\"])[0]\n", + "user_id" + ] + }, + { + "cell_type": "markdown", + "id": "ffc782e3", + "metadata": {}, + "source": [ + "#### Add user into group" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8a1eb4a5", + "metadata": {}, + "outputs": [], + "source": [ + "ph.groups.add_user(group_info['id'], user_id)" + ] + }, + { + "cell_type": "markdown", + "id": "cb3d8527", + "metadata": {}, + "source": [ + "#### List the group member" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4bba57e6", + "metadata": {}, + "outputs": [], + "source": [ + "pd.DataFrame(ph.groups.list_users(group_info['id']))" + ] + }, + { + "cell_type": "markdown", + "id": "f0880791", + "metadata": {}, + "source": [ + "#### Remove the user from the group" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "228c667f", + "metadata": {}, + "outputs": [], + "source": [ + "ph.groups.remove_user(group_info['id'], user_id)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "62ac6c04", + "metadata": {}, + "outputs": [], + "source": [ + "pd.DataFrame(ph.groups.list_users(group_info['id']))" + ] + }, + { + "cell_type": "markdown", + "id": "df80d5d7", + "metadata": {}, + "source": [ + "### MLFlow Setting" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "140218a8", + "metadata": {}, + "outputs": [], + "source": [ + "mlflow_config = {\n", + " \"tracking_uri\": ,\n", + " \"ui_uri\": \n", + "}" + ] + }, + { + "cell_type": "markdown", + "id": "1a5285a3", + "metadata": {}, + "source": [ + "#### Set the mlflow configuration" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "47040891", + "metadata": {}, + "outputs": [], + "source": [ + "ph.groups.set_mlflow(group_info['id'], mlflow_config)" + ] + }, + { + "cell_type": "markdown", + "id": "66c5d876", + "metadata": {}, + "source": [ + "#### Get the mlflow configuration" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f49118e2", + "metadata": {}, + "outputs": [], + "source": [ + "ph.groups.get_mlflow(group_info['id'])" + ] + }, + { + "cell_type": "markdown", + "id": "65315150", + "metadata": {}, + "source": [ + "#### Unset the mlflow configuration" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "e1065639", + "metadata": {}, + "outputs": [], + "source": [ + "ph.groups.unset_mlflow(group_info['id'])" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.12" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +}