Cloud-init, Exception Handling
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
#!/usr/bin/env python3
|
||||
from hcloud import Client
|
||||
from hcloud import Client, APIException
|
||||
from hcloud.server_types.domain import ServerType
|
||||
import time
|
||||
import argparse
|
||||
|
||||
import sys
|
||||
|
||||
# Get Servername
|
||||
parser = argparse.ArgumentParser()
|
||||
@@ -18,10 +18,12 @@ serverType = args.serverType
|
||||
apiKey = args.apiKey
|
||||
|
||||
try:
|
||||
# Please paste your API token here between the quotes
|
||||
client = Client(token=apiKey)
|
||||
|
||||
server = client.servers.get_by_name(name=serverName)
|
||||
|
||||
if server.server_type.name == serverType:
|
||||
sys.exit('Server type is already: %s' % serverType)
|
||||
|
||||
if server.status != "off":
|
||||
print("Stopping: ", server.name)
|
||||
response = client.servers.power_off(server)
|
||||
|
||||
Reference in New Issue
Block a user