Scott Baker | 45a09b1 | 2015-01-08 22:38:17 -0800 | [diff] [blame] | 1 | from rest_framework.decorators import api_view |
| 2 | from rest_framework.response import Response
|
| 3 | from rest_framework.reverse import reverse
|
| 4 | from rest_framework import serializers
|
| 5 | from rest_framework import generics
|
| 6 | from rest_framework.views import APIView
|
| 7 | from core.models import *
|
| 8 | from django.forms import widgets |
| 9 | from 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 | |
| 14 | BLESSED_DEPLOYMENTS = ["ViCCI"] # ["US-MaxPlanck", "US-GeorgiaTech", "US-Princeton", "US-Washington", "US-Stanford"] |
| 15 | |
Scott Baker | 48b84d1 | 2015-01-12 12:57:44 -0800 | [diff] [blame] | 16 | def getTenantViewDict(user): |
Scott Baker | 45a09b1 | 2015-01-08 22:38:17 -0800 | [diff] [blame] | 17 | 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 | |
| 35 | volumes=[] |
| 36 | for volume in Volume.objects.all(): |
| 37 | if not volume.private:
|
| 38 | volumes.append(volume) |
| 39 | |
| 40 | return {"id": 0, |
| 41 | "blessed_deployment_names": BLESSED_DEPLOYMENTS, |
| 42 | "blessed_site_names": [site.name for site in blessed_sites], |
| 43 | "blessed_sites": [site.id for site in blessed_sites], |
| 44 | "blessed_image_names": [image.name for image in blessed_images], |
| 45 | "blessed_images": [image.id for image in blessed_images], |
| 46 | "public_volume_names": [volume.name for volume in volumes], |
| 47 | "public_volumes": [volume.id for volume in volumes], |
Scott Baker | 48b84d1 | 2015-01-12 12:57:44 -0800 | [diff] [blame] | 48 | "current_user_site_id": user.site.id, |
| 49 | "current_user_login_base": user.site.login_base, |
Scott Baker | 45a09b1 | 2015-01-08 22:38:17 -0800 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | class TenantList(APIView): |
| 53 | method_kind = "list" |
| 54 | method_name = "tenantview" |
| 55 | |
| 56 | def get(self, request, format=None): |
Scott Baker | 48b84d1 | 2015-01-12 12:57:44 -0800 | [diff] [blame] | 57 | return Response( getTenantViewDict(request.user) ) |
Scott Baker | 45a09b1 | 2015-01-08 22:38:17 -0800 | [diff] [blame] | 58 | |
| 59 | class TenantDetail(APIView): |
| 60 | method_kind = "detail" |
| 61 | method_name = "tenantview" |
| 62 | |
| 63 | def get(self, request, format=None, pk=0): |
Scott Baker | 48b84d1 | 2015-01-12 12:57:44 -0800 | [diff] [blame] | 64 | return Response( [getTenantViewDict(request.user)] ) |
Scott Baker | 45a09b1 | 2015-01-08 22:38:17 -0800 | [diff] [blame] | 65 | |