def post(self, request): req_dict = json.loads(request.read()) task_id = req_dict["task_id"] conf_name = req_dict["conf_name"] conf_json = req_dict["conf_data"] try: obj = TrainTask.objects.get(task_id=task_id) host = obj.host_id task_name = obj.task_name except Exception as e: import traceback logger.error(traceback.format_exc()) resp = JsonResponse({ "errno": RET.DBERR, "data": None, "message": "Failed" }) else: src_path = os.path.abspath( os.path.join(os.getcwd(), 'tmp', task_id)) op_conf(src_path=src_path, host=host, types=2, conf_name=conf_name, conf_json=conf_json, dest_path=TRAIN_CONF_PATH.format(task_name)) resp = JsonResponse({ "errno": RET.OK, "data": None, "message": "success" }) return resp
def get(self, request): task_id = request.GET.get('task_id') page = int(request.GET.get('page')) token = {"token": None} token["token"] = request.META.get('HTTP_TOKEN') user_name = get_username(token) try: obj = TrainTask.objects.get(task_id=task_id) task_type = obj.task_type version = obj.version host = obj.host_id except Exception as e: import traceback logger.error(traceback.format_exc()) resp = JsonResponse({ "errno": RET.DBERR, "data": None, "message": "Failed" }) else: data = get_global_conf(task_type, version, types="train", host=host, user_name=user_name.username) if page <= len(data["conf"]): conf_path = data["conf"][page - 1] conf_name = os.path.basename(conf_path) dest_path = os.path.abspath( os.path.join(os.getcwd(), 'tmp', task_id)) src_path = os.path.join(TMP_PATH, task_id) conf_data = op_conf(src_path=src_path, docker_type=task_type, docker_version=version, conf_path=conf_path, types=1, dest_path=dest_path) resp = JsonResponse({ "errno": RET.OK, "data": { "data": conf_data, "conf_name": conf_name }, "message": "success" }) else: resp = JsonResponse({ "errno": RET.IOERR, "data": None, "message": "Failed" }) return resp