Ejemplo n.º 1
0
    def post(self, request, *args, **kwargs):
        """
        docker-compose创建应用
        ---
        parameters:
            - name: tenantName
              description: 租户名
              required: true
              type: string
              paramType: path
            - name: group_name
              description: 应用组名称
              required: true
              type: string
              paramType: form
            - name: yaml_content
              description: compose文件内容
              required: true
              type: string
              paramType: form

        """

        group_name = request.data.get("group_name", None)
        yaml_content = request.data.get("yaml_content", "")
        try:
            if not group_name:
                return Response(general_message(400, 'params error', "请指明需要创建的compose组名"), status=400)
            if not yaml_content:
                return Response(general_message(400, "params error", "未指明yaml内容"), status=400)
            code, msg, json_data = compose_service.yaml_to_json(yaml_content)
            if code != 200:
                return Response(general_message(code, "parse yaml error", msg), status=code)
            # 创建组
            code, msg, group_info = group_service.add_group(self.tenant, self.response_region, group_name)
            if code != 200:
                return Response(general_message(code, "create group error", msg), status=code)
            code, msg, group_compose = compose_service.create_group_compose(self.tenant, self.response_region,
                                                                            group_info.ID, json_data)
            if code != 200:
                return Response(general_message(code, "create group compose error", msg), status=code)
            bean = dict()
            bean["group_id"] = group_compose.group_id
            bean["compose_id"] = group_compose.compose_id
            bean["group_name"] = group_info.group_name
            result = general_message(200, "operation success", "compose组创建成功", bean=bean)
        except Exception as e:
            logger.exception(e)
            result = error_message()
        return Response(result, status=result["code"])
    def post(self, request, *args, **kwargs):
        """
        docker-compose创建组件
        ---
        parameters:
            - name: tenantName
              description: 租户名
              required: true
              type: string
              paramType: path
            - name: group_name
              description: 应用名称
              required: true
              type: string
              paramType: form
            - name: user_name
              description: 镜像仓库名称
              required: true
              type: string
              paramType: form
            - name: password
              description: 镜像仓库密码
              required: true
              type: string
              paramType: form
            - name: yaml_content
              description: compose文件内容
              required: true
              type: string
              paramType: form

        """

        group_name = request.data.get("group_name", None)
        hub_user = request.data.get("user_name", "")
        hub_pass = request.data.get("password", "")
        yaml_content = request.data.get("yaml_content", "")
        group_note = request.data.get("group_note", "")
        if group_note and len(group_note) > 2048:
            return Response(general_message(400, "node too long",
                                            "应用备注长度限制2048"),
                            status=400)
        if not group_name:
            return Response(general_message(400, 'params error',
                                            "请指明需要创建的compose组名"),
                            status=400)
        if not yaml_content:
            return Response(general_message(400, "params error", "未指明yaml内容"),
                            status=400)
        # Parsing yaml determines whether the input is illegal
        code, msg, json_data = compose_service.yaml_to_json(yaml_content)
        if code != 200:
            return Response(general_message(code, "parse yaml error", msg),
                            status=code)
        # 创建组
        group_info = group_service.add_group(self.tenant, self.response_region,
                                             group_name, group_note)
        code, msg, group_compose = compose_service.create_group_compose(
            self.tenant, self.response_region, group_info.ID, yaml_content,
            hub_user, hub_pass)
        if code != 200:
            return Response(general_message(code, "create group compose error",
                                            msg),
                            status=code)
        bean = dict()
        bean["group_id"] = group_compose.group_id
        bean["compose_id"] = group_compose.compose_id
        bean["group_name"] = group_info.group_name
        result = general_message(200,
                                 "operation success",
                                 "compose组创建成功",
                                 bean=bean)
        return Response(result, status=result["code"])