blob: b2e0e0e82d9f1225b888bb9aa80d355edd34d416 [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
Scott Bakerc94091a2015-01-12 12:57:44 -080016def getTenantViewDict(user):
Scott Baker03324832015-01-08 22:38:17 -080017 blessed_sites = []
18 for site in Site.objects.all():
19 good=False
20 for deployment in site.deployments.all():
21 if deployment.name in BLESSED_DEPLOYMENTS:
22 good=True
23 if good:
24 blessed_sites.append(site)
25
26 blessed_images=[]
27 for image in Image.objects.all():
28 good = False
29 for deployment in image.deployments.all():
30 if deployment.name in BLESSED_DEPLOYMENTS:
31 good=True
32 if good:
33 blessed_images.append(image)
34
Scott Baker2a11f252015-01-12 13:37:01 -080035 blessed_flavors=[]
36 for flavor in Flavor.objects.all():
37 good = False
38 for deployment in flavor.deployments.all():
39 if deployment.name in BLESSED_DEPLOYMENTS:
40 good=True
41 if good:
42 blessed_flavors.append(flavor)
43
Scott Baker03324832015-01-08 22:38:17 -080044 volumes=[]
45 for volume in Volume.objects.all():
46 if not volume.private:
47 volumes.append(volume)
48
Scott Baker97acad92015-01-12 19:45:40 -080049 site_users=[]
50 for auser in user.site.users.all():
51 site_users.append(auser)
52
Scott Baker2a11f252015-01-12 13:37:01 -080053 blessed_service_classes = [ServiceClass.objects.get(name="Best Effort")]
54
Scott Baker03324832015-01-08 22:38:17 -080055 return {"id": 0,
56 "blessed_deployment_names": BLESSED_DEPLOYMENTS,
57 "blessed_site_names": [site.name for site in blessed_sites],
58 "blessed_sites": [site.id for site in blessed_sites],
59 "blessed_image_names": [image.name for image in blessed_images],
60 "blessed_images": [image.id for image in blessed_images],
Scott Baker2a11f252015-01-12 13:37:01 -080061 "blessed_flavor_names": [flavor.name for flavor in blessed_flavors],
62 "blessed_flavors": [flavor.id for flavor in blessed_flavors],
63 "blessed_service_class_names": [serviceclass.name for serviceclass in blessed_service_classes],
64 "blessed_service_classes": [serviceclass.id for serviceclass in blessed_service_classes],
Scott Baker03324832015-01-08 22:38:17 -080065 "public_volume_names": [volume.name for volume in volumes],
66 "public_volumes": [volume.id for volume in volumes],
Scott Bakerc94091a2015-01-12 12:57:44 -080067 "current_user_site_id": user.site.id,
68 "current_user_login_base": user.site.login_base,
Scott Baker97acad92015-01-12 19:45:40 -080069 "current_user_site_users": [auser.id for auser in site_users],
70 "current_user_site_user_names": [auser.email for auser in site_users],
Scott Baker03324832015-01-08 22:38:17 -080071 }
72
73class TenantList(APIView):
74 method_kind = "list"
75 method_name = "tenantview"
76
77 def get(self, request, format=None):
Scott Bakerc94091a2015-01-12 12:57:44 -080078 return Response( getTenantViewDict(request.user) )
Scott Baker03324832015-01-08 22:38:17 -080079
80class TenantDetail(APIView):
81 method_kind = "detail"
82 method_name = "tenantview"
83
84 def get(self, request, format=None, pk=0):
Scott Bakerc94091a2015-01-12 12:57:44 -080085 return Response( [getTenantViewDict(request.user)] )
Scott Baker03324832015-01-08 22:38:17 -080086