Skip to content

Commit

Permalink
Add --region parameter for launch command
Browse files Browse the repository at this point in the history
  • Loading branch information
ksuderman committed Oct 14, 2022
1 parent 9ee2b6b commit 3df03c5
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions abm/lib/cloudlaunch.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import arrow
import requests
import configparser
import traceback

from common import Context
from cloudlaunch_cli.main import create_api_client
Expand Down Expand Up @@ -66,6 +67,7 @@ def list(context: Context, args: list):

def create(context: Context, args: list):
cloud = None
region = None
params = {
'application': 'cloudman-20',
'application_version': 'dev'
Expand All @@ -84,14 +86,25 @@ def create(context: Context, args: list):
'aws': 11,
'gcp': 16
}
regions = {
'aws': {
'us-east-1': 11,
'us-east-2': 12,
'us-west-1': 13,
'us-west-2': 14
},
'gcp': {
'us-central1': 16
}
}
while len(args) > 0:
arg = args.pop(0)
if arg in ['aws', 'gcp']:
if cloud is not None:
print(f"ERROR: the cloud provider has already been specified: {cloud}")
return
cloud = arg
params['deployment_target_id'] = targets[cloud]
#params['deployment_target_id'] = targets[cloud]
elif arg in ['-c', '--config']:
filepath = args.pop(0)
with open(filepath, 'r') as f:
Expand All @@ -102,6 +115,8 @@ def create(context: Context, args: list):
config['config_cloudlaunch']['keyPair'] = args.pop(0)
elif arg in ['-p', '--password']:
config['config_cloudman2']['clusterPassword'] = args.pop(0)
elif arg in ['-r', '--region']:
region = args.pop(0)
elif 'name' in params:
print(f"ERROR: the cluster name has already been specified: {params['name']}")
return
Expand All @@ -115,12 +130,32 @@ def create(context: Context, args: list):
if cloud is None:
print("ERROR: cloud provider not specied. Must be one of 'aws' or 'gcp'")
return
if region is not None:
if cloud not in regions:
print("ERROR: No regions have been defined for cloud provider {cloud")
return
if region not in regions[cloud]:
print(f"ERROR: Region {region} has not been defined for {cloud}")
return
params['deployment_target_id'] = regions[cloud][region]

# If the deployment target (region) has not been specified on the command
# line use the default for that provider.
if 'deployment_target_id' not in params:
params['deployment_target_id'] = targets[cloud]

if 'vmType' not in config['config_cloudlaunch']:
print("ERROR: please specify a VM type.")
return
print(f"Deployment target id {params['deployment_target_id']}")
cloudlaunch_client = create_api_client(cloud)
new_deployment = cloudlaunch_client.deployments.create(**params)
_print_deployments([new_deployment])
try:
new_deployment = cloudlaunch_client.deployments.create(**params)
_print_deployments([new_deployment])
except Exception as e:
print("Unable to launch the cluster")
#traceback.print_tb(e.__traceback__)
print(e)


def delete(context: Context, args: list):
Expand Down

0 comments on commit 3df03c5

Please sign in to comment.