blob: 2542fd7670f453ce06b22d02f5f88a65c7abea6d [file] [log] [blame]
Scott Baker5f4770d2014-07-13 11:17:58 -07001from core.models.slice import Slice
2
3class SlicePlus(Slice):
Scott Baker88e34372014-07-13 11:46:36 -07004 class Meta:
5 proxy = True
6
Scott Baker5f4770d2014-07-13 11:17:58 -07007 def getSliceInfo(self, user=None):
Scott Baker88e34372014-07-13 11:46:36 -07008 used_sites = {}
9 used_deployments = {}
Scott Baker5f4770d2014-07-13 11:17:58 -070010 sliverCount = 0
11 for sliver in self.slivers.all():
12 site = sliver.node.site
13 deployment = sliver.node.deployment
Scott Baker88e34372014-07-13 11:46:36 -070014 used_sites[site.name] = used_sites.get(site.name, 0) + 1
Scott Baker5f4770d2014-07-13 11:17:58 -070015 used_deployments[deployment.name] = used_deployments.get(deployment.name, 0) + 1
Scott Baker88e34372014-07-13 11:46:36 -070016 sliverCount = sliverCount + 1
Scott Baker5f4770d2014-07-13 11:17:58 -070017
18 roles = []
19 if (user!=None):
20 roles = [x.role for x in self.slice_privileges.filter(user=user)]
21
22 return {"sitesUsed": used_sites,
23 "deploymentsUsed": used_deployments,
Scott Baker88e34372014-07-13 11:46:36 -070024 "sliverCount": sliverCount,
Scott Baker5f4770d2014-07-13 11:17:58 -070025 "siteCount": len(used_sites.keys()),
26 "roles": roles}
Scott Baker88e34372014-07-13 11:46:36 -070027
28 @staticmethod
29 def select_by_user(user):
Scott Baker88e34372014-07-13 11:46:36 -070030 if user.is_admin:
31 qs = SlicePlus.objects.all()
32 else:
33 slice_ids = [sp.slice.id for sp in SlicePrivilege.objects.filter(user=user)]
34 qs = SlicePlus.objects.filter(id__in=slice_ids)
Scott Baker88e34372014-07-13 11:46:36 -070035 return qs