30 lines
714 B
Python
30 lines
714 B
Python
import os
|
|
|
|
from hcloud import Client
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv(dotenv_path=".env")
|
|
|
|
api_token = os.getenv("hetzner_api_token")
|
|
|
|
client = Client(
|
|
token=api_token
|
|
)
|
|
|
|
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}")
|
|
|
|
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)
|
|
|