2022-10-25 04:57:34 +00:00
|
|
|
from rest_framework import viewsets
|
2022-10-28 10:19:44 +00:00
|
|
|
from rest_framework.decorators import action
|
|
|
|
from rest_framework.response import Response
|
2022-10-25 04:57:34 +00:00
|
|
|
|
2022-10-28 10:19:44 +00:00
|
|
|
from terminal import serializers
|
2022-11-01 03:52:51 +00:00
|
|
|
from terminal.models import AppletHost, Applet, AppletHostDeployment
|
2022-10-28 10:19:44 +00:00
|
|
|
from terminal.tasks import run_applet_host_deployment
|
2022-10-25 04:57:34 +00:00
|
|
|
|
2022-11-01 03:52:51 +00:00
|
|
|
|
|
|
|
__all__ = ['AppletHostViewSet', 'AppletHostDeploymentViewSet']
|
2022-10-25 04:57:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
class AppletHostViewSet(viewsets.ModelViewSet):
|
|
|
|
serializer_class = serializers.AppletHostSerializer
|
2022-11-01 03:52:51 +00:00
|
|
|
queryset = AppletHost.objects.all()
|
2022-10-28 10:19:44 +00:00
|
|
|
|
2022-11-01 03:52:51 +00:00
|
|
|
|
|
|
|
class AppletHostDeploymentViewSet(viewsets.ModelViewSet):
|
|
|
|
serializer_class = serializers.AppletHostDeploymentSerializer
|
|
|
|
queryset = AppletHostDeployment.objects.all()
|
|
|
|
|
|
|
|
def create(self, request, *args, **kwargs):
|
|
|
|
serializer = self.get_serializer(data=request.data)
|
|
|
|
serializer.is_valid(raise_exception=True)
|
|
|
|
instance = serializer.save()
|
|
|
|
task = run_applet_host_deployment.delay(instance.id)
|
|
|
|
return Response({'task': str(task.id)}, status=201)
|
|
|
|
|