from rest_framework import viewsets from caas.models import Cluster, Location, Server from .models import AutomationStatus from .serializers import AutomationStatusSerializer class AutomationStatusViewSet(viewsets.ModelViewSet): queryset = AutomationStatus.objects.all().order_by('created_at') serializer_class = AutomationStatusSerializer def perform_create(self, serializer): # Lookup cluster name based on the ilo_host_address server = Server.objects.get(ilo_host_address=self.request.data['ilo_host_address']) cluster = Cluster.objects.get(id=server.cluster_id) fuze_id = cluster.location_id location = Location.objects.get(id=fuze_id) serializer.save( cluster_name=cluster.cluster_name, fuze_spm_site_name=location.fuze_spm_site_name, fuze_spm_site_id=location.fuze_spm_site_id)