A distributed command execution framework.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

77 lines
2.3 KiB

#!/usr/bin/env python
"""
Employ instance to do your bidding
Usage:
employ help (commands | command <command> | regions)
employ run <command> [options] [<command_options> ...]
Global Options:
-h --help Show this message
--version Show the version number
Run Options:
-i NUM, --instances NUM Number of instances to start [default: 1]
-r REGION, --region REGION Which region to start the instances up on [default: us-east-1]
-n NAME, --name NAME Which name to assign to each new instance [default: employed]
Help Commands:
commands List all available commands
command <command> Print the docstring for the provided command
regions List all available regions names
"""
import sys
from docopt import docopt
import employ
import employ.manager
def command_doc(command):
all_commands = employ.manager.Manager.available_commands()
if all_commands.get(command):
print all_commands[command].__doc__
else:
sys.exit("Unknown command: '%s'" % command)
def list_commands(command=None):
all_commands = employ.manager.Manager.available_commands()
print "List of Available Commands:"
for cls in all_commands:
print " %s" % cls
def list_regions():
print "List of Available Regions:"
for region in sorted(employ.manager.Manager.available_regions()):
print " %s" % region
def run(arguments):
all_commands = employ.manager.Manager.available_commands()
if arguments["<command>"] not in all_commands:
sys.exit("Unknown command '%s'" % command)
command_cls = all_commands[arguments["<command>"]]
command = command_cls(*arguments["<command_options>"])
manager = employ.manager.Manager(
num_instances=arguments["--instances"],
name=arguments["--name"],
region=arguments["--region"],
)
with manager:
manager.run(command)
arguments = docopt(__doc__, help=True, version="employ %s" % employ.__version__)
if arguments["help"]:
if arguments["commands"]:
list_commands()
elif arguments["command"] and arguments["<command>"]:
command_doc(arguments["<command>"])
elif arguments["regions"]:
list_regions()
elif arguments["run"]:
run(arguments)