hetzner-webservice/clean.py
2023-01-18 20:41:58 +01:00

37 lines
938 B
Python

import sys
from hcloud import Client
prefix = "444380"
ssh_key_name = prefix+"-webservice-ssh-key"
subnet_name = prefix+"-webservice-subnet"
server_name = prefix+"-webservice-server"
load_balancer_name = prefix+"-webservice-loadbalancer"
token = sys.argv[1]
server_count = 5
client = Client(
token=token
)
print("Removing servers...")
for i in range(server_count):
action = client.servers.delete(client.servers.get_by_name(f"{server_name}-{i+1}"))
action.wait_until_finished()
print("Servers removed")
print("Removing load balancer...")
action = client.load_balancers.delete(client.load_balancers.get_by_name(load_balancer_name))
print("Load balancer removed")
print("Removing subnet...")
action = client.networks.delete(client.networks.get_by_name(subnet_name))
print("Subnet removed")
print("Removing ssh-key...")
action = client.ssh_keys.delete(client.ssh_keys.get_by_name(ssh_key_name))
print("Ssh-key removed")