def api_templates_add(): status = "success" answ = {"data": {}} try: cloud_api_main.debug_log_print_ext( "attempting to add template from request:", request.data) reqdata = json.loads(request.data) templstring = reqdata.pop("template") name = reqdata.pop("name") dbid = cloud_api_main.add_nodetemplate_db(templstring, name, **reqdata) data = {"name": name, "id": dbid} answ["data"]["template"] = data except cloud_api_main.GeneralAPIError as e: status = "fail" answ["message"] = repr(e) answ["data"]["description"] = cloud_api_main.tdata.extended_error_log except Exception as e: status = "error" answ["message"] = repr(e) answ["data"]["description"] = cloud_api_main.tdata.extended_error_log answ["status"] = status return make_response(jsonify(answ))
def api_net_create_link(): status = "success" answ = {"data": {}} # debug_log_print(request.data) try: cloud_api_main.debug_log_print_ext("attmpting to load from json", request.data) reqdata = cloud_api_main.json.loads(request.data) netid = None if "node1" in reqdata and "node2" in reqdata: n1 = reqdata.pop("node1") n2 = reqdata.pop("node2") data = cloud_api_main.connect_nodes_nebula(n1, n2, **reqdata) answ["data"]["connection"] = data netid = data["id"] elif "mac1" in reqdata and "mac2" in reqdata: mac1 = reqdata.pop("mac1") mac2 = reqdata.pop("mac1") netid = cloud_api_main.create_link(mac1, mac2) else: pass answ["data"]["net"] = cloud_api_main.get_network_db_for_output() except (cloud_api_main.PrivilegeException, cloud_api_main.NoSuchObjectException) as e: status = "fail" answ["message"] = repr(e) answ["data"]["description"] = cloud_api_main.get_user_problem_msg() except cloud_api_main.GeneralAPIError as e: status = "fail" answ["message"] = repr(e) answ["data"]["description"] = cloud_api_main.get_user_problem_msg() except Exception as e: status = "error" answ["message"] = repr(e) answ["data"]["description"] = cloud_api_main.get_user_problem_msg() answ["status"] = status return make_response(jsonify(answ))
def api_templates_add(): status = "success" answ = {"data": {}} try: cloud_api_main.debug_log_print_ext("attempting to add template from request:", request.data) reqdata = json.loads(request.data) templstring = reqdata.pop("template") name = reqdata.pop("name") dbid = cloud_api_main.add_nodetemplate_db(templstring, name, **reqdata) data = {"name": name, "id": dbid} answ["data"]["template"] = data except cloud_api_main.GeneralAPIError as e: status = "fail" answ["message"] = repr(e) answ["data"]["description"] = cloud_api_main.tdata.extended_error_log except Exception as e: status = "error" answ["message"] = repr(e) answ["data"]["description"] = cloud_api_main.tdata.extended_error_log answ["status"] = status return make_response(jsonify(answ))