mirror of
https://github.com/ansible/awx.git
synced 2026-03-23 11:55:04 -02:30
create new bulk host create endpoint
allow system admins, org admins, and inventory admins to bulk create hosts. Testing on an "open" licensed awx as system admin, I created 1000 hosts with 6 queries in ~ 0.15 seconds Testing on an "open" licensed awx as organization admin, I created 1000 hosts with 11 queries in ~ 0.15 seconds fix org max host check also only do permission denied if license is a trial add /api/v2/bulk to list bulk apis available add api description templates One motiviation to not take a list of hosts with mixed inventories is to keep things simple re: RBAC and keeping a constant number of queries. If there is great clamor for accepting list of hosts to insert into arbitrary different inventories, we could probably make it happen - we'd need to pop the inventory off of each of the hosts, run the HostSerializer validate, then in top level BulkHostCreateSerializer fetch all the inventories/check permissions/org host limits for those inventories/etc. But that makes this that much more complicated. add test for rbac access test also helped me find a bug in a query, fixed that add test to assert num queries scales as expected also move other test to dedicated file also test with super user like I meant to record activity stream for the inventory this records that a certain number of hosts were added by a certain user we could consider if there is any other additional information we want to include
This commit is contained in:
49
awx/api/views/bulk.py
Normal file
49
awx/api/views/bulk.py
Normal file
@@ -0,0 +1,49 @@
|
||||
from collections import OrderedDict
|
||||
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.renderers import JSONRenderer
|
||||
from rest_framework.reverse import reverse
|
||||
from rest_framework import status
|
||||
from rest_framework.response import Response
|
||||
|
||||
from awx.api.generics import (
|
||||
GenericAPIView,
|
||||
APIView,
|
||||
)
|
||||
from awx.api import (
|
||||
serializers,
|
||||
renderers,
|
||||
)
|
||||
|
||||
|
||||
class BulkView(APIView):
|
||||
_ignore_model_permissions = True
|
||||
permission_classes = [IsAuthenticated]
|
||||
renderer_classes = [
|
||||
renderers.BrowsableAPIRenderer,
|
||||
JSONRenderer,
|
||||
]
|
||||
allowed_methods = ['GET', 'OPTIONS']
|
||||
|
||||
def get(self, request, format=None):
|
||||
'''List top level resources'''
|
||||
data = OrderedDict()
|
||||
data['bulk_host_create'] = reverse('api:bulk_host_create', request=request)
|
||||
return Response(data)
|
||||
|
||||
|
||||
class BulkHostCreateView(GenericAPIView):
|
||||
_ignore_model_permissions = True
|
||||
permission_classes = [IsAuthenticated]
|
||||
serializer_class = serializers.BulkHostCreateSerializer
|
||||
allowed_methods = ['GET', 'POST', 'OPTIONS']
|
||||
|
||||
def get(self, request):
|
||||
return Response({"detail": "Bulk create hosts with this endpoint"}, status=status.HTTP_200_OK)
|
||||
|
||||
def post(self, request):
|
||||
serializer = serializers.BulkHostCreateSerializer(data=request.data, context={'request': request})
|
||||
if serializer.is_valid():
|
||||
result = serializer.create(serializer.validated_data)
|
||||
return Response(result, status=status.HTTP_201_CREATED)
|
||||
return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
|
||||
@@ -121,6 +121,7 @@ class ApiVersionRootView(APIView):
|
||||
data['workflow_job_template_nodes'] = reverse('api:workflow_job_template_node_list', request=request)
|
||||
data['workflow_job_nodes'] = reverse('api:workflow_job_node_list', request=request)
|
||||
data['mesh_visualizer'] = reverse('api:mesh_visualizer_view', request=request)
|
||||
data['bulk'] = reverse('api:bulk', request=request)
|
||||
return Response(data)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user