Merge branch 'master' of ssh://git.planet-lab.org/git/plstackapi
diff --git a/planetstack/core/xoslib/methods/sliceplus.py b/planetstack/core/xoslib/methods/sliceplus.py
index c48d036..4d15d41 100644
--- a/planetstack/core/xoslib/methods/sliceplus.py
+++ b/planetstack/core/xoslib/methods/sliceplus.py
@@ -44,6 +44,7 @@
network_ports = NetworkPortsField(required=False)
site_allocation = DictionaryField(required=False)
users = ListField(required=False)
+ user_names = ListField(required=False) # readonly = True ?
def getSliceInfo(self, slice):
return slice.getSliceInfo(user=self.context['request'].user)
@@ -57,7 +58,7 @@
model = SlicePlus
fields = ('humanReadableName', 'id','created','updated','enacted','name','enabled','omf_friendly','description','slice_url','site','max_slivers','service','network','mount_data_sets',
'default_image', 'default_flavor',
- 'serviceClass','creator','networks','sliceInfo','network_ports','backendIcon','backendHtml','site_allocation','users')
+ 'serviceClass','creator','networks','sliceInfo','network_ports','backendIcon','backendHtml','site_allocation','users',"user_names")
class SlicePlusList(PlusListCreateAPIView): #generics.ListCreateAPIView):
queryset = SlicePlus.objects.select_related().all()
diff --git a/planetstack/core/xoslib/objects/sliceplus.py b/planetstack/core/xoslib/objects/sliceplus.py
index 73017ee..4fdc824 100644
--- a/planetstack/core/xoslib/objects/sliceplus.py
+++ b/planetstack/core/xoslib/objects/sliceplus.py
@@ -10,27 +10,39 @@
super(SlicePlus, self).__init__(*args, **kwargs)
self._update_site_allocation = None
self._update_users = None
+ self._sliceInfo = None
def getSliceInfo(self, user=None):
- used_sites = {}
- used_deployments = {}
- sliverCount = 0
- for sliver in self.slivers.all():
- site = sliver.node.site_deployment.site
- deployment = sliver.node.site_deployment.deployment
- 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
+ if not self._sliceInfo:
+ used_sites = {}
+ used_deployments = {}
+ sliverCount = 0
+ for sliver in self.slivers.all():
+ site = sliver.node.site_deployment.site
+ deployment = sliver.node.site_deployment.deployment
+ 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):
- roles = [x.role.role for x in self.sliceprivileges.filter(user=user)]
+ users = {}
+ for priv in SlicePrivilege.objects.filter(slice=self):
+ if not (priv.user.id in users.keys()):
+ users[priv.user.id] = {"name": priv.user.email, "id": priv.user.id, "roles": []}
+ users[priv.user.id]["roles"].append(priv.role.role)
- return {"sitesUsed": used_sites,
- "deploymentsUsed": used_deployments,
- "sliverCount": sliverCount,
- "siteCount": len(used_sites.keys()),
- "roles": roles}
+ self._sliceInfo= {"sitesUsed": used_sites,
+ "deploymentsUsed": used_deployments,
+ "sliverCount": sliverCount,
+ "siteCount": len(used_sites.keys()),
+ "users": users,
+ "roles": []}
+
+ if user:
+ auser = self._sliceInfo["users"].get(user.id, None)
+ if (auser):
+ self._sliceInfo["roles"] = auser["roles"]
+
+ return self._sliceInfo
@property
def site_allocation(self):
@@ -42,12 +54,12 @@
#print "XXX set sitesUsed to", value
@property
+ def user_names(self):
+ return [user["name"] for user in self.getSliceInfo()["users"].values()]
+
+ @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
+ return [user["id"] for user in self.getSliceInfo()["users"].values()]
@users.setter
def users(self, value):
@@ -165,7 +177,6 @@
for user_id in new_users:
if (user_id not in slice_user_ids):
- print "XXX", user_id
priv = SlicePrivilege(slice=self, user=User.objects.get(id=user_id), role=default_role)
if (not noAct):
priv.save()
diff --git a/planetstack/core/xoslib/static/js/xoslib/xos-util.js b/planetstack/core/xoslib/static/js/xoslib/xos-util.js
index 15aa1b0..7a57d8a 100644
--- a/planetstack/core/xoslib/static/js/xoslib/xos-util.js
+++ b/planetstack/core/xoslib/static/js/xoslib/xos-util.js
@@ -100,7 +100,7 @@
return names[index];
}
}
- return undefined;
+ return "object #" + x;
}
function all_options(selector) {