DPZC-Hetzner/clean.py

24 lines
779 B
Python
Raw Normal View History

2022-12-30 17:24:08 +01:00
from hcloud import Client
with open("token.txt", "r") as file:
api_token = file.read().strip()
client = Client(token=api_token)
PREFIX = "s478873"
servers = client.servers.get_all()
print(f"Usuwanie {len(servers)} serwerów")
for s in servers:
if s.data_model.name.startswith(PREFIX):
action = client.servers.delete(s)
2023-01-07 17:13:20 +01:00
print(f"Usuwanie serwera {s.data_model.name} ({s.data_model.public_net.ipv4.ip}): {action.data_model.status}")
volumes = client.volumes.get_all()
print(f"Usuwanie {len(volumes)} wolumenów")
for v in volumes:
if s.data_model.name.startswith(PREFIX):
action = client.volumes.detach(v)
action.wait_until_finished()
action = client.volumes.delete(v)
print(f"\tUsuwanie wolumenu {v.name}: {action}")