def record_rollback_app(self, username, release_id, access_token): # operation record extra = json.dumps( dict( access_token=access_token, release_id=release_id, )) logger_client = client.UserActivityLogClient( project_id=self.project_id, user=username, resource_type="helm_app", activity_type="rollback", resource=self.name, resource_id=self.id, extra=extra, description= "Helm App[{app_name}:{app_id}] rollback, cluster[{cluster_id}], namespace[{namespace}]" .format( app_id=self.id, app_name=self.name, namespace=self.namespace, cluster_id=self.cluster_id, ), ) logger_client.log(activity_status="busy") return logger_client
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)
def record_initialize_app(self, access_token, project_id, cluster_id, namespace_id, namespace, chart_version, answers, customs, creator, updator, valuefile=None, name=None, unique_ns=0, sys_variables=None, valuefile_name=DEFAULT_VALUES_FILE_NAME, **kwargs): # operation record extra = json.dumps( dict( access_token=access_token, name=name, project_id=project_id, cluster_id=cluster_id, namespace_id=namespace_id, namespace=namespace, chart_version=chart_version.id, answers=answers, customs=customs, valuefile=valuefile, creator=creator, updator=updator, unique_ns=unique_ns, sys_variables=sys_variables, valuefile_name=valuefile_name, cmd_flags=kwargs.get("cmd_flags"), )) desc = "create Helm App, chart [{chart_name}:{template_id}], cluster[{cluster_id}], namespace[{namespace}]" desc = desc.format( template_id=chart_version.id, chart_name=chart_version.chart.name, namespace=namespace, cluster_id=cluster_id, ) logger_client = client.UserActivityLogClient( project_id=project_id, user=creator, activity_type="add", resource_type="helm_app", resource=chart_version.name, resource_id=chart_version.id, extra=extra, description=desc, ) logger_client.log(activity_status="busy") return logger_client
def record_upgrade_app( self, chart_version_id, answers, customs, updator, access_token, valuefile=None, sys_variables=None, valuefile_name=DEFAULT_VALUES_FILE_NAME, **kwargs, ): # operation record extra = json.dumps( dict( access_token=access_token, chart_version_id=chart_version_id, answers=answers, customs=customs, valuefile=valuefile, updator=updator, sys_variables=sys_variables, valuefile_name=valuefile_name, **kwargs, )) logger_client = client.UserActivityLogClient( project_id=self.project_id, user=updator, resource_type="helm_app", activity_type="modify", resource=self.name, resource_id=self.id, extra=extra, description= "Helm App[{app_name}:{app_id}] upgrade, cluster[{cluster_id}], namespace[{namespace}]" .format( app_id=self.id, app_name=self.name, namespace=self.namespace, cluster_id=self.cluster_id, ), ) logger_client.log(activity_status="busy") return logger_client