예제 #1
0
    def post(self, request, *args, **kwargs):
        """
        应用备份
        ---
        parameters:
            - name: tenantName
              description: 团队名称
              required: true
              type: string
              paramType: path
            - name: group_id
              description: 组ID
              required: true
              type: string
              paramType: path
            - name: note
              description: 备份说明
              required: true
              type: string
              paramType: form
            - name: mode
              description: 备份模式(full-online|full-offline)
              required: true
              type: string
              paramType: form
        """
        group_id = int(kwargs.get("group_id", None))
        if not group_id:
            return Response(general_message(400, "group id is null",
                                            "请选择需要备份的组"),
                            status=400)
        note = request.data.get("note", None)
        mode = request.data.get("mode", None)
        if not note:
            return Response(general_message(400, "note is null", "请填写备份信息"),
                            status=400)
        if not mode:
            return Response(general_message(400, "mode is null", "请选择备份模式"),
                            status=400)

        code, running_state_services = groupapp_backup_service.check_backup_condition(
            self.tenant, self.region_name, group_id)
        if running_state_services:
            msg_cn = "您有有状态服务未关闭,应用如下 {0}".format(
                ",".join(running_state_services))
            return Response(general_message(412, "state service is not closed",
                                            msg_cn),
                            status=412)
        code, msg, back_up_record = groupapp_backup_service.backup_group_apps(
            self.tenant, self.user, self.region_name, group_id, mode, note)
        if code != 200:
            return Response(general_message(code, "backup not success", msg),
                            status=code)

        bean = back_up_record.to_dict()
        bean.pop("backup_server_info")
        result = general_message(200, "success", "操作成功,正在备份中", bean=bean)
        return Response(result, status=result["code"])
예제 #2
0
    def post(self, request, *args, **kwargs):
        """
        应用备份
        ---
        parameters:
            - name: tenantName
              description: 团队名称
              required: true
              type: string
              paramType: path
            - name: group_id
              description: 组ID
              required: true
              type: string
              paramType: path
            - name: note
              description: 备份说明
              required: true
              type: string
              paramType: form
            - name: mode
              description: 备份模式(full-online|full-offline)
              required: true
              type: string
              paramType: form
        """
        group_id = int(kwargs.get("group_id", None))
        if not group_id:
            return Response(general_message(400, "group id is null", "请选择需要备份的组"), status=400)
        note = request.data.get("note", None)
        if not note:
            return Response(general_message(400, "note is null", "请填写备份信息"), status=400)
        mode = request.data.get("mode", None)
        if not mode:
            return Response(general_message(400, "mode is null", "请选择备份模式"), status=400)

        force = request.data.get("force", False)
        if not force:
            # state service can't backup while it is running
            code, running_state_services = groupapp_backup_service.check_backup_condition(
                self.tenant, self.region_name, group_id)
            if running_state_services:
                return Response(
                    general_message(
                        code=4121, msg="state service is running", msg_show="有状态组件未关闭", list=running_state_services),
                    status=412)
            # if service use custom service, can't backup
            use_custom_svc = groupapp_backup_service.check_backup_app_used_custom_volume(group_id)
            if use_custom_svc:
                return Response(
                    general_message(code=4122, msg="use custom volume", msg_show="组件使用了自定义存储", list=use_custom_svc), status=412)

        back_up_record = groupapp_backup_service.backup_group_apps(self.tenant, self.user, self.region_name, group_id, mode,
                                                                   note, force)

        bean = back_up_record.to_dict()
        result = general_message(200, "success", "操作成功,正在备份中", bean=bean)
        return Response(result, status=result["code"])