dpzc-hetzner-gitea/clean.py

23 lines
661 B
Python
Raw Permalink Normal View History

2023-12-27 16:53:41 +01:00
import os
from hcloud import Client
client = Client(
token="qOpoQdAg5VxZVpNONWbLbJO3xgGqSvkjm4kQV9H1RlnDhL2rI2P8CbII3hl2nyYb"
)
PREFIX = "s452662"
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)
print(f"Usuwanie serwera {s.data_model.name} ({s.data_model.public_net.ipv4.ip}): {action.data_model.status}")
servers = client.load_balancers.get_all()
print(f"Usuwanie {len(servers)} load balancer")
for s in servers:
if s.data_model.name.startswith(PREFIX):
action = client.load_balancers.delete(s)