Ejemplo n.º 1
0
def create():

    region = askfor['region']()
    cidr = askfor['cidr']()
    azs = askfor['azs']()
    name = askfor['name']()
    env = askfor['env']()

    usr = Msg()
    for arg in [region, cidr, azs, name, env]:
        if arg == 'help': return usr.help

    creds = askfor['creds'](region)
    if creds != 'Pass': return usr.message(creds, 401)

    aws = Aws(region)
    subnets = aws.subnet_sizes(azs, cidr)
    if 'error' in subnets:
        return usr.message(subnets, 404)

    vpc, vpc_id = aws.create_vpc(cidr, region, name, env)
    if 'error' in vpc:
        return usr.message(vpc, 400)

    igw, igw_id = aws.create_igw(vpc_id, region, name, env)
    if 'error' in igw:
        if vpc_id != 'None': aws.delete_vpc(vpc_id)
        return usr.message(igw, 400)

    sub_ids = aws.create_subnet(vpc_id, azs, subnets, region, name, env)
    rtb_ids = aws.create_rtb(vpc_id, azs, sub_ids, igw_id, region, name, env)
    acl_ids = aws.create_acl(vpc_id, azs, sub_ids, cidr, region, name, env)

    return usr.message(vpc, 200)
Ejemplo n.º 2
0
def test_create_vpc():

    session = boto3.Session(region_name=region)
    ec2 = session.client('ec2')

    # Test...
    aws = Aws(region)
    aws.create_vpc(cidr, region, name, env)

    assert ec2.describe_vpcs(Filters=[{
        'Name': 'cidr',
        'Values': [cidr]
    }])['Vpcs'][0]['CidrBlock'] == cidr
Ejemplo n.º 3
0
def test_delete_subnet():

    session = boto3.Session(region_name=region)
    ec2 = session.client('ec2')

    vpc_id = ec2.create_vpc(CidrBlock=cidr)['Vpc']['VpcId']
    sub_id = ec2.create_subnet(VpcId=vpc_id,
                               CidrBlock=sub)['Subnet']['SubnetId']

    # Test...
    aws = Aws(region)
    aws.delete_subnet(vpc_id)

    assert ec2.describe_subnets(SubnetIds=[sub_id])['Subnets'] == []
Ejemplo n.º 4
0
def test_create_igw():

    session = boto3.Session(region_name=region)
    ec2 = session.client('ec2')

    vpc_id = ec2.create_vpc(CidrBlock=cidr)['Vpc']['VpcId']

    # Test...
    aws = Aws(region)
    aws.create_igw(vpc_id, region, name, env)

    assert ec2.describe_internet_gateways(Filters=[{
        'Name': 'attachment.vpc-id',
        'Values': [vpc_id]
    }])['InternetGateways'][0]['Attachments'][0]['VpcId'] == vpc_id
Ejemplo n.º 5
0
def test_delete_vpc():

    session = boto3.Session(region_name=region)
    ec2 = session.client('ec2')

    vpc_id = ec2.create_vpc(CidrBlock=cidr)['Vpc']['VpcId']

    # Test...
    aws = Aws(region)
    aws.delete_vpc(vpc_id)

    assert ec2.describe_vpcs(Filters=[{
        'Name': 'vpc-id',
        'Values': [vpc_id]
    }])['Vpcs'] == []
Ejemplo n.º 6
0
def cli(ctx, product, env, profile, region, format, kubeconfig):
    """
    This CLI can be used to manage products and environments conforming to a set of standards. The deployments should
    have set the following tags on their resources:

    Product: The name of the deployed product (eg. my-awesome-product)
    Environment: The discrete environment for the product (eg. dev, qa, stg, prod)

    To work with your products and environments, you will either need to set some environment variables or pass in some
    command line switches. The easiest way is to create a set of shell scripts that you can source in to set the
    appropriate environment variables for a product/environment. For example, you could have a shell script named
    foo-dev.sh containing the following:

    #!/bin/bash

    export PRODUCT=foo\n
    export ENV=dev\n
    export AWS_PROFILE=foo-dev-profile (this is the profile name from ~/.aws/credentials)\n
    export AWS_REGION=us-west-2\n
    export KUBECONFIG=/home/joesmith/Git/Phoenix/terraform/products/foo/kubeconfig_v2-dev\n

    Source this script in before working with this CLI, and all commands executed will take effect against the product /
    environment specified by the environment variables.

    If your product uses Kubernetes, make sure that KUBECONFIG is set to the location of your environment's kubeconfig
    file. This will allow you to run the show-dashboard command to open the Kubernetes dashboard for your product.
    """
    aws = Aws(region, profile, product, env, format)
    kube = Kubernetes(kubeconfig)
    ctx.obj['AWS'] = aws
    ctx.obj['FORMAT'] = format
    ctx.obj['KUBE'] = kube
Ejemplo n.º 7
0
def test_create_subnet():

    session = boto3.Session(region_name=region)
    ec2 = session.client('ec2')

    vpc_id = ec2.create_vpc(CidrBlock=cidr)['Vpc']['VpcId']

    # Test...
    aws = Aws(region)
    subnets = aws.subnet_sizes(azs, cidr)
    aws.create_subnet(vpc_id, azs, subnets, region, name, env)

    assert ec2.describe_subnets(Filters=[{
        'Name': 'cidrBlock',
        'Values': [sub]
    }])['Subnets'][0]['CidrBlock'] == sub
Ejemplo n.º 8
0
def check():

    region = askfor['region']()
    cidr = askfor['cidr']()

    usr = Msg()
    for arg in [region, cidr]:
        if arg == 'help': return usr.help

    creds = askfor['creds'](region)
    if creds != 'Pass': return usr.message(creds, 401)

    aws = Aws(region)
    vpc_id = None
    vpc = aws.get_vpc(cidr, vpc_id)
    if vpc:
        return usr.message(vpc, 200)

    return usr.message('VPC assigned ' + str(cidr) + ' does not exist.', 200)
Ejemplo n.º 9
0
def test_delete_igw():

    session = boto3.Session(region_name=region)
    ec2 = session.client('ec2')

    vpc_id = ec2.create_vpc(CidrBlock=cidr)['Vpc']['VpcId']
    igw_id = ec2.create_internet_gateway(
    )['InternetGateway']['InternetGatewayId']

    ec2.attach_internet_gateway(InternetGatewayId=igw_id, VpcId=vpc_id)

    # Test...
    aws = Aws(region)
    aws.delete_igw(vpc_id)

    assert ec2.describe_internet_gateways(Filters=[{
        'Name': 'attachment.vpc-id',
        'Values': [vpc_id]
    }])['InternetGateways'] == []
Ejemplo n.º 10
0
    def run_stalker(self, collection_name: str, target_name: str):
        if len(Collection().get_all_collections(
        )) == 0 or collection_name not in Collection().get_all_collections():
            Collection().create_new_collection(collection_name)
        else:
            if len(Collection().get_faces_from_collection(
                    collection_name)) < 3:
                list_faces_name = glob('wanted/*.jpeg')
                for victim in list_faces_name:
                    Collection().add_new_face(collection_name, victim)
            img_victim = str(Path('devils_eye') / target_name)
            faces_info = Aws().face_rekognition(collection_name, img_victim)
            student_name = ''.join([
                face_info['Face']['ExternalImageId']
                for face_info in faces_info
            ])

            return student_name[:student_name.find('.')]
Ejemplo n.º 11
0
def creds(region):
    creds = Auth().check_creds(Aws(region).session)
    return creds
Ejemplo n.º 12
0
def ping():
    aws = Aws('us-east-1')
    usr = Msg()
    return usr.message(aws.msg, 200)
Ejemplo n.º 13
0
def delete():

    region = askfor['region']()
    vpc_id = askfor['vpc_id']()

    usr = Msg()
    for arg in [region, vpc_id]:
        if arg == 'help': return usr.help

    creds = askfor['creds'](region)
    if creds != 'Pass': return usr.message(creds, 401)

    aws = Aws(region)
    cidr = None
    vpc = aws.get_vpc(cidr, vpc_id)
    if vpc:
        aws.delete_igw(vpc_id)
        aws.delete_subnet(vpc_id)
        aws.delete_rtb(vpc_id)
        aws.delete_acl(vpc_id)
        aws.delete_vpc(vpc_id)
    else:
        return usr.message(vpc_id + ' does not exist.', 200)

    return usr.message(vpc_id + ' removed.', 200)