{ "cells": [ { "cell_type": "markdown", "id": "cddb91fd-4a0a-4128-952e-590db1ad5550", "metadata": {}, "source": [ "# DELETE: Cluster" ] }, { "cell_type": "code", "execution_count": null, "id": "1316811a-e614-4c1a-afda-3767e352252f", "metadata": {}, "outputs": [], "source": [ "# Cluster name to delete\n", "CLUSTER_NAME=\"cluster_create_delete_db\"" ] }, { "cell_type": "code", "execution_count": null, "id": "a3b86ed6-7e57-4f77-9871-772b861234b9", "metadata": {}, "outputs": [], "source": [ "import os\n", "import boto3\n", "import json\n", "import datetime\n", "\n", "from managed_kx import *\n", "from env_2 import *\n" ] }, { "cell_type": "code", "execution_count": null, "id": "19695e39-86c1-4952-8c70-0056f2bd512c", "metadata": {}, "outputs": [], "source": [ "# triggers credential get\n", "session=None\n", "\n", "try:\n", " subprocess.call([\"which\", \"ada\"])\n", " os.system(f\"ada credentials update --account={ACCOUNT_ID} --provider=isengard --role=Admin --once\")\n", "except: \n", " None\n", "\n", "if AWS_ACCESS_KEY_ID is None:\n", " print(\"Using Defaults ...\")\n", " # create AWS sessio: using access variables\n", " session = boto3.Session()\n", "else:\n", " print(\"Using variables ...\")\n", " session = boto3.Session(\n", " aws_access_key_id=AWS_ACCESS_KEY_ID,\n", " aws_secret_access_key=AWS_SECRET_ACCESS_KEY,\n", " aws_session_token=AWS_SESSION_TOKEN\n", " )\n", "\n", "# create finspace client\n", "client = session.client(service_name='finspace', endpoint_url=ENDPOINT_URL)" ] }, { "cell_type": "code", "execution_count": null, "id": "aafff390-4f42-453d-9792-742c661ddc00", "metadata": {}, "outputs": [], "source": [ "if CLUSTER_NAME is not None:\n", " try:\n", " resp = client.get_kx_cluster(environmentId=ENV_ID, clusterName=CLUSTER_NAME)\n", " resp.pop('ResponseMetadata', None)\n", " except client.exceptions.ResourceNotFoundException:\n", " resp = f\"Cluster: {CLUSTER_NAME} does not exist\"\n", "\n", " display(resp)" ] }, { "cell_type": "code", "execution_count": null, "id": "9c958567-6b34-42d6-a1be-47073e5b7e8b", "metadata": {}, "outputs": [], "source": [ "if CLUSTER_NAME is not None:\n", " try:\n", " resp = client.delete_kx_cluster(environmentId=ENV_ID, clusterName=CLUSTER_NAME)\n", " resp.pop('ResponseMetadata', None)\n", " except client.exceptions.ResourceNotFoundException:\n", " resp = f\"Cluster: {CLUSTER_NAME} does not exist\"\n", "\n", " display(resp)" ] }, { "cell_type": "code", "execution_count": null, "id": "0b9fb06f-3213-4746-bd8c-a620ac7d2e95", "metadata": {}, "outputs": [], "source": [ "wait_for_cluster_status(client, environmentId=ENV_ID, clusterName=CLUSTER_NAME, show_wait=True)\n", "print()\n", "print(\"** DONE **\")" ] }, { "cell_type": "code", "execution_count": null, "id": "1a5634e9-3184-4929-a57f-3ca826ced0c4", "metadata": {}, "outputs": [], "source": [ "print( f\"Last Run: {datetime.datetime.now()}\" )" ] }, { "cell_type": "code", "execution_count": null, "id": "92b75f80-c998-4ff0-90da-833960f5d1f5", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.12" } }, "nbformat": 4, "nbformat_minor": 5 }