15 lines
500 B
Python
Executable File
15 lines
500 B
Python
Executable File
#!/usr/bin/env python3
|
|
"""List Hetzner servers via API."""
|
|
import urllib.request, json, os
|
|
|
|
token = os.environ.get("HETZNER_TOKEN", "")
|
|
req = urllib.request.Request(
|
|
"https://api.hetzner.cloud/v1/servers",
|
|
headers={"Authorization": f"Bearer {token}"}
|
|
)
|
|
data = json.loads(urllib.request.urlopen(req).read())
|
|
|
|
for s in data["servers"]:
|
|
t = s["server_type"]
|
|
print(f" {s['name']:20s} | ID: {s['id']:8d} | {t['name']:8s} | {t['cores']}vCPU {t['memory']}GB {t['disk']}GB | {s['status']}")
|