Esempio n. 1
0
    def update(self, request, project_id):
        """更新项目信息"""
        if not self.can_edit(request, project_id):
            raise error_codes.CheckFailed(_("请确认有项目管理员权限,并且项目下无集群"))
        data = self.validate_update_project_data(request)
        access_token = request.user.token.access_token
        data["updator"] = request.user.username

        # 添加操作日志
        ual_client = client.UserActivityLogClient(
            project_id=project_id,
            user=request.user.username,
            resource_type="project",
            resource=request.project.project_name,
            resource_id=project_id,
            description="{}: {}".format(_("更新项目"), request.project.project_name),
        )
        resp = paas_cc.update_project_new(access_token, project_id, data)
        if resp.get("code") != ErrorCode.NoError:
            ual_client.log_modify(activity_status="failed")
            raise error_codes.APIError(_("更新项目信息失败,错误详情: {}").format(resp.get("message")))
        ual_client.log_modify(activity_status="succeed")
        project_data = resp.get("data")
        if project_data:
            project_data["created_at"], project_data["updated_at"] = self.normalize_create_update_time(
                project_data["created_at"], project_data["updated_at"]
            )

        # 主动令缓存失效
        self.invalid_project_cache(project_id)
        # 创建或更新依赖服务,包含data、template、helm
        update_bcs_service_for_project(request, project_id, data)

        return Response(project_data)
Esempio n. 2
0
    def update(self, request, project_id):
        """更新项目信息
        """
        if not self.can_edit(request, project_id):
            raise error_codes.CheckFailed("请确认有项目管理员权限,并且项目下无集群", replace=True)
        data = self.validate_update_project_data(request)
        access_token = request.user.token.access_token
        data['updator'] = request.user.username

        # 添加操作日志
        ual_client = client.UserActivityLogClient(
            project_id=project_id,
            user=request.user.username,
            resource_type='project',
            resource=request.project.project_name,
            resource_id=project_id,
            description="更新项目: %s" % request.project.project_name,
        )
        project = paas_cc.update_project_new(access_token, project_id, data)
        if project.get('code') != 0:
            ual_client.log_modify(activity_status='failed')
            raise error_codes.APIError(project.get('message', "更新项目成功"))
        ual_client.log_modify(activity_status='succeed')
        project_data = project.get('data')
        if project_data:
            project_data['created_at'], project_data['updated_at'] = self.normalize_create_update_time(
                project_data['created_at'], project_data['updated_at'])

        # 主动令缓存失效
        self.invalid_project_cache(project_id)
        # 创建或更新依赖服务,包含data、template、helm
        update_bcs_service_for_project(request, project_id, data)

        return Response(project_data)
Esempio n. 3
0
    def update(self, request, project_id):
        """更新项目信息
        """
        if not self.can_edit(request, project_id):
            raise error_codes.CheckFailed("请确认有项目管理员权限,并且项目下无集群", replace=True)
        data = self.validate_update_project_data(request)
        access_token = request.user.token.access_token
        data['updator'] = request.user.username
        # 编辑之前项目绑定的业务和调度类型,用户后面判断是否进行相应的操作
        pre_cc_app_id = request.project.cc_app_id
        pre_kind = request.project.kind

        # 添加操作日志
        ual_client = client.UserActivityLogClient(
            project_id=project_id,
            user=request.user.username,
            resource_type='project',
            resource=request.project.project_name,
            resource_id=project_id,
            description="更新项目: %s" % request.project.project_name,
        )
        project = paas_cc.update_project_new(access_token, project_id, data)
        if project.get('code') != 0:
            ual_client.log_modify(activity_status='failed')
            raise error_codes.APIError(project.get('message', "更新项目成功"))
        ual_client.log_modify(activity_status='succeed')
        project_data = project.get('data')
        if project_data:
            project_data['created_at'], project_data[
                'updated_at'] = self.normalize_create_update_time(
                    project_data['created_at'], project_data['updated_at'])

        # 主动令缓存失效
        self.invalid_project_cache(project_id)
        # 触发后台任务
        self.backend_tasks(request, project_id, data, pre_cc_app_id, pre_kind)

        return Response(project_data)
Esempio n. 4
0
def update_project(access_token, project_id, data):
    return paas_cc.update_project_new(access_token, project_id, data)