agent: |
Gv2xwubuO5QRvwcFHeLrDelete AKS Clusters
Delete AKS Clusters
There was a problem that the LLM was not able to address. Please rephrase your prompt and try again.
This task involves terminating specific Azure Kubernetes Service (AKS) clusters. By doing so, users can streamline their infrastructure, reduce costs, and ensure only relevant clusters remain active within their Azure setup.
inputs
outputs
import azure.identity
from azure.mgmt.containerservice import ContainerServiceClient
from azure.core.exceptions import HttpResponseError, ResourceNotFoundError
# Set this to True if you want to actually delete the clusters
#ACTUALLY_DELETE = True
if subscription_id:
try:
# Initialize Azure credentials
credential = azure.identity.DefaultAzureCredential()
# Setup Azure AKS client
aks_client = ContainerServiceClient(credential, subscription_id)
# Displaying clusters that will be deleted
print(f"Clusters queued for deletion:")
for cluster in clusters_to_delete:
print(f" - Name: {cluster.name}, Location: {cluster.location}")
if ACTUALLY_DELETE:
for cluster in clusters_to_delete:
try:
aks_client.managed_clusters.begin_delete(cluster.resource_group, cluster.name)
print(f"Initiated deletion for cluster: {cluster.name}")
except ResourceNotFoundError:
print(f"Cluster {cluster.name} not found. Skipping deletion.")
except HttpResponseError as hr_err:
print(f"Failed to delete cluster {cluster.name} due to Azure SDK error: {hr_err.message}")
except Exception as e:
print(f"Failed to delete cluster {cluster.name}: {e}")
else:
print("ACTUALLY_DELETE is set to False. Clusters will not be deleted.")
except azure.core.exceptions.AzureError as ae:
print(f"Azure SDK Error: {ae.message}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
else:
print("Failed to obtain subscription ID. Cannot proceed with deletion.")
copied