1
0

Cloud-init, Exception Handling

This commit is contained in:
Philipp Klüter
2020-05-22 16:42:02 +02:00
parent c8248ef7bf
commit 6e194e0c52
5 changed files with 51 additions and 33 deletions

18
list.py
View File

@@ -1,5 +1,5 @@
#!/usr/bin/env python3
from hcloud import Client
from hcloud import Client, APIException
import argparse
# Get Servername
@@ -8,10 +8,14 @@ parser.add_argument("apiKey")
args = parser.parse_args()
apiKey = args.apiKey
# Please paste your API token here between the quotes
client = Client(token=apiKey)
servers = client.servers.get_all()
for server in servers:
print("Servername:", server.name)
print("Servername:", server.status)
try:
client = Client(token=apiKey)
servers = client.servers.get_all()
for server in servers:
print("Servername:", server.name)
print("Servername:", server.status)
except APIException as e:
print("API Error ", e)