hetzner/delete.py

39 lines
1.2 KiB
Python
Raw Permalink Normal View History

2024-11-23 19:53:34 +01:00
from hcloud import Client
client = Client(
token="V5gkzZ13coCVPKWkQbmbyGPyxDdsTjiubwVtx35jH7mix8A32JqM5CWJtqoLjtFK"
)
PREFIX = "464962"
lbs = client.load_balancers.get_all()
print(f"Usuwanie {len(lbs)} mechanizmów LB")
for s in lbs:
if s.data_model.name.startswith(PREFIX):
action = client.load_balancers.delete(s)
print(f"\tUsuwanie LB {s.data_model.name}: {action}")
2024-11-25 22:32:48 +01:00
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"\tUsuwanie serwera {s.data_model.name} ({s.data_model.public_net.ipv4.ip}): {action.data_model.status}")
2024-11-23 19:53:34 +01:00
vnets = client.networks.get_all()
print(f"Usuwanie {len(vnets)} sieci wirtualnych")
for s in vnets:
if s.data_model.name.startswith(PREFIX):
action = client.networks.delete(s)
print(f"\tUsuwanie sieci wirtualnej {s.name}: {action}")
2024-11-25 22:27:03 +01:00
2024-11-23 19:53:34 +01:00
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.delete(v)
print(f"\tUsuwanie wolumenu {v.name}: {action}")
2024-11-25 22:27:03 +01:00