prototype first virtual object for xoslib: sliceplus
diff --git a/planetstack/core/xoslib/__init__.py b/planetstack/core/xoslib/__init__.py
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/planetstack/core/xoslib/__init__.py
@@ -0,0 +1 @@
+
diff --git a/planetstack/core/xoslib/methods/__init__.py b/planetstack/core/xoslib/methods/__init__.py
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/planetstack/core/xoslib/methods/__init__.py
@@ -0,0 +1 @@
+
diff --git a/planetstack/core/xoslib/methods/sliceplus.py b/planetstack/core/xoslib/methods/sliceplus.py
new file mode 100644
index 0000000..79aae3b
--- /dev/null
+++ b/planetstack/core/xoslib/methods/sliceplus.py
@@ -0,0 +1,59 @@
+from rest_framework.decorators import api_view
+from rest_framework.response import Response
+from rest_framework.reverse import reverse
+from rest_framework import serializers
+from rest_framework import generics
+from core.models import *
+from django.forms import widgets
+from core.xoslib.objects.sliceplus import SlicePlus
+
+class SlicePlusIdSerializer(serializers.ModelSerializer):
+ id = serializers.Field()
+
+ sliceInfo = serializers.SerializerMethodField("getSliceInfo")
+
+ def getSliceInfo(self, slice):
+ return slice.getSliceInfo()
+
+ networks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
+ availableNetworks = serializers.HyperlinkedRelatedField(many=True, read_only=True, view_name='network-detail')
+
+ class Meta:
+ model = SlicePlus
+ fields = ('id','created','updated','enacted','name','enabled','omf_friendly','description','slice_url','site','max_slivers','imagePreference','service','network','mountDataSets','serviceClass','creator','networks','availableNetworks','sliceInfo')
+
+class SlicePlusList(generics.ListCreateAPIView):
+ queryset = SlicePlus.objects.select_related().all()
+ serializer_class = SlicePlusIdSerializer
+
+ def get_queryset(self):
+ return SlicePlus.select_by_user(self.request.user)
+
+ def create(self, request, *args, **kwargs):
+ obj = self.get_object()
+ obj.caller = request.user
+ if obj.can_update(request.user):
+ return super(SliceList, self).create(request, *args, **kwargs)
+ else:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+
+class SlicePlusDetail(generics.RetrieveUpdateDestroyAPIView):
+ queryset = SlicePlus.objects.select_related().all()
+ serializer_class = SlicePlusIdSerializer
+
+ def get_queryset(self):
+ return SlicePlus.select_by_user(self.request.user)
+
+ def update(self, request, *args, **kwargs):
+ obj = self.get_object()
+ if obj.can_update(request.user):
+ return super(SlicePlusDetail, self).update(request, *args, **kwargs)
+ else:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
+
+ def destroy(self, request, *args, **kwargs):
+ obj = self.get_object()
+ if obj.can_update(request.user):
+ return super(SlicePlusDetail, self).destroy(request, *args, **kwargs)
+ else:
+ return Response(status=status.HTTP_400_BAD_REQUEST)
diff --git a/planetstack/core/xoslib/objects/__init__.py b/planetstack/core/xoslib/objects/__init__.py
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/planetstack/core/xoslib/objects/__init__.py
@@ -0,0 +1 @@
+
diff --git a/planetstack/core/xoslib/objects/sliceplus.py b/planetstack/core/xoslib/objects/sliceplus.py
index a68602d..e35f4d1 100644
--- a/planetstack/core/xoslib/objects/sliceplus.py
+++ b/planetstack/core/xoslib/objects/sliceplus.py
@@ -1,15 +1,19 @@
from core.models.slice import Slice
class SlicePlus(Slice):
+ class Meta:
+ proxy = True
+
def getSliceInfo(self, user=None):
- used_sites = []
- used_deployments = []
+ used_sites = {}
+ used_deployments = {}
sliverCount = 0
for sliver in self.slivers.all():
site = sliver.node.site
deployment = sliver.node.deployment
- used_sites[site.name] = used.sites.get(site.name, 0) + 1
+ used_sites[site.name] = used_sites.get(site.name, 0) + 1
used_deployments[deployment.name] = used_deployments.get(deployment.name, 0) + 1
+ sliverCount = sliverCount + 1
roles = []
if (user!=None):
@@ -17,6 +21,18 @@
return {"sitesUsed": used_sites,
"deploymentsUsed": used_deployments,
- "sliverCount": sliceCount,
+ "sliverCount": sliverCount,
"siteCount": len(used_sites.keys()),
"roles": roles}
+
+ @staticmethod
+ def select_by_user(user):
+ print "XX"
+ if user.is_admin:
+ qs = SlicePlus.objects.all()
+ else:
+ slice_ids = [sp.slice.id for sp in SlicePrivilege.objects.filter(user=user)]
+ qs = SlicePlus.objects.filter(id__in=slice_ids)
+ print qs
+ print qs.all()
+ return qs