blob: efb6b2ab8eacff466651b094c184b8b4e667248a [file] [log] [blame]
Scott Baker5f4770d2014-07-13 11:17:58 -07001from core.models.slice import Slice
Scott Bakere791dc62014-08-28 14:02:54 -07002from plus import PlusObjectMixin
Scott Baker5f4770d2014-07-13 11:17:58 -07003
Scott Bakere791dc62014-08-28 14:02:54 -07004class SlicePlus(Slice, PlusObjectMixin):
Scott Baker88e34372014-07-13 11:46:36 -07005 class Meta:
6 proxy = True
7
Scott Baker5f4770d2014-07-13 11:17:58 -07008 def getSliceInfo(self, user=None):
Scott Baker88e34372014-07-13 11:46:36 -07009 used_sites = {}
10 used_deployments = {}
Scott Baker5f4770d2014-07-13 11:17:58 -070011 sliverCount = 0
12 for sliver in self.slivers.all():
Scott Bakerdc844122015-01-07 11:15:08 -080013 site = sliver.node.site_deployment.site
14 deployment = sliver.node.site_deployment.deployment
Scott Baker88e34372014-07-13 11:46:36 -070015 used_sites[site.name] = used_sites.get(site.name, 0) + 1
Scott Baker5f4770d2014-07-13 11:17:58 -070016 used_deployments[deployment.name] = used_deployments.get(deployment.name, 0) + 1
Scott Baker88e34372014-07-13 11:46:36 -070017 sliverCount = sliverCount + 1
Scott Baker5f4770d2014-07-13 11:17:58 -070018
19 roles = []
20 if (user!=None):
Scott Bakerc8655082014-12-23 11:03:58 -080021 roles = [x.role.role for x in self.sliceprivileges.filter(user=user)]
Scott Baker5f4770d2014-07-13 11:17:58 -070022
23 return {"sitesUsed": used_sites,
24 "deploymentsUsed": used_deployments,
Scott Baker88e34372014-07-13 11:46:36 -070025 "sliverCount": sliverCount,
Scott Baker5f4770d2014-07-13 11:17:58 -070026 "siteCount": len(used_sites.keys()),
27 "roles": roles}
Scott Baker88e34372014-07-13 11:46:36 -070028
Scott Baker9062b0c2015-01-08 22:34:51 -080029 @property
Scott Baker697512d2015-01-08 22:37:34 -080030 def network_ports(self):
Scott Baker9062b0c2015-01-08 22:34:51 -080031 # XXX this assumes there is only one network that can have ports bound
32 # to it for a given slice. This is intended for the tenant view, which
33 # will obey this field.
34 networkPorts = ""
35 for networkSlice in self.networkslices.all():
36 network = networkSlice.network
37 if network.ports:
38 networkPorts = network.ports
39
40 return networkPorts
41
Scott Baker697512d2015-01-08 22:37:34 -080042 @network_ports.setter
43 def network_ports(self, value):
Scott Baker9062b0c2015-01-08 22:34:51 -080044 print "XXX set networkPorts to", value
45
Scott Baker88e34372014-07-13 11:46:36 -070046 @staticmethod
47 def select_by_user(user):
Scott Baker88e34372014-07-13 11:46:36 -070048 if user.is_admin:
49 qs = SlicePlus.objects.all()
50 else:
51 slice_ids = [sp.slice.id for sp in SlicePrivilege.objects.filter(user=user)]
52 qs = SlicePlus.objects.filter(id__in=slice_ids)
Scott Baker88e34372014-07-13 11:46:36 -070053 return qs