Cloud-init, Exception Handling
This commit is contained in:
14
create.py
14
create.py
@@ -1,6 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
from hcloud import Client
|
||||
from hcloud import APIException
|
||||
from hcloud import Client, APIException
|
||||
from hcloud.server_types.domain import ServerType
|
||||
from hcloud.images.domain import Image
|
||||
import argparse
|
||||
@@ -10,6 +9,8 @@ parser = argparse.ArgumentParser()
|
||||
parser.add_argument("serverName")
|
||||
parser.add_argument("serverType")
|
||||
parser.add_argument("serverImage")
|
||||
parser.add_argument('-ci', '--cloudInit', dest='ciFile', metavar='cloud-init filepath')
|
||||
|
||||
parser.add_argument("apiKey")
|
||||
|
||||
args = parser.parse_args()
|
||||
@@ -18,12 +19,15 @@ serverName = args.serverName
|
||||
serverType = args.serverType
|
||||
serverImage = args.serverImage
|
||||
apiKey = args.apiKey
|
||||
ciFile = args.ciFile
|
||||
|
||||
try:
|
||||
with open('/Users/Philipp/Documents/Server/cloud-init/default.yaml', 'r') as file:
|
||||
cloud_init = file.read()
|
||||
if ciFile:
|
||||
with open(ciFile, 'r') as file:
|
||||
cloud_init = file.read()
|
||||
else:
|
||||
cloud_init=''
|
||||
|
||||
# Please paste your API token here between the quotes
|
||||
client = Client(token=apiKey)
|
||||
response = client.servers.create(name=serverName, server_type=ServerType(
|
||||
name=serverType), image=Image(name=serverImage), user_data=cloud_init)
|
||||
|
||||
Reference in New Issue
Block a user