Esempio n. 1
0
    def put(self, request, *args, **kwargs):
        """
        更新某个版本插件的信息
        ---
        parameters:
            - name: tenantName
              description: 租户名
              required: true
              type: string
              paramType: path
            - name: plugin_id
              description: 插件ID
              required: true
              type: string
              paramType: path
            - name: build_version
              description: 插件版本
              required: true
              type: string
              paramType: path
            - name: plugin_alias
              description: 插件名称
              required: false
              type: string
              paramType: form
            - name: update_info
              description: 更新信息
              required: false
              type: string
              paramType: form
            - name: build_cmd
              description: 构建命令
              required: false
              type: string
              paramType: form
            - name: image_tag
              description: 镜像版本
              required: false
              type: string
              paramType: form
            - name: code_version
              description: 代码版本
              required: false
              type: string
              paramType: form
            - name: min_memory
              description: 最小内存
              required: false
              type: string
              paramType: form

        """
        try:
            plugin_alias = request.data.get("plugin_alias",
                                            self.plugin.plugin_alias)
            update_info = request.data.get("update_info",
                                           self.plugin_version.update_info)
            build_cmd = request.data.get("build_cmd",
                                         self.plugin_version.build_cmd)
            image_tag = request.data.get("image_tag",
                                         self.plugin_version.image_tag)
            code_version = request.data.get("code_version",
                                            self.plugin_version.code_version)
            min_memory = request.data.get("min_memory",
                                          self.plugin_version.min_memory)
            min_cpu = plugin_version_service.calculate_cpu(
                self.response_region, min_memory)

            self.plugin.plugin_alias = plugin_alias

            self.plugin_version.update_info = update_info
            self.plugin_version.build_cmd = build_cmd
            self.plugin_version.image_tag = image_tag
            self.plugin_version.code_version = code_version
            self.plugin_version.min_memory = min_memory
            self.plugin_version.min_cpu = min_cpu

            plugin_service.update_region_plugin_info(self.response_region,
                                                     self.team, self.plugin,
                                                     self.plugin_version)
            # 保存基本信息
            self.plugin.save()
            # 保存版本信息
            self.plugin_version.save()
            result = general_message(200, "success", "操作成功")
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result, status=result["code"])
Esempio n. 2
0
    def put(self, request, *args, **kwargs):
        """
        更新某个版本插件的信息
        ---
        parameters:
            - name: tenantName
              description: 租户名
              required: true
              type: string
              paramType: path
            - name: plugin_id
              description: 插件ID
              required: true
              type: string
              paramType: path
            - name: build_version
              description: 插件版本
              required: true
              type: string
              paramType: path
            - name: plugin_alias
              description: 插件名称
              required: false
              type: string
              paramType: form
            - name: update_info
              description: 更新信息
              required: false
              type: string
              paramType: form
            - name: build_cmd
              description: 构建命令
              required: false
              type: string
              paramType: form
            - name: image_tag
              description: 镜像版本
              required: false
              type: string
              paramType: form
            - name: code_version
              description: 代码版本
              required: false
              type: string
              paramType: form
            - name: min_memory
              description: 最小内存
              required: false
              type: string
              paramType: form

        """
        try:
            plugin_alias = request.data.get("plugin_alias",
                                            self.plugin.plugin_alias)
            update_info = request.data.get("update_info",
                                           self.plugin_version.update_info)
            build_cmd = request.data.get("build_cmd",
                                         self.plugin_version.build_cmd)
            image = request.data.get("image", self.plugin.image)
            code_repo = request.data.get("code_repo", self.plugin.code_repo)
            code_version = request.data.get("code_version",
                                            self.plugin_version.code_version)
            min_memory = request.data.get("min_memory",
                                          self.plugin_version.min_memory)
            min_cpu = plugin_version_service.calculate_cpu(
                self.response_region, min_memory)
            # if get username and password is "", means user remove the username and password
            username = request.data.get("username", "")
            password = request.data.get("password", "")
            image_tag = ""  # if build_source is dockerfile, image_tag should be empty
            if image and self.plugin.build_source == "image":
                ref = reference.Reference.parse(image)
                image = ref["name"]
                image_tag = ref["tag"]

            self.plugin.image = image
            self.plugin.code_repo = code_repo
            self.plugin.username = username
            self.plugin.password = password
            self.plugin.plugin_alias = plugin_alias
            self.plugin.desc = update_info
            self.plugin_version.update_info = update_info
            self.plugin_version.build_cmd = build_cmd
            self.plugin_version.image_tag = image_tag
            self.plugin_version.code_version = code_version
            self.plugin_version.min_memory = min_memory
            self.plugin_version.min_cpu = min_cpu

            plugin_service.update_region_plugin_info(self.response_region,
                                                     self.team, self.plugin,
                                                     self.plugin_version)
            # 保存基本信息
            self.plugin.save()
            # 保存版本信息
            self.plugin_version.save()
            result = general_message(200, "success", "操作成功")
        except Exception as e:
            logger.exception(e)
            result = error_message(e.message)
        return Response(result, status=result["code"])