Cloud-init, Exception Handling
This commit is contained in:
17
details.py
17
details.py
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
from hcloud import Client
|
||||
from hcloud import Client, APIException
|
||||
import argparse
|
||||
|
||||
# Get Servername
|
||||
@@ -12,9 +12,12 @@ args = parser.parse_args()
|
||||
serverName = args.serverName
|
||||
apiKey = args.apiKey
|
||||
|
||||
# Please paste your API token here between the quotes
|
||||
client = Client(token=apiKey)
|
||||
server = client.servers.get_by_name(serverName)
|
||||
print("Name: ", server.name)
|
||||
print("Status: ", server.status)
|
||||
print("Type: ", server.server_type.name)
|
||||
try:
|
||||
client = Client(token=apiKey)
|
||||
server = client.servers.get_by_name(serverName)
|
||||
print("Name: ", server.name)
|
||||
print("Status: ", server.status)
|
||||
print("Type: ", server.server_type.name)
|
||||
|
||||
except APIException as e:
|
||||
print("API Error ", e)
|
||||
|
||||
Reference in New Issue
Block a user