summaryrefslogtreecommitdiff
path: root/src/automationstatus/views.py
blob: df7586815ca8ac870d171202a247f73ea44c62c3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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)