Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
0
def ping():
    aws = Aws('us-east-1')
    usr = Msg()
    return usr.message(aws.msg, 200)
Exemplo n.º 5
0
def help():
    return Msg().help
Exemplo n.º 6
0
def index():
    return Msg().help
Exemplo n.º 7
0
def root():
    return Msg().help
Exemplo n.º 8
0
def not_found(error=None):

    usr = Msg()
    resp = usr.message('Not Found: ' + request.url, 404)

    return resp