Added ssh_key option
This commit is contained in:
20
create.py
20
create.py
@@ -10,6 +10,7 @@ parser.add_argument("serverName")
|
|||||||
parser.add_argument("serverType")
|
parser.add_argument("serverType")
|
||||||
parser.add_argument("serverImage")
|
parser.add_argument("serverImage")
|
||||||
parser.add_argument('-ci', '--cloudInit', dest='ciFile', metavar='cloud-init filepath')
|
parser.add_argument('-ci', '--cloudInit', dest='ciFile', metavar='cloud-init filepath')
|
||||||
|
parser.add_argument('-s', '--sshKeys', dest='sshKeys', metavar='ssh keys (comma separated)')
|
||||||
|
|
||||||
parser.add_argument("apiKey")
|
parser.add_argument("apiKey")
|
||||||
|
|
||||||
@@ -20,20 +21,31 @@ serverType = args.serverType
|
|||||||
serverImage = args.serverImage
|
serverImage = args.serverImage
|
||||||
apiKey = args.apiKey
|
apiKey = args.apiKey
|
||||||
ciFile = args.ciFile
|
ciFile = args.ciFile
|
||||||
|
sshKeys = args.sshKeys
|
||||||
|
ssh_keys = [];
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
client = Client(token=apiKey)
|
||||||
|
|
||||||
if ciFile:
|
if ciFile:
|
||||||
with open(ciFile, 'r') as file:
|
with open(ciFile, 'r') as file:
|
||||||
cloud_init = file.read()
|
cloud_init = file.read()
|
||||||
else:
|
else:
|
||||||
cloud_init=''
|
cloud_init=''
|
||||||
|
|
||||||
client = Client(token=apiKey)
|
if sshKeys:
|
||||||
|
for sshKey in sshKeys.split(','):
|
||||||
|
ssh_keys.append(client.ssh_keys.get_by_name(sshKey))
|
||||||
|
else:
|
||||||
|
ssh_keys=''
|
||||||
|
|
||||||
response = client.servers.create(name=serverName, server_type=ServerType(
|
response = client.servers.create(name=serverName, server_type=ServerType(
|
||||||
name=serverType), image=Image(name=serverImage), user_data=cloud_init)
|
name=serverType), image=Image(name=serverImage), user_data=cloud_init, ssh_keys=ssh_keys)
|
||||||
server = response.server
|
server = response.server
|
||||||
print(server)
|
|
||||||
print("Root Password: " + response.root_password)
|
if response.root_password:
|
||||||
|
print("Root Password: " + response.root_password)
|
||||||
print("IP: " + response.server.public_net.ipv4.ip)
|
print("IP: " + response.server.public_net.ipv4.ip)
|
||||||
|
|
||||||
except APIException as e:
|
except APIException as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user