# ---
# jupyter:
#   jupytext:
#     formats: ipynb
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python [default]
#     language: python
#     name: python3
# ---

# # Tear it all down
# Once you are done with your task you can use the following commands to clean up resources.

from dotenv import set_key, get_key, find_dotenv
from utilities import get_auth

env_path = find_dotenv(raise_error_if_not_found=True)
resource_group = get_key(env_path, 'resource_group')
iot_hub_name = get_key(env_path, 'iot_hub_name')

# !sudo systemctl stop iotedge

# !sudo apt-get remove -y iotedge

# Delete the IoT hub. This step may take a few minutes.

# Delete IoT hub
# cmd_results = !az iot hub show -n $iot_hub_name -g $resource_group
if 'Not Found' not in cmd_results[0]:
    # !az iot hub delete --name $iot_hub_name --resource-group $resource_group

# Finally, you should delete the resource group. This also deletes the IoT hub and can be used instead of the above command if the resource group is only used for this purpose.

# cmd_results = !az group show -n $resource_group -o tsv
if "not be found" not in cmd_results[0]:
    # !az group delete --name $resource_group -y

# !docker stop $(docker ps -qa)
# !docker rm $(docker ps -qa)

StarcoderdataJupyterScriptsDedupFiltered