blob: c7ce500b2baf68d5b090ebfd2829d5b00d448c71 [file] [log] [blame]
Scott Baker03324832015-01-08 22:38:17 -08001from rest_framework.decorators import api_view
2from rest_framework.response import Response
3from rest_framework.reverse import reverse
4from rest_framework import serializers
5from rest_framework import generics
6from rest_framework.views import APIView
7from core.models import *
8from django.forms import widgets
9from syndicate_storage.models import Volume
10
11# This REST API endpoint contains a bunch of misc information that the
12# tenant view needs to display
13
14BLESSED_DEPLOYMENTS = ["ViCCI"] # ["US-MaxPlanck", "US-GeorgiaTech", "US-Princeton", "US-Washington", "US-Stanford"]
15
16
17def getTenantViewDict():
18 blessed_sites = []
19 for site in Site.objects.all():
20 good=False
21 for deployment in site.deployments.all():
22 if deployment.name in BLESSED_DEPLOYMENTS:
23 good=True
24 if good:
25 blessed_sites.append(site)
26
27 blessed_images=[]
28 for image in Image.objects.all():
29 good = False
30 for deployment in image.deployments.all():
31 if deployment.name in BLESSED_DEPLOYMENTS:
32 good=True
33 if good:
34 blessed_images.append(image)
35
36 volumes=[]
37 for volume in Volume.objects.all():
38 if not volume.private:
39 volumes.append(volume)
40
41 return {"id": 0,
42 "blessed_deployment_names": BLESSED_DEPLOYMENTS,
43 "blessed_site_names": [site.name for site in blessed_sites],
44 "blessed_sites": [site.id for site in blessed_sites],
45 "blessed_image_names": [image.name for image in blessed_images],
46 "blessed_images": [image.id for image in blessed_images],
47 "public_volume_names": [volume.name for volume in volumes],
48 "public_volumes": [volume.id for volume in volumes],
49 }
50
51class TenantList(APIView):
52 method_kind = "list"
53 method_name = "tenantview"
54
55 def get(self, request, format=None):
56 return Response( getTenantViewDict() )
57
58class TenantDetail(APIView):
59 method_kind = "detail"
60 method_name = "tenantview"
61
62 def get(self, request, format=None, pk=0):
63 return Response( [getTenantViewDict()] )
64