Skip to content

Commit

Permalink
Merge pull request #155 from galaxyproject/154-cloudlaunch-list
Browse files Browse the repository at this point in the history
cloudlaunch list
  • Loading branch information
ksuderman authored Oct 18, 2022
2 parents 7df3006 + 5fcf29a commit a9399d9
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
1 change: 0 additions & 1 deletion abm/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ def bold(text: str):
help_args = ['help', '-h', '--help']
version_args = ['-v', '--version', 'version']

# TODO Parse this from the menu.yml file.
# Commands that do not depend on a cloud instance
stand_alone_commands = []

Expand Down
51 changes: 47 additions & 4 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 All @@ -29,17 +30,19 @@ def h1(text):
-r, --running list running deployments
-d, --deleted list deleted deployments
-l, --launch list deploymentes that are launching or have launched
-n, --limit limit output to N lines
-h, --help print this help message
{h1('NOTES')}
The above options are mutually exclusive.
The --archived, --running, and --deleted options are mutually exclusive.
'''

def list(context: Context, args: list):
archived = False
filter = None
status = lambda t: t.instance_status if t.instance_status else t.status
n = None
while len(args) > 0:
arg = args.pop(0)
if arg in ['-a', '--archived', 'archived']:
Expand All @@ -50,6 +53,8 @@ def list(context: Context, args: list):
filter = lambda d: 'DELETE' in d.latest_task.action
elif arg in ['-l', '--launch', 'launch']:
filter = lambda d: 'LAUNCH' in d.latest_task.action
elif arg in ['-n', '--limit', 'limit']:
n = int(args.pop(0))
elif arg in ['-h', '--help', 'help']:
print(list_help)
return
Expand All @@ -60,12 +65,16 @@ def list(context: Context, args: list):

if filter is not None:
deployments = [ d for d in deployments if filter(d) ]

if n is not None and len(deployments) > n:
deployments = deployments[:n]
_print_deployments(deployments)



def create(context: Context, args: list):
cloud = None
region = None
params = {
'application': 'cloudman-20',
'application_version': 'dev'
Expand All @@ -84,14 +93,26 @@ 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,
'us-east-1b': 36
},
'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 +123,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 +138,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 a9399d9

Please sign in to comment.