2023-01-10 23:25:25 +01:00
|
|
|
import os
|
|
|
|
|
2023-01-10 17:38:17 +01:00
|
|
|
from hcloud import Client
|
|
|
|
|
2023-01-10 23:25:25 +01:00
|
|
|
from dotenv import load_dotenv
|
|
|
|
|
|
|
|
load_dotenv(dotenv_path=".env")
|
|
|
|
|
|
|
|
api_token = os.getenv("hetzner_api_token")
|
|
|
|
|
2023-01-10 17:38:17 +01:00
|
|
|
client = Client(
|
2023-01-10 23:25:25 +01:00
|
|
|
token=api_token
|
2023-01-10 17:38:17 +01:00
|
|
|
)
|
2023-01-10 23:25:25 +01:00
|
|
|
|
2023-01-10 17:38:17 +01:00
|
|
|
PREFIX = "s444417"
|
|
|
|
|
|
|
|
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}")
|
|
|
|
|
2023-01-10 23:25:25 +01:00
|
|
|
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)
|
|
|
|
|