Scott Baker | 5f4770d | 2014-07-13 11:17:58 -0700 | [diff] [blame] | 1 | from core.models.slice import Slice |
Scott Baker | e791dc6 | 2014-08-28 14:02:54 -0700 | [diff] [blame] | 2 | from plus import PlusObjectMixin |
Scott Baker | 5f4770d | 2014-07-13 11:17:58 -0700 | [diff] [blame] | 3 | |
Scott Baker | e791dc6 | 2014-08-28 14:02:54 -0700 | [diff] [blame] | 4 | class SlicePlus(Slice, PlusObjectMixin): |
Scott Baker | 88e3437 | 2014-07-13 11:46:36 -0700 | [diff] [blame] | 5 | class Meta: |
| 6 | proxy = True |
| 7 | |
Scott Baker | 5f4770d | 2014-07-13 11:17:58 -0700 | [diff] [blame] | 8 | def getSliceInfo(self, user=None): |
Scott Baker | 88e3437 | 2014-07-13 11:46:36 -0700 | [diff] [blame] | 9 | used_sites = {} |
| 10 | used_deployments = {} |
Scott Baker | 5f4770d | 2014-07-13 11:17:58 -0700 | [diff] [blame] | 11 | sliverCount = 0 |
| 12 | for sliver in self.slivers.all(): |
Scott Baker | dc84412 | 2015-01-07 11:15:08 -0800 | [diff] [blame] | 13 | site = sliver.node.site_deployment.site |
| 14 | deployment = sliver.node.site_deployment.deployment |
Scott Baker | 88e3437 | 2014-07-13 11:46:36 -0700 | [diff] [blame] | 15 | used_sites[site.name] = used_sites.get(site.name, 0) + 1 |
Scott Baker | 5f4770d | 2014-07-13 11:17:58 -0700 | [diff] [blame] | 16 | used_deployments[deployment.name] = used_deployments.get(deployment.name, 0) + 1 |
Scott Baker | 88e3437 | 2014-07-13 11:46:36 -0700 | [diff] [blame] | 17 | sliverCount = sliverCount + 1 |
Scott Baker | 5f4770d | 2014-07-13 11:17:58 -0700 | [diff] [blame] | 18 | |
| 19 | roles = [] |
| 20 | if (user!=None): |
Scott Baker | c865508 | 2014-12-23 11:03:58 -0800 | [diff] [blame] | 21 | roles = [x.role.role for x in self.sliceprivileges.filter(user=user)] |
Scott Baker | 5f4770d | 2014-07-13 11:17:58 -0700 | [diff] [blame] | 22 | |
| 23 | return {"sitesUsed": used_sites, |
| 24 | "deploymentsUsed": used_deployments, |
Scott Baker | 88e3437 | 2014-07-13 11:46:36 -0700 | [diff] [blame] | 25 | "sliverCount": sliverCount, |
Scott Baker | 5f4770d | 2014-07-13 11:17:58 -0700 | [diff] [blame] | 26 | "siteCount": len(used_sites.keys()), |
| 27 | "roles": roles} |
Scott Baker | 88e3437 | 2014-07-13 11:46:36 -0700 | [diff] [blame] | 28 | |
Scott Baker | 9062b0c | 2015-01-08 22:34:51 -0800 | [diff] [blame] | 29 | @property |
Scott Baker | 697512d | 2015-01-08 22:37:34 -0800 | [diff] [blame] | 30 | def network_ports(self): |
Scott Baker | 9062b0c | 2015-01-08 22:34:51 -0800 | [diff] [blame] | 31 | # 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 Baker | 697512d | 2015-01-08 22:37:34 -0800 | [diff] [blame] | 42 | @network_ports.setter |
| 43 | def network_ports(self, value): |
Scott Baker | 9062b0c | 2015-01-08 22:34:51 -0800 | [diff] [blame] | 44 | print "XXX set networkPorts to", value |
| 45 | |
Scott Baker | 88e3437 | 2014-07-13 11:46:36 -0700 | [diff] [blame] | 46 | @staticmethod |
| 47 | def select_by_user(user): |
Scott Baker | 88e3437 | 2014-07-13 11:46:36 -0700 | [diff] [blame] | 48 | 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 Baker | 88e3437 | 2014-07-13 11:46:36 -0700 | [diff] [blame] | 53 | return qs |