#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""Train: AWS CLI Tool"""

import argparse
import sys

import boto.vpc

from vpc.config import *
import vpc.instances as inst
import vpc.labs as labs
import vpc.util as util
import vpc.vpc as vpc


# configure parser
parser = argparse.ArgumentParser(description='Train: AWS CLI Tool')
parser.add_argument('-k',
                    help='Create AWS key pairs',
                    action='store_true', required=False)

parser.add_argument('-v',
                    help='Create AWS VPC',
                    action='store_true', required=False)

parser.add_argument('-a',
                    help='List all available labs',
                    action='store_true', required=False)

parser.add_argument('-i', metavar='<lab>',
                    help='View description for an available lab',
                    required=False)

parser.add_argument('-x', metavar='<lab>',
                    help='Excecute a lab',
                    required=False)

parser.add_argument('-l',
                    help='List running labs and instances in AWS',
                    action='store_true', required=False)

parser.add_argument('-d', metavar='<tag>',
                    help='Delete a lab from AWS',
                    required=False)

parser.add_argument('-p',
                    help='Purge/Delete all instances in vpc',
                    action='store_true', required=False)

parser.add_argument('-t', 
                    help='Terminate environment (VPC and local files)',
                    action='store_true', required=False)

args = parser.parse_args()


def process():
    """Execute command/flags"""

    if args.k:
        vpc.create_key_pairs()
    if args.v:
        print "Creating AWS VPC ..."
        vpc.create_vpc()
    if args.a:
        labs.list_available_labs()
    if args.i:
        labs.lab_description(args.i)

    # vpc and connection required for the following options...
    conn = boto.vpc.connect_to_region(AWS_REGION)
    user_vpc = vpc.get_vpc_id(conn, TRAINER + '-{0}'.format(TRAIN_TAG))
    if not user_vpc:
        print "\n'{0}' VPC doesn't exist.".format(TRAINER + '-{0}'.format(TRAIN_TAG))
        print "Create it by running the command: train -v\n"
        sys.exit(1)

    if args.x:
        labs.launch_lab(conn, user_vpc, args.x)
    if args.l:
        labs.lab_info(conn, user_vpc)
    if args.d:
        labs.terminate_lab(conn, user_vpc, args.d)
    if args.p:
        inst.terminate_all_instances(conn, user_vpc)
    if args.t:
        vpc.terminate_environment(conn, user_vpc)


if __name__ == '__main__':
    if len(sys.argv)==1:
        parser.print_help()
        sys.exit(1)

    process()

@@ -137,16 +137,42 @@
 mport *%0A
+import vpc.email as email%0A
 import v
@@ -216,16 +216,48 @@
 as labs%0A
+import vpc.register as register%0A
 import v
@@ -1040,32 +1040,346 @@
 equired=False)%0A%0A
+parser.add_argument('-r', metavar='%3Clab%3E',%0A                    help='Execute a lab in registration mode',%0A                    required=False)%0A%0Aparser.add_argument('-e',%0A                    help='Email all users their instance information and credentials',%0A                    action='store_true', required=False)%0A%0A
 parser.add_argum
@@ -2686,16 +2686,156 @@
 args.x)%0A
+    if args.r:%0A        register.registration(conn, user_vpc, args.r)%0A    if args.e:%0A        email.email_credentials(conn, user_vpc, args.e)%0A
     if a

Add train -r and -e flags