Exemple #1
0
def process():
    """Execute command/flags"""

    if args.v:
        print "Creating AWS VPC ..."
        vpc.create_vpc()
    if args.k:
        vpc.create_key_pairs()
    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(VPC))
    if not user_vpc:
        print "\n'{0}' VPC doesn't exist.".format(TRAINER + '-{0}'.format(VPC))
        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.r:
        register.registration(conn, user_vpc, args.r)
    if args.e:
        ses.email_credentials()
    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)
Exemple #2
0
def process():
    """Execute command/flags"""

    if args.v:
        print "Creating AWS VPC ..."
        vpc.create_vpc()
    if args.k:
        vpc.create_key_pairs()
    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(VPC))
    if not user_vpc:
        print "\n'{0}' VPC doesn't exist.".format(TRAINER + '-{0}'.format(VPC))
        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.r:
        register.registration(conn, user_vpc, args.r)
    if args.e:
        email.email_credentials(conn)
    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)
Exemple #3
0
def provision_vpc(env, vpc):
    dryRun = True
    if env != "test":
        dryRun = False
    print "Availability zones: " + str(vpc.get_all_zones())
    existing_vpcs = [v for v in vpc.get_all_vpcs() if v.id == my_vpc['id']]
    existing_subnets = [s.id for s in vpc.get_all_subnets()]
    print "Info: Existing VPCs: " + str(vpc.get_all_vpcs())
    print "Info: Existing Subnets: " + str(existing_subnets)
    #print my_vpc['id']

    vpc_to_prov = existing_vpcs[0] if existing_vpcs else None
    if not vpc_to_prov:
        print "Starting new VPC provisioning process.."
        new_vpc = vpc.create_vpc(my_vpc['cidr_block'], dry_run=dryRun)
        print "New VPC provisioned, please update its ID: " + str(new_vpc.id)
        provision_subnets(env, vpc, new_vpc.id, existing_subnets)
    else:
        print "vpc already exists, nothing to do here, moving on to subnets.."
        provision_subnets(env, vpc, my_vpc['id'], existing_subnets)
def provision_vpc(env, vpc):
	dryRun = True
	if env != "test":
		dryRun = False
	print "Availability zones: " + str( vpc.get_all_zones() )
	existing_vpcs = [v for v in vpc.get_all_vpcs() if v.id == my_vpc['id'] ]
	existing_subnets = [s.id for s in vpc.get_all_subnets() ]
	print "Info: Existing VPCs: " + str(vpc.get_all_vpcs())
	print "Info: Existing Subnets: " + str(existing_subnets)
	#print my_vpc['id']

	vpc_to_prov = existing_vpcs[0] if existing_vpcs else None
	if not vpc_to_prov:
		print "Starting new VPC provisioning process.."
		new_vpc = vpc.create_vpc(my_vpc['cidr_block'], dry_run = dryRun)
		print "New VPC provisioned, please update its ID: " +str(new_vpc.id)
		provision_subnets(env, vpc, new_vpc.id, existing_subnets)
	else:
		print "vpc already exists, nothing to do here, moving on to subnets.."
		provision_subnets(env, vpc, my_vpc['id'], existing_subnets)
Exemple #5
0
            module.exit_json(changed=changed, vpc_id=vpc_id)
        elif changed:
            if update_dhcp:
                dhcp_opts = update_dhcp_opts(module, vpc, vpc_id, dhcp_id)
            if update_tags:
                e_tags = update_vpc_tags(module, vpc, vpc_id, tags, name)

            module.exit_json(changed=changed,
                             name=name,
                             dhcp_options_id=dhcp_opts,
                             tags=e_tags)

        if not already_exists:
            try:
                vpc_id = str(
                    vpc.create_vpc(cidr_block,
                                   instance_tenancy=tenancy)).split(':')[1]
                vpc.create_tags(vpc_id, dict(Name=name))
            except Exception, e:
                e_msg = boto_exception(e)
                module.fail_json(msg=e_msg)

            update_dhcp, update_tags = vpc_needs_update(
                module, vpc, vpc_id, dns_support, dns_hostnames, dhcp_id, tags)

            if update_dhcp:
                new_dhcp_opts = update_dhcp_opts(module, vpc, vpc_id, dhcp_id)
            if update_tags:
                new_tags = update_vpc_tags(module, vpc, vpc_id, tags, name)
                module.exit_json(changed=True,
                                 name=name,
                                 vpc_id=vpc_id,