def register_token(event): # cred = read_cred_db(event.get("db_url"), event.get("user_id")) # user_name = validate_token(event.get("text"), cred.get("org_id")) data = { "vmc_command": "validate_token", "token": event.get("text"), "org_id": event.get("org_id") } try: user_name = call_lambda_sync( "slack_vmc", data ) message_handler(msg_const.SUCCESS_TOKEN, event) write_cred_db( event.get("db_url"), event.get("user_id"), { "status": cmd_const.REGISTERED, "token": event.get("text"), "user_name": user_name } ) except Exception as e: message_handler(msg_const.FAILED_TOKEN, event) event.update({"text": str(e)}) message_handler(msg_const.WRONG_TOKEN, event) delete_cred_db(event.get("db_url"), event.get("user_id"))
def aws_account(event): #update selected AWS account and send VPC list menu aws_account = event.get("response").split("+")[0] aws_id = event.get("response").split("+")[1] data = prepare_data_for_lambda(event, "list_vpc") data.update( { "linked_account_id": aws_id, "region": event.get("region") } ) event.update( { "vpc_list": call_lambda_sync( "slack_vmc", data ) } ) message_handler(msg_const.AWS_VPC, event) write_event_db( event.get("db_url"), event.get("user_id"), { "status": cmd_const.AWS_VPC, "aws_account": aws_account, "connected_account_id": aws_id } )
def aws_vpc(event): #update selected VPC and send list of AWS Subnet menu vpc_id = event.get("response") data = prepare_data_for_lambda(event, "list_subnet") data.update( { "linked_account_id": event.get("aws_id"), "region": event.get("region"), "connected_account_id": event.get("connected_account_id"), "vpc_id": vpc_id } ) event.update( { "subnet_list": call_lambda_sync( "slack_vmc", data ) } ) message_handler(msg_const.AWS_SUBNET, event) write_event_db( event.get("db_url"), event.get("user_id"), { "status": cmd_const.AWS_SUBNET, "vpc_id": vpc_id } )
def check_max_hosts(event): #response if proceed with this wizard or not and send select menu of AWS Region if "yes" in event.get("response"): data = prepare_data_for_lambda(event, "list_region") event.update( { "region_list": call_lambda_sync( "slack_vmc", data ) } # { # "region_list": [ # { # "text": "AP_NORTHEAST_1", #for internal use # "value": "AP_NORTHEAST_1" #for internal use # } # ] # } ) message_handler(msg_const.REGION, event) write_event_db( event.get("db_url"), event.get("user_id"), { "status": cmd_const.AWS_REGION } ) else: message_handler(msg_const.CANCEL_SDDC, event) delete_event_db(event.get("db_url"), event.get("user_id"))
def create_sddc(event): #first create sddc command from text message message_handler(msg_const.SDDC_WIZARD, event) message_handler(msg_const.CHECK_RESOURCE, event) data = prepare_data_for_lambda(event, "check_max_hosts") max_hosts = call_lambda_sync( "slack_vmc", data ) # max_hosts = 10 #for test max_hosts = 5 #for test event.update({"max_hosts": max_hosts}) if max_hosts < 1: message_handler(msg_const.NOT_ENOUGH, event) delete_event_db(event.get("db_url"), event.get("user_id")) else: message_handler(msg_const.MAX_HOSTS, event) write_event_db( event.get("db_url"), event.get("user_id"), { "command": cmd_const.COMMAND_SDDC[event.get("text")], "status": cmd_const.CHECK_MAX_HOSTS, "max_hosts": max_hosts, "provider": "AWS" } )
def read_cred_db(db_url, user_id): event = { "db_url": db_url, "user_id": user_id, "db_command": "read_cred_db" } return call_lambda_sync("slack_db", event)
def read_event_db(db_url, user_id, minuites=None): event = { "db_url": db_url, "user_id": user_id, "minuites": minuites, "db_command": "read_event_db" } return call_lambda_sync("slack_db", event)
def check_sddc_user(event): data = prepare_data_for_lambda(event, "get_sddc_user") data.update({"sddc_id": event.get("sddc_id")}) user = call_lambda_sync("slack_vmc", data) if user == event.get("user_name"): return True else: return False
def list_sddcs(event): data = prepare_data_for_lambda(event, "list_sddcs") try: event.update( { "sddcs": call_lambda_sync( "slack_vmc", data ) } ) message_handler(msg_const.SDDCS_TXT, event) message_handler(msg_const.SDDCS_MSG, event) except Exception as e: event.update({"text": str(e)}) message_handler(msg_const.ERROR, event)
def list_aws_account(event): data = prepare_data_for_lambda(event, "list_aws_account") event.update( { "aws_account_list": call_lambda_sync( "slack_vmc", data ) # "aws_account_list": [ # { # "text": event.get("aws_internal_account"), #for internal use # "value": "{}+{}".format( # event.get("aws_internal_account"), # event.get("aws_internal_id") # ) #for internal use # } # ] } ) message_handler(msg_const.AWS_ACCOUNT, event)
def check_config(event): if "yes" in event.get("response"): message_handler(msg_const.CREATE, event) event.update({"vmc_command": "create_sddc"}) try: task_id = call_lambda_sync("slack_vmc", event) except Exception as e: event.update( { "message": "Sorry, failed to create sddc. {}".format(str(e)), # "text": str(e), # "status": "task_failed" } ) message_handler(msg_const.SDDC_RESULT, event) delete_event_db(event.get("db_url"), event.get("user_id")) else: event.update( { "task_id": task_id, "status": "task_started", "lambda_name": "check_task" } ) write_event_db( event.get("db_url"), event.get("user_id"), { "status": "creating", } ) call_lambda_async("check_task", event) message_handler(msg_const.TASK_MSG, event) message_handler(msg_const.CRUD_SDDC, event) message_handler(msg_const.TASK_WH, event) else: message_handler(msg_const.CANCEL_SDDC, event) delete_event_db(event.get("db_url"), event.get("user_id"))
def delete_sddc(event): data = prepare_data_for_lambda(event, "list_sddcs_name_id") try: event.update( { "option_list": call_lambda_sync( "slack_vmc", data ) } ) except Exception as e: event.update({"text": str(e)}) message_handler(msg_const.ERROR, event) else: message_handler(msg_const.DELETE_SDDC, event) write_event_db( event.get("db_url"), event.get("user_id"), { "command": cmd_const.COMMAND_SDDC[event.get("text")], "status": cmd_const.DELETE_SDDC } )