edit users button in tenant view
[plstackapi.git] / planetstack / core / xoslib / objects / sliceplus.py
index ddec295..adbc77e 100644 (file)
@@ -1,4 +1,4 @@
-from core.models.slice import Slice
+from core.models.slice import Slice, SlicePrivilege
 from plus import PlusObjectMixin
 
 class SlicePlus(Slice, PlusObjectMixin):
@@ -26,6 +26,43 @@ class SlicePlus(Slice, PlusObjectMixin):
                 "siteCount": len(used_sites.keys()),
                 "roles": roles}
 
+    @property
+    def site_allocation(self):
+        return self.getSliceInfo()["sitesUsed"]
+
+    @site_allocation.setter
+    def site_allocation(self, value):
+        print "XXX set sitesUsed to", value
+
+    @property
+    def users(self):
+        user_ids = []
+        for priv in SlicePrivilege.objects.filter(slice=self):
+            if not (priv.user.id in user_ids):
+                user_ids.append(priv.user.id)
+        return user_ids
+
+    @users.setter
+    def users(self, value):
+        print "XXX set users to", value
+
+    @property
+    def network_ports(self):
+        # XXX this assumes there is only one network that can have ports bound
+        # to it for a given slice. This is intended for the tenant view, which
+        # will obey this field.
+        networkPorts = ""
+        for networkSlice in self.networkslices.all():
+            network = networkSlice.network
+            if network.ports:
+                networkPorts = network.ports
+
+        return networkPorts
+
+    @network_ports.setter
+    def network_ports(self, value):
+        print "XXX set networkPorts to", value
+
     @staticmethod
     def select_by_user(user):
         if user.is_admin: