xoslib method to get tenant view info
Scott Baker [Fri, 9 Jan 2015 06:38:17 +0000 (22:38 -0800)]
planetstack/core/xoslib/methods/tenantview.py [new file with mode: 0644]

diff --git a/planetstack/core/xoslib/methods/tenantview.py b/planetstack/core/xoslib/methods/tenantview.py
new file mode 100644 (file)
index 0000000..c7ce500
--- /dev/null
@@ -0,0 +1,64 @@
+from rest_framework.decorators import api_view
+from rest_framework.response import Response\r
+from rest_framework.reverse import reverse\r
+from rest_framework import serializers\r
+from rest_framework import generics\r
+from rest_framework.views import APIView\r
+from core.models import *\r
+from django.forms import widgets
+from syndicate_storage.models import Volume
+
+# This REST API endpoint contains a bunch of misc information that the
+# tenant view needs to display
+
+BLESSED_DEPLOYMENTS = ["ViCCI"] # ["US-MaxPlanck", "US-GeorgiaTech", "US-Princeton", "US-Washington", "US-Stanford"]
+
+
+def getTenantViewDict():
+    blessed_sites = []
+    for site in Site.objects.all():
+        good=False
+        for deployment in site.deployments.all():
+            if deployment.name in BLESSED_DEPLOYMENTS:
+                good=True
+        if good:
+            blessed_sites.append(site)
+
+    blessed_images=[]
+    for image in Image.objects.all():
+        good = False
+        for deployment in image.deployments.all():
+            if deployment.name in BLESSED_DEPLOYMENTS:
+                 good=True
+        if good:
+            blessed_images.append(image)
+
+    volumes=[]
+    for volume in Volume.objects.all():
+        if not volume.private:\r
+            volumes.append(volume)
+
+    return {"id": 0,
+            "blessed_deployment_names": BLESSED_DEPLOYMENTS,
+            "blessed_site_names": [site.name for site in blessed_sites],
+            "blessed_sites": [site.id for site in blessed_sites],
+            "blessed_image_names": [image.name for image in blessed_images],
+            "blessed_images": [image.id for image in blessed_images],
+            "public_volume_names": [volume.name for volume in volumes],
+            "public_volumes": [volume.id for volume in volumes],
+            }
+
+class TenantList(APIView):
+    method_kind = "list"
+    method_name = "tenantview"
+
+    def get(self, request, format=None):
+        return Response( getTenantViewDict() )
+
+class TenantDetail(APIView):
+    method_kind = "detail"
+    method_name = "tenantview"
+
+    def get(self, request, format=None, pk=0):
+        return Response( [getTenantViewDict()] )
+