def get(self, request, *args, **kwargs): """ 总览 团队信息 --- parameters: - name: team_name description: 团队名 required: true type: string paramType: path """ try: overview_detail = dict() users = team_services.get_team_users(self.team) if users: user_nums = len(users) overview_detail["user_nums"] = user_nums team_service_num = service_repo.get_team_service_num_by_team_id(team_id=self.team.tenant_id, region_name=self.response_region) total_memory, total_disk = common_services.get_current_region_used_resource(self.team, self.response_region) overview_detail["team_service_num"] = team_service_num overview_detail["team_service_memory_count"] = total_memory overview_detail["team_service_total_disk"] = total_disk return Response(general_message(200, "success", "查询成功",bean=overview_detail )) else: data = {"user_nums": 1, "team_service_num": 0, "total_memory": 0} result = general_message(200, "success", "团队信息总览获取成功", bean=data) return Response(result, status=200) except Exception as e: logger.exception(e) result = error_message(e.message) return Response(result, status=500)
def get_tenant_resource(self, team, region_name): if team: data = { "team_id": team.tenant_id, "team_name": team.tenant_name, "team_alias": team.tenant_alias, } source = common_services.get_current_region_used_resource(team, region_name) if source: cpu_usage = 0 memory_usage = 0 if int(source["limit_cpu"]) != 0: cpu_usage = float(int(source["cpu"])) / float(int(source["limit_cpu"])) * 100 if int(source["limit_memory"]) != 0: memory_usage = float(int(source["memory"])) / float(int(source["limit_memory"])) * 100 data.update({ "used_cpu": int(source["cpu"]), "used_memory": int(source["memory"]), "total_cpu": int(source["limit_cpu"]), "total_memory": int(source["limit_memory"]), "used_cpu_percentage": round(cpu_usage, 2), "used_memory_percentage": round(memory_usage, 2), }) return data return None
def get(self, request, *args, **kwargs): """ 总览 团队信息 --- parameters: - name: team_name description: 团队名 required: true type: string paramType: path """ try: overview_detail = dict() users = team_services.get_team_users(self.team) if users: user_nums = len(users) overview_detail["user_nums"] = user_nums team_service_num = service_repo.get_team_service_num_by_team_id( team_id=self.team.tenant_id, region_name=self.response_region) source = common_services.get_current_region_used_resource( self.team, self.response_region) # 获取tcp和http策略数量 region = region_repo.get_region_by_region_name( self.response_region) total_tcp_domain = tcp_domain.get_all_domain_count_by_tenant_and_region( self.team.tenant_id, region.region_id) overview_detail["total_tcp_domain"] = total_tcp_domain total_http_domain = domain_repo.get_all_domain_count_by_tenant_and_region_id( self.team.tenant_id, region.region_id) overview_detail["total_http_domain"] = total_http_domain # 获取分享应用数量 groups = group_repo.get_tenant_region_groups( self.team.tenant_id, region.region_name) share_app_num = 0 if groups: for group in groups: share_record = share_repo.get_service_share_record_by_groupid( group_id=group.ID) if share_record: share_app_num += 1 overview_detail["share_app_num"] = share_app_num if source: team_app_num = group_repo.get_tenant_region_groups_count( self.team.tenant_id, self.response_region) overview_detail["team_app_num"] = team_app_num overview_detail["team_service_num"] = team_service_num overview_detail["team_service_memory_count"] = int( source["memory"]) overview_detail["team_service_total_disk"] = int( source["disk"]) overview_detail["team_service_total_cpu"] = int( source["limit_cpu"]) overview_detail["team_service_total_memory"] = int( source["limit_memory"]) overview_detail["team_service_use_cpu"] = int( source["cpu"]) cpu_usage = 0 memory_usage = 0 if int(source["limit_cpu"]) != 0: cpu_usage = float(int(source["cpu"])) / float( int(source["limit_cpu"])) * 100 if int(source["limit_memory"]) != 0: memory_usage = float(int(source["memory"])) / float( int(source["limit_memory"])) * 100 overview_detail["cpu_usage"] = round(cpu_usage, 2) overview_detail["memory_usage"] = round(memory_usage, 2) return Response( general_message(200, "success", "查询成功", bean=overview_detail)) else: data = { "user_nums": 1, "team_service_num": 0, "total_memory": 0 } result = general_message(200, "success", "团队信息总览获取成功", bean=data) return Response(result, status=200) except Exception as e: logger.exception(e) result = error_message(e.message) return Response(result, status=500)
def get(self, request, *args, **kwargs): """ 总览 团队信息 --- parameters: - name: team_name description: 团队名 required: true type: string paramType: path """ overview_detail = dict() users = team_services.get_team_users(self.team) if users: user_nums = len(users) overview_detail["user_nums"] = user_nums team_service_num = service_repo.get_team_service_num_by_team_id( team_id=self.team.tenant_id, region_name=self.response_region) source = common_services.get_current_region_used_resource(self.team, self.response_region) # 获取tcp和http策略数量 region = region_repo.get_region_by_region_name(self.response_region) if not region: overview_detail["region_health"] = False return Response(general_message(200, "success", "查询成功", bean=overview_detail)) total_tcp_domain = tcp_domain.get_all_domain_count_by_tenant_and_region(self.team.tenant_id, region.region_id) overview_detail["total_tcp_domain"] = total_tcp_domain total_http_domain = domain_repo.get_all_domain_count_by_tenant_and_region_id(self.team.tenant_id, region.region_id) overview_detail["total_http_domain"] = total_http_domain # 获取分享应用数量 groups = group_repo.get_tenant_region_groups(self.team.tenant_id, region.region_name) share_app_num = 0 batch_create_app_body = [] if groups: for group in groups: share_record = share_repo.get_service_share_record_by_groupid(group_id=group.ID) if share_record and share_record.step == 3: share_app_num += 1 try: region_app_repo.get_region_app_id(region.region_name, group.ID) except RegionApp.DoesNotExist: create_app_body = dict() group_services = base_service.get_group_services_list(self.team.tenant_id, region.region_name, group.ID) service_ids = [] if group_services: service_ids = [service["service_id"] for service in group_services] create_app_body["app_name"] = group.group_name create_app_body["console_app_id"] = group.ID create_app_body["service_ids"] = service_ids batch_create_app_body.append(create_app_body) if len(batch_create_app_body) > 0: try: body = {"apps_info": batch_create_app_body} applist = region_api.batch_create_application(region.region_name, self.tenant_name, body) app_list = [] if applist: for app in applist: data = RegionApp( app_id=app["app_id"], region_app_id=app["region_app_id"], region_name=region.region_name) app_list.append(data) RegionApp.objects.bulk_create(app_list) except Exception as e: logger.exception(e) team_app_num = group_repo.get_tenant_region_groups_count(self.team.tenant_id, self.response_region) overview_detail["share_app_num"] = share_app_num overview_detail["team_app_num"] = team_app_num overview_detail["team_service_num"] = team_service_num overview_detail["eid"] = self.team.enterprise_id overview_detail["team_service_memory_count"] = 0 overview_detail["team_service_total_disk"] = 0 overview_detail["team_service_total_cpu"] = 0 overview_detail["team_service_total_memory"] = 0 overview_detail["team_service_use_cpu"] = 0 overview_detail["cpu_usage"] = 0 overview_detail["memory_usage"] = 0 if source: try: overview_detail["region_health"] = True overview_detail["team_service_memory_count"] = int(source["memory"]) overview_detail["team_service_total_disk"] = int(source["disk"]) overview_detail["team_service_total_cpu"] = int(source["limit_cpu"]) overview_detail["team_service_total_memory"] = int(source["limit_memory"]) overview_detail["team_service_use_cpu"] = int(source["cpu"]) cpu_usage = 0 memory_usage = 0 if int(source["limit_cpu"]) != 0: cpu_usage = float(int(source["cpu"])) / float(int(source["limit_cpu"])) * 100 if int(source["limit_memory"]) != 0: memory_usage = float(int(source["memory"])) / float(int(source["limit_memory"])) * 100 overview_detail["cpu_usage"] = round(cpu_usage, 2) overview_detail["memory_usage"] = round(memory_usage, 2) except Exception as e: logger.debug(source) logger.exception(e) else: overview_detail["region_health"] = False return Response(general_message(200, "success", "查询成功", bean=overview_detail)) else: data = {"user_nums": 1, "team_service_num": 0, "total_memory": 0, "eid": self.team.enterprise_id} result = general_message(200, "success", "团队信息总览获取成功", bean=data) return Response(result, status=200)