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)
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)
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)
def ping(): aws = Aws('us-east-1') usr = Msg() return usr.message(aws.msg, 200)
def help(): return Msg().help
def index(): return Msg().help
def root(): return Msg().help
def not_found(error=None): usr = Msg() resp = usr.message('Not Found: ' + request.url, 404) return resp