forked from yugabyte/yugabyte-db
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[PLAT-1549] Add Python API client examples (for list & create provider)
Summary: This diff adds examples for create / list providers. A few minor changes were necessary to make these examples work: - Modify Platform API to not return null fields from API responses. - Modify devops code to handle null fields. - Modify sever API responses to not "require" potentially-null fields. Test Plan: - Itest (gcp, aws, k8s) - Unit tests - UI tests Reviewers: sb-yb Reviewed By: sb-yb Subscribers: yugaware, jenkins-bot Differential Revision: https://phabricator.dev.yugabyte.com/D12691
- Loading branch information
1 parent
ea03c55
commit 0e431dd
Showing
10 changed files
with
328 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
venv | ||
.ipynb_checkpoints |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"* Import packages.\n", | ||
"* Define platform API endpoint (modify for your environment).\n", | ||
"* Define platform API key (found on user page).\n", | ||
"* Create platform API client." | ||
], | ||
"metadata": {} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"source": [ | ||
"import os\n", | ||
"import yb_platform_client\n", | ||
"from yb_platform_client.api import provider_api, session_api\n", | ||
"from yb_platform_client.model.provider import Provider\n", | ||
"from yb_platform_client.model.region import Region\n", | ||
"from pprint import pprint\n", | ||
"\n", | ||
"platform_address = 'http://localhost:9000'\n", | ||
"platform_api_key = os.getenv('YB_API_KEY')\n", | ||
"\n", | ||
"api_client = yb_platform_client.ApiClient(yb_platform_client.Configuration(\n", | ||
" host = platform_address,\n", | ||
" api_key = {\n", | ||
" 'apiKeyAuth': platform_api_key,\n", | ||
" }\n", | ||
"))" | ||
], | ||
"outputs": [], | ||
"metadata": {} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"Make an API call to session endpoint to determine customer UUID." | ||
], | ||
"metadata": {} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"source": [ | ||
"session_api = session_api.SessionApi(api_client)\n", | ||
"\n", | ||
"try:\n", | ||
" session_info = session_api.get_session_info()\n", | ||
"except yb_platform_client.ApiException as e:\n", | ||
" print(\"Error get_session_info: %s\" % e)\n", | ||
" raise\n", | ||
"\n", | ||
"customer_uuid = session_info.get('customer_uuid')\n", | ||
"print('Customer UUID:\\n%s' % customer_uuid)" | ||
], | ||
"outputs": [], | ||
"metadata": {} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"Define new provider object." | ||
], | ||
"metadata": {} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"source": [ | ||
"new_provider = Provider(\n", | ||
" air_gap_install=False,\n", | ||
" code=\"gcp\",\n", | ||
" config={\n", | ||
" \"GCE_EMAIL\": \"<service acct email>\",\n", | ||
" \"GCE_HOST_PROJECT\": \"<gcp project>\",\n", | ||
" \"GCE_PROJECT\": \"<gcp project>\",\n", | ||
" \"YB_FIREWALL_TAGS\": \"<vpc tags>\",\n", | ||
" \"auth_provider_x509_cert_url\": \"https://www.googleapis.com/oauth2/v1/certs\",\n", | ||
" \"auth_uri\": \"https://accounts.google.com/o/oauth2/auth\",\n", | ||
" \"client_email\": \"<service account email>\",\n", | ||
" \"client_id\": \"<service account id>\",\n", | ||
" \"client_x509_cert_url\": \"<service account cert url>\",\n", | ||
" \"private_key\": \"<service account key>\",\n", | ||
" \"private_key_id\": \"<service account key id>\",\n", | ||
" \"project_id\": \"<gcp project>\",\n", | ||
" \"token_uri\": \"https://accounts.google.com/o/oauth2/token\",\n", | ||
" \"type\": \"service_account\",\n", | ||
" },\n", | ||
" dest_vpc_id=\"yugabyte-network\",\n", | ||
" name=\"api-test\",\n", | ||
" regions=[\n", | ||
" Region(\n", | ||
" code=\"us-central1\",\n", | ||
" name=\"us-central1\",\n", | ||
" zones=[],\n", | ||
" ),\n", | ||
" ],\n", | ||
" ssh_port=54422,\n", | ||
")" | ||
], | ||
"outputs": [], | ||
"metadata": {} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"Make API call to provider endpoint to create new provider." | ||
], | ||
"metadata": {} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"source": [ | ||
"provider_api = provider_api.ProviderApi(api_client)\n", | ||
"\n", | ||
"try:\n", | ||
" api_response = provider_api.create_providers(customer_uuid, new_provider)\n", | ||
"except yb_platform_client.ApiException as e:\n", | ||
" print('Error create_providers: %s' % e)\n", | ||
" raise\n", | ||
"\n", | ||
"pprint(api_response)" | ||
], | ||
"outputs": [], | ||
"metadata": {} | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"name": "python3", | ||
"display_name": "Python 3.8.10 64-bit ('venv')" | ||
}, | ||
"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.8.10" | ||
}, | ||
"interpreter": { | ||
"hash": "57f28aa4ce40fd00633621e172c0b6004aa3a4c49cc0dd486e1853a51500889f" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"* Import packages.\n", | ||
"* Define platform API endpoint (modify for your environment).\n", | ||
"* Define platform API key (found on user page).\n", | ||
"* Create platform API client." | ||
], | ||
"metadata": {} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"source": [ | ||
"import os\n", | ||
"import yb_platform_client\n", | ||
"from yb_platform_client.api import provider_api, session_api\n", | ||
"from yb_platform_client.model.provider import Provider\n", | ||
"from yb_platform_client.model.session_info import SessionInfo\n", | ||
"\n", | ||
"platform_address = 'http://localhost:9000'\n", | ||
"platform_api_key = os.getenv('YB_API_KEY')\n", | ||
"\n", | ||
"api_client = yb_platform_client.ApiClient(yb_platform_client.Configuration(\n", | ||
" host = platform_address,\n", | ||
" api_key = {\n", | ||
" 'apiKeyAuth': platform_api_key,\n", | ||
" }\n", | ||
"))" | ||
], | ||
"outputs": [], | ||
"metadata": {} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"Make an API call to session endpoint to determine customer UUID." | ||
], | ||
"metadata": {} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"source": [ | ||
"session_api = session_api.SessionApi(api_client)\n", | ||
"\n", | ||
"try:\n", | ||
" session_info = session_api.get_session_info()\n", | ||
"except yb_platform_client.ApiException as e:\n", | ||
" print(\"Error get_session_info: %s\" % e)\n", | ||
" raise\n", | ||
"\n", | ||
"customer_uuid = session_info.get('customer_uuid')\n", | ||
"print('Customer UUID:\\n%s' % customer_uuid)" | ||
], | ||
"outputs": [], | ||
"metadata": {} | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"source": [ | ||
"Make API call to provider endpoint to list providers." | ||
], | ||
"metadata": {} | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"source": [ | ||
"provider_api = provider_api.ProviderApi(api_client)\n", | ||
"\n", | ||
"try:\n", | ||
" provider_list = provider_api.get_list_of_providers(customer_uuid)\n", | ||
"except yb_platform_client.ApiException as e:\n", | ||
" print('Error get_list_of_providers: %s' % e)\n", | ||
" raise\n", | ||
"\n", | ||
"print('Providers:\\n%s' % provider_list)" | ||
], | ||
"outputs": [], | ||
"metadata": {} | ||
} | ||
], | ||
"metadata": { | ||
"interpreter": { | ||
"hash": "57f28aa4ce40fd00633621e172c0b6004aa3a4c49cc0dd486e1853a51500889f" | ||
}, | ||
"kernelspec": { | ||
"name": "python3", | ||
"display_name": "Python 3.8.10 64-bit ('venv')" | ||
}, | ||
"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.8.10" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/usr/bin/bash | ||
|
||
set -eo pipefail | ||
|
||
if [ ! -d venv ]; | ||
then | ||
python3 -m venv venv | ||
. venv/bin/activate | ||
pip3 install --upgrade pip | ||
# see: https://anbasile.github.io/posts/2017-06-25-jupyter-venv/ | ||
pip3 install ipykernel | ||
ipython kernel install --user --name=yugabyte-db-client | ||
pip3 install -e ~/code/yugabyte-db/managed/client/python/generated | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.