Cloud-init, Exception Handling
This commit is contained in:
18
list.py
18
list.py
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user