feat: ops 支持节点和资产

This commit is contained in:
Aaron3S
2022-12-26 19:02:05 +08:00
parent dd630f0e14
commit 9ba792cf1c
5 changed files with 44 additions and 5 deletions

View File

@@ -1,3 +1,4 @@
from django.db.models import Count
from rest_framework.views import APIView
from django.shortcuts import get_object_or_404
from rest_framework.response import Response
@@ -5,12 +6,14 @@ from rest_framework.response import Response
from ops.models import Job, JobExecution
from ops.serializers.job import JobSerializer, JobExecutionSerializer
__all__ = ['JobViewSet', 'JobExecutionViewSet', 'JobRunVariableHelpAPIView', 'JobAssetDetail', 'JobExecutionTaskDetail']
__all__ = ['JobViewSet', 'JobExecutionViewSet', 'JobRunVariableHelpAPIView',
'JobAssetDetail', 'JobExecutionTaskDetail','FrequentUsernames']
from ops.tasks import run_ops_job_execution
from ops.variables import JMS_JOB_VARIABLE_HELP
from orgs.mixins.api import OrgBulkModelViewSet
from orgs.utils import tmp_to_org, get_current_org_id, get_current_org
from assets.models import Account
def set_task_to_serializer_data(serializer, task):
@@ -111,3 +114,12 @@ class JobExecutionTaskDetail(APIView):
'is_success': execution.is_success,
'time_cost': execution.time_cost,
})
class FrequentUsernames(APIView):
rbac_perms = ()
permission_classes = ()
def get(self, request, **kwargs):
top_accounts = Account.objects.all().values('username').annotate(total=Count('username')).order_by('total')
return Response(data=top_accounts)