ManagedkdbInsights/boto/delete_cluster.ipynb (152 lines of code) (raw):

{ "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": { "tags": [] }, "outputs": [], "source": [ "# Cluster name to delete\n", "CLUSTER_NAME=\"HDB_welcomedb\"" ] }, { "cell_type": "code", "execution_count": null, "id": "a3b86ed6-7e57-4f77-9871-772b861234b9", "metadata": { "tags": [] }, "outputs": [], "source": [ "import os\n", "import boto3\n", "import json\n", "import datetime\n", "\n", "from managed_kx import *\n", "from env import *" ] }, { "cell_type": "code", "execution_count": null, "id": "19695e39-86c1-4952-8c70-0056f2bd512c", "metadata": { "tags": [] }, "outputs": [], "source": [ "# Using credentials and create service client\n", "session = boto3.Session()\n", "\n", "# create finspace client\n", "client = session.client(service_name='finspace')" ] }, { "cell_type": "code", "execution_count": null, "id": "aafff390-4f42-453d-9792-742c661ddc00", "metadata": { "tags": [] }, "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": { "tags": [] }, "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": { "tags": [] }, "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": { "tags": [] }, "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": "conda_python3", "language": "python", "name": "conda_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.10.15" } }, "nbformat": 4, "nbformat_minor": 5 }