2017-07-19 20:48:23 +03:00
|
|
|
import argparse
|
|
|
|
import typing
|
|
|
|
from . import cluster_create
|
|
|
|
from . import cluster_add_user
|
|
|
|
from . import cluster_delete
|
|
|
|
from . import cluster_get
|
|
|
|
from . import cluster_list
|
|
|
|
from . import cluster_ssh
|
2017-09-19 18:29:23 +03:00
|
|
|
from . import cluster_app_logs
|
|
|
|
from . import cluster_submit
|
2017-07-19 20:48:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
class ClusterAction:
|
|
|
|
create = "create"
|
|
|
|
add_user = "add-user"
|
|
|
|
delete = "delete"
|
|
|
|
get = "get"
|
|
|
|
list = "list"
|
|
|
|
ssh = "ssh"
|
2017-09-19 18:29:23 +03:00
|
|
|
app_logs = "app-logs"
|
|
|
|
submit = "submit"
|
2017-07-19 20:48:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
def setup_parser(parser: argparse.ArgumentParser):
|
|
|
|
subparsers = parser.add_subparsers(
|
|
|
|
title="Actions", dest="cluster_action", metavar="<action>")
|
|
|
|
subparsers.required = True
|
|
|
|
|
|
|
|
create_parser = subparsers.add_parser(
|
|
|
|
ClusterAction.create, help="Create a new cluster")
|
|
|
|
add_user_parser = subparsers.add_parser(
|
|
|
|
ClusterAction.add_user, help="Add a user to the given cluster")
|
|
|
|
delete_parser = subparsers.add_parser(
|
|
|
|
ClusterAction.delete, help="Delete a cluster")
|
|
|
|
get_parser = subparsers.add_parser(
|
|
|
|
ClusterAction.get, help="Get information about a cluster")
|
|
|
|
list_parser = subparsers.add_parser(
|
|
|
|
ClusterAction.list, help="List clusters in your account")
|
2017-09-19 18:29:23 +03:00
|
|
|
app_logs_parser = subparsers.add_parser(
|
|
|
|
"app-logs", help="Get the logs from a submitted app")
|
2017-07-19 20:48:23 +03:00
|
|
|
ssh_parser = subparsers.add_parser(
|
|
|
|
ClusterAction.ssh, help="SSH into the master node of a cluster")
|
2017-09-19 18:29:23 +03:00
|
|
|
submit_parser = subparsers.add_parser(
|
|
|
|
"submit", help="Submit a new spark job to a cluster")
|
|
|
|
|
2017-07-19 20:48:23 +03:00
|
|
|
|
|
|
|
cluster_create.setup_parser(create_parser)
|
|
|
|
cluster_add_user.setup_parser(add_user_parser)
|
|
|
|
cluster_delete.setup_parser(delete_parser)
|
|
|
|
cluster_get.setup_parser(get_parser)
|
|
|
|
cluster_list.setup_parser(list_parser)
|
|
|
|
cluster_ssh.setup_parser(ssh_parser)
|
2017-09-19 18:29:23 +03:00
|
|
|
cluster_submit.setup_parser(submit_parser)
|
|
|
|
cluster_app_logs.setup_parser(app_logs_parser)
|
2017-07-19 20:48:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
def execute(args: typing.NamedTuple):
|
|
|
|
actions = {}
|
|
|
|
|
|
|
|
actions[ClusterAction.create] = cluster_create.execute
|
|
|
|
actions[ClusterAction.add_user] = cluster_add_user.execute
|
|
|
|
actions[ClusterAction.delete] = cluster_delete.execute
|
|
|
|
actions[ClusterAction.get] = cluster_get.execute
|
|
|
|
actions[ClusterAction.list] = cluster_list.execute
|
|
|
|
actions[ClusterAction.ssh] = cluster_ssh.execute
|
2017-09-19 18:29:23 +03:00
|
|
|
actions[ClusterAction.submit] = cluster_submit.execute
|
|
|
|
actions[ClusterAction.app_logs] = cluster_app_logs.execute
|
2017-07-19 20:48:23 +03:00
|
|
|
|
|
|
|
func = actions[args.cluster_action]
|
|
|
|
func(args)
|