#!/usr/bin/env python3 import sys from hcloud import Client if len(sys.argv) > 1: VERBOSE = True else: VERBOSE = False with open('.credentials/token', 'r') as file: client = Client(token=str(file.readline()).strip()) index = 's444501' ssh_name = index + '-ssh' network_name = index + '-network' server_base_name = index + '-server' load_balancer_name = index + '-lb' SERVER_COUNT = 5 print("Clearing SSH key... ", end='') if VERBOSE else None try: action = client.ssh_keys.delete(client.ssh_keys.get_by_name(ssh_name)) action.wait_until_finished() except AttributeError: pass print('\t\tdone.') if VERBOSE else None print("Clearing network... ", end='') if VERBOSE else None try: action = client.networks.delete(client.networks.get_by_name(network_name)) action.wait_until_finished() except AttributeError: pass print('\t\tdone.') if VERBOSE else None print("Clearing servers... ", end='') if VERBOSE else None for i in range(SERVER_COUNT): try: action = client.servers.delete(client.servers.get_by_name(server_base_name + '-' + str(i + 1))) action.wait_until_finished() except AttributeError: pass print('\tdone.') if VERBOSE else None print("Clearing load balancer... ", end='') if VERBOSE else None try: action = client.load_balancers.delete(client.load_balancers.get_by_name(load_balancer_name)) action.wait_until_finished() except AttributeError: pass print('\tdone.') if VERBOSE else None