def check_volume_path(self, service, volume_path, local_path=[]):
     for path in local_path:
         if volume_path.startswith(path + "/"):
             raise ServiceHandleException(msg="path error", msg_show="持久化路径不能再挂载共享路径下")
     volume = volume_repo.get_service_volume_by_path(service.service_id, volume_path)
     if volume:
         raise ServiceHandleException(
             msg="path already exists", msg_show="持久化路径[{0}]已存在".format(volume_path), status_code=412)
     if service.service_source == AppConstants.SOURCE_CODE:
         if volume_path == "/app":
             raise ServiceHandleException(msg="path error", msg_show="源码组件不能挂载/app目录", status_code=409)
     if not runner_util.is_runner(service.image):
         volume_path_win = False
         if re.match('[a-zA-Z]', volume_path[0]) and volume_path[1] == ':':
             volume_path_win = True
         if not volume_path.startswith("/") and not volume_path_win:
             raise ServiceHandleException(msg="path error", msg_show="路径仅支持linux和windows")
         if volume_path in self.SYSDIRS:
             raise ServiceHandleException(msg="path error", msg_show="路径{0}为系统路径".format(volume_path), status_code=412)
         if volume_path_win and len(volume_path) == 3:
             raise ServiceHandleException(msg="path error", msg_show="路径不能为系统路径", status_code=412)
     else:
         if not is_path_legal(volume_path):
             raise ServiceHandleException(msg="path error", msg_show="请输入符合规范的路径(如:/tmp/volumes)", status_code=412)
     all_volumes = volume_repo.get_service_volumes(service.service_id).values("volume_path")
     for path in list(all_volumes):
         # volume_path不能重复
         if path["volume_path"].startswith(volume_path + "/") or volume_path.startswith(path["volume_path"] + "/"):
             raise ServiceHandleException(
                 msg="path error", msg_show="已存在以{0}开头的路径".format(path["volume_path"]), status_code=412)
    def check_volume_path(self, service, volume_path):
        volume = volume_repo.get_service_volume_by_path(service.service_id, volume_path)
        if volume:
            return 412, u"持久化路径 {0} 已存在".format(volume_path)
        if service.service_source == AppConstants.SOURCE_CODE:
            if volume_path == "/app":
                return 409, u"源码应用不能挂载/app目录"
        if service.image != "goodrain.me/runner":
            if not volume_path.startswith("/"):
                return 400, u"路径需要以/(斜杠)开头"
            if volume_path in self.SYSDIRS:
                return 412, u"路径{0}为系统路径".format(volume_path)
        else:
            if not is_path_legal(volume_path):
                return 412, u"请输入符合规范的路径(如:/app/volumes )"
        all_volumes = volume_repo.get_service_volumes(service.service_id).values("volume_path")
        for path in list(all_volumes):
            # volume_path不能重复

            if path["volume_path"].startswith(volume_path + "/"):
                return 412, u"已存在以{0}开头的路径".format(path["volume_path"])
            if volume_path.startswith(path["volume_path"] + "/"):
                return 412, u"已存在以{0}开头的路径".format(volume_path)

        return 200, u"success"
    def check_volume_path(self, service, volume_path, local_path=[]):
        os_type = label_service.get_service_os_name(service)
        if os_type == "windows":
            return

        for path in local_path:
            if volume_path.startswith(path + "/"):
                raise ErrVolumePath(msg="path error",
                                    msg_show="持久化路径不能再挂载共享路径下")
        volume = volume_repo.get_service_volume_by_path(
            service.service_id, volume_path)
        if volume:
            raise ErrVolumePath(msg="path already exists",
                                msg_show="持久化路径[{0}]已存在".format(volume_path),
                                status_code=412)
        if service.service_source == AppConstants.SOURCE_CODE and service.language != ServiceLanguageConstants.DOCKER_FILE:
            if volume_path == "/app" or volume_path == "/tmp":
                raise ErrVolumePath(msg="path error",
                                    msg_show="源码组件不能挂载/app或/tmp目录",
                                    status_code=409)
            if not volume_path.startswith("/"):
                raise ErrVolumePath(msg_show="挂载路径需为标准的 Linux 路径")
            if volume_path in self.SYSDIRS:
                raise ErrVolumePath(msg_show="路径{0}为系统路径".format(volume_path))
        else:
            if not is_path_legal(volume_path):
                raise ErrVolumePath(msg_show="请输入符合规范的路径(如:/tmp/volumes)")
        all_volumes = volume_repo.get_service_volumes(
            service.service_id).values("volume_path")
        for path in list(all_volumes):
            # volume_path不能重复
            if path["volume_path"].startswith(volume_path +
                                              "/") or volume_path.startswith(
                                                  path["volume_path"] + "/"):
                raise ErrVolumePath(msg="path error",
                                    msg_show="已存在以{0}开头的路径".format(
                                        path["volume_path"]),
                                    status_code=412)
Esempio n. 4
0
    def check_volume_path(self, service, volume_path, local_path):
        if local_path:
            for path in local_path:
                # if volume_path.startswith(path):
                #     return 412, u"持久化路径不能和挂载共享路径相同"
                if volume_path.startswith(path + "/"):
                    return 412, u"持久化路径不能再挂载共享路径下"
        volume = volume_repo.get_service_volume_by_path(
            service.service_id, volume_path)
        if volume:
            return 412, u"持久化路径 {0} 已存在".format(volume_path)
        if service.service_source == AppConstants.SOURCE_CODE:
            if volume_path == "/app":
                return 409, u"源码应用不能挂载/app目录"
        if service.image != "goodrain.me/runner":
            volume_path_win = False
            if re.match('[a-zA-Z]', volume_path[0]) and volume_path[1] == ':':
                volume_path_win = True
            if not volume_path.startswith("/") and not volume_path_win:
                return 400, u"路径仅支持linux和windows"
            if volume_path in self.SYSDIRS:
                return 412, u"路径{0}为系统路径".format(volume_path)
            if volume_path_win and len(volume_path) == 3:
                return 412, u"路径不能为系统路径"
        else:
            if not is_path_legal(volume_path):
                return 412, u"请输入符合规范的路径(如:/app/volumes )"
        all_volumes = volume_repo.get_service_volumes(
            service.service_id).values("volume_path")
        for path in list(all_volumes):
            # volume_path不能重复

            if path["volume_path"].startswith(volume_path + "/"):
                return 412, u"已存在以{0}开头的路径".format(path["volume_path"])
            if volume_path.startswith(path["volume_path"] + "/"):
                return 412, u"已存在以{0}开头的路径".format(volume_path)

        return 200, u"success"