def provision_and_configure_elb(configuration, session):
    client = _get_client(session)
    project_name = configuration.get("project_name")
    elb_name = _get_elb_name(project_name)
    dns_name = None

    bcolors.message(
        "Creating Elastic Load Balancer({name})".format(name=elb_name))
    try:
        elb_response = _create_elb(configuration, elb_name, client)
        dns_name = elb_response.get('DNSName')
        bcolors.ok()
    except ClientError as e:
        if _is_duplicate_elb_exception(e):
            bcolors.exists()
            dns_name = _get_elb_dns_by_name(elb_name, client)
        else:
            bcolors.fail()

    bcolors.message(
        "Configuring Health Checks for ELB({name})".format(name=elb_name))
    try:
        _configure_health_check(elb_name, client)
        bcolors.ok()
    except ClientError as e:
        bcolors.fail()
        raise e

    return {"elb_name": elb_name, "elb_dns": dns_name}
Exemple #2
0
def provision_security_groups(configuration, session):
    client = _get_client(session)
    project_name = configuration.get("project_name")
    vpc_id = configuration.get("vpc_id")

    try:
        elb_sg_data = _create_elb_security_group(project_name, vpc_id, client)
        bcolors.message("Creating ELB Security Group")
        bcolors.ok()
    except RequestToAWSError:
        bcolors.message("Creating ELB Security Group")
        bcolors.fail()
        elb_sg_data = dict()

    try:
        app_sg_data = _create_application_security_group(
            project_name,
            vpc_id,
            client,
            source_sg=elb_sg_data["name"]
        )
        bcolors.message("Creating Application Security Group")
        bcolors.ok()
    except RequestToAWSError:
        bcolors.message("Creating Application Security Group")
        bcolors.fail()
        app_sg_data = dict()

    return {"ELB": elb_sg_data, "APP": app_sg_data}
Exemple #3
0
def _authorize_sg_ingress(security_group_name, client, in_permissions=None, source_sg=None):
    bcolors.message("Creating SG {sg_name} Ingress Rules".format(sg_name=security_group_name))
    try:
        if source_sg:
            client.authorize_security_group_ingress(
                GroupName=security_group_name,
                SourceSecurityGroupName=source_sg
            )
        else:
            client.authorize_security_group_ingress(
                GroupName=security_group_name,
                IpPermissions=in_permissions
            )
        bcolors.ok()
    except ClientError as e:
        if _is_sg_permissions_duplicate_exception(e):
            bcolors.exists()
        else:
            bcolors.fail()
def create_launch_conf_and_asg(configuration, session):
    client = _get_client(session)
    project_name = configuration.get("project_name")

    bcolors.message("Creating Launch configuration")
    launch_cfg_name = _get_launch_configuration_name(project_name)
    try:
        create_launch_configuration(launch_cfg_name, configuration, client)
        bcolors.ok()
    except RequestToAWSError:
        bcolors.fail()
        launch_cfg_name = None
    except LCfgAlreadyExists:
        bcolors.exists()

    bcolors.message("Creating Autoscaling Group")
    asg_name = _get_autoscaling_group_name(project_name)
    try:
        asg_name = create_autoscaling_group(asg_name, configuration,
                                            launch_cfg_name, client)
        bcolors.ok()
    except RequestToAWSError:
        bcolors.fail()
        asg_name = None
    except ASGAlreadyExists:
        bcolors.exists()

    bcolors.message("Creating the Scaling Policy")
    try:
        create_scaling_policy(configuration, asg_name, client)
        bcolors.ok()

    except RequestToAWSError:
        bcolors.fail()
        raise LaunchCfgCreationError
    except ClientError as e:
        print(e)
        raise e
Exemple #5
0
def _report_final_status(dns_name):
    bcolors.message("Application will shortly be available at")
    if dns_name:
        bcolors.green(dns_name)
    else:
        bcolors.fail()