Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1 | import os |
| 2 | from django.db import models |
Sapan Bhatia | 4a62a2f | 2014-09-22 18:47:53 -0400 | [diff] [blame] | 3 | from django.db.models import Q |
Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 4 | from django.contrib.contenttypes import generic |
Tony Mack | a6928d6 | 2015-03-29 09:29:12 -0400 | [diff] [blame] | 5 | from django.core.exceptions import PermissionDenied |
Siobhan Tully | 567e3e6 | 2013-06-21 18:03:16 -0400 | [diff] [blame] | 6 | from geoposition.fields import GeopositionField |
Tony Mack | 50e1221 | 2015-03-09 13:03:56 -0400 | [diff] [blame] | 7 | from core.models import PlCoreBase,PlCoreBaseManager,PlCoreBaseDeletionManager |
| 8 | from core.models import Tag |
| 9 | from core.models.plcorebase import StrippedCharField |
Scott Baker | 5380c52 | 2014-06-06 14:49:43 -0700 | [diff] [blame] | 10 | from core.acl import AccessControlList |
Scott Baker | 86e132c | 2015-02-11 21:38:09 -0800 | [diff] [blame] | 11 | from xos.config import Config |
Sapan Bhatia | 1d1b2b1 | 2014-09-22 17:25:06 -0400 | [diff] [blame] | 12 | |
| 13 | config = Config() |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 14 | |
Tony Mack | 51c4a7d | 2014-11-30 15:33:35 -0500 | [diff] [blame] | 15 | class ControllerLinkDeletionManager(PlCoreBaseDeletionManager): |
Sapan Bhatia | c4b9807 | 2014-09-19 16:48:36 -0400 | [diff] [blame] | 16 | def get_queryset(self): |
Tony Mack | 06c8e47 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 17 | parent=super(ControllerLinkDeletionManager, self) |
Sapan Bhatia | d0a176c | 2014-09-23 13:14:31 -0400 | [diff] [blame] | 18 | try: |
| 19 | backend_type = config.observer_backend_type |
| 20 | except AttributeError: |
| 21 | backend_type = None |
| 22 | |
| 23 | parent_queryset = parent.get_queryset() if hasattr(parent, "get_queryset") else parent.get_query_set() |
| 24 | if (backend_type): |
Tony Mack | 51c4a7d | 2014-11-30 15:33:35 -0500 | [diff] [blame] | 25 | return parent_queryset.filter(Q(controller__backend_type=backend_type)) |
Sapan Bhatia | c4b9807 | 2014-09-19 16:48:36 -0400 | [diff] [blame] | 26 | else: |
Sapan Bhatia | d0a176c | 2014-09-23 13:14:31 -0400 | [diff] [blame] | 27 | return parent_queryset |
Sapan Bhatia | c4b9807 | 2014-09-19 16:48:36 -0400 | [diff] [blame] | 28 | |
| 29 | # deprecated in django 1.7 in favor of get_queryset(). |
| 30 | def get_query_set(self): |
| 31 | return self.get_queryset() |
| 32 | |
| 33 | |
Tony Mack | 51c4a7d | 2014-11-30 15:33:35 -0500 | [diff] [blame] | 34 | class ControllerDeletionManager(PlCoreBaseDeletionManager): |
Sapan Bhatia | 15fdcdb | 2014-09-19 16:48:11 -0400 | [diff] [blame] | 35 | def get_queryset(self): |
Tony Mack | 51c4a7d | 2014-11-30 15:33:35 -0500 | [diff] [blame] | 36 | parent=super(ControllerDeletionManager, self) |
Sapan Bhatia | d0a176c | 2014-09-23 13:14:31 -0400 | [diff] [blame] | 37 | |
| 38 | try: |
| 39 | backend_type = config.observer_backend_type |
| 40 | except AttributeError: |
| 41 | backend_type = None |
| 42 | |
| 43 | parent_queryset = parent.get_queryset() if hasattr(parent, "get_queryset") else parent.get_query_set() |
| 44 | |
| 45 | if backend_type: |
Sapan Bhatia | 40e1813 | 2014-10-08 09:38:21 -0400 | [diff] [blame] | 46 | return parent_queryset.filter(Q(backend_type=backend_type)) |
Sapan Bhatia | 15fdcdb | 2014-09-19 16:48:11 -0400 | [diff] [blame] | 47 | else: |
Sapan Bhatia | d0a176c | 2014-09-23 13:14:31 -0400 | [diff] [blame] | 48 | return parent_queryset |
Sapan Bhatia | 15fdcdb | 2014-09-19 16:48:11 -0400 | [diff] [blame] | 49 | |
| 50 | # deprecated in django 1.7 in favor of get_queryset(). |
| 51 | def get_query_set(self): |
| 52 | return self.get_queryset() |
| 53 | |
Tony Mack | 51c4a7d | 2014-11-30 15:33:35 -0500 | [diff] [blame] | 54 | class ControllerLinkManager(PlCoreBaseManager): |
Sapan Bhatia | 48df09f | 2014-09-19 16:47:40 -0400 | [diff] [blame] | 55 | def get_queryset(self): |
Tony Mack | 51c4a7d | 2014-11-30 15:33:35 -0500 | [diff] [blame] | 56 | parent=super(ControllerLinkManager, self) |
Sapan Bhatia | d0a176c | 2014-09-23 13:14:31 -0400 | [diff] [blame] | 57 | |
| 58 | try: |
| 59 | backend_type = config.observer_backend_type |
| 60 | except AttributeError: |
| 61 | backend_type = None |
| 62 | |
| 63 | parent_queryset = parent.get_queryset() if hasattr(parent, "get_queryset") else parent.get_query_set() |
| 64 | |
| 65 | if backend_type: |
Tony Mack | 51c4a7d | 2014-11-30 15:33:35 -0500 | [diff] [blame] | 66 | return parent_queryset.filter(Q(controller__backend_type=backend_type)) |
Sapan Bhatia | 48df09f | 2014-09-19 16:47:40 -0400 | [diff] [blame] | 67 | else: |
Sapan Bhatia | d0a176c | 2014-09-23 13:14:31 -0400 | [diff] [blame] | 68 | return parent_queryset |
Sapan Bhatia | 48df09f | 2014-09-19 16:47:40 -0400 | [diff] [blame] | 69 | |
| 70 | # deprecated in django 1.7 in favor of get_queryset(). |
| 71 | def get_query_set(self): |
| 72 | return self.get_queryset() |
| 73 | |
| 74 | |
Tony Mack | 51c4a7d | 2014-11-30 15:33:35 -0500 | [diff] [blame] | 75 | class ControllerManager(PlCoreBaseManager): |
Sapan Bhatia | ad6dbd8 | 2014-09-19 16:47:07 -0400 | [diff] [blame] | 76 | def get_queryset(self): |
Tony Mack | 06c8e47 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 77 | parent=super(ControllerManager, self) |
Sapan Bhatia | d0a176c | 2014-09-23 13:14:31 -0400 | [diff] [blame] | 78 | |
| 79 | try: |
| 80 | backend_type = config.observer_backend_type |
| 81 | except AttributeError: |
| 82 | backend_type = None |
| 83 | |
| 84 | parent_queryset = parent.get_queryset() if hasattr(parent, "get_queryset") else parent.get_query_set() |
| 85 | |
| 86 | if backend_type: |
Sapan Bhatia | 40e1813 | 2014-10-08 09:38:21 -0400 | [diff] [blame] | 87 | return parent_queryset.filter(Q(backend_type=backend_type)) |
Sapan Bhatia | ad6dbd8 | 2014-09-19 16:47:07 -0400 | [diff] [blame] | 88 | else: |
Sapan Bhatia | f77d01a | 2014-09-24 00:34:44 -0400 | [diff] [blame] | 89 | return parent_queryset |
Sapan Bhatia | ad6dbd8 | 2014-09-19 16:47:07 -0400 | [diff] [blame] | 90 | |
| 91 | # deprecated in django 1.7 in favor of get_queryset(). |
| 92 | def get_query_set(self): |
| 93 | return self.get_queryset() |
| 94 | |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 95 | class Site(PlCoreBase): |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 96 | """ |
| 97 | A logical grouping of Nodes that are co-located at the same geographic location, which also typically corresponds to the Nodes' location in the physical network. |
| 98 | """ |
Tony Mack | 50e1221 | 2015-03-09 13:03:56 -0400 | [diff] [blame] | 99 | name = StrippedCharField(max_length=200, help_text="Name for this Site") |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 100 | site_url = models.URLField(null=True, blank=True, max_length=512, help_text="Site's Home URL Page") |
| 101 | enabled = models.BooleanField(default=True, help_text="Status for this Site") |
Tony Mack | 6a38847 | 2015-08-04 17:21:55 -0400 | [diff] [blame] | 102 | hosts_nodes = models.BooleanField(default=True, help_text="Indicates whether or not the site host nodes") |
| 103 | hosts_users = models.BooleanField(default=True, help_text="Indicates whether or not the site manages user accounts") |
Siobhan Tully | 567e3e6 | 2013-06-21 18:03:16 -0400 | [diff] [blame] | 104 | location = GeopositionField() |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 105 | longitude = models.FloatField(null=True, blank=True) |
| 106 | latitude = models.FloatField(null=True, blank=True) |
Tony Mack | 50e1221 | 2015-03-09 13:03:56 -0400 | [diff] [blame] | 107 | login_base = StrippedCharField(max_length=50, unique=True, help_text="Prefix for Slices associated with this Site") |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 108 | is_public = models.BooleanField(default=True, help_text="Indicates the visibility of this site to other members") |
Tony Mack | 50e1221 | 2015-03-09 13:03:56 -0400 | [diff] [blame] | 109 | abbreviated_name = StrippedCharField(max_length=80) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 110 | |
Tony Mack | e4be32f | 2014-03-11 20:45:25 -0400 | [diff] [blame] | 111 | #deployments = models.ManyToManyField('Deployment', blank=True, related_name='sites') |
Tony Mack | 3066a95 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 112 | deployments = models.ManyToManyField('Deployment', through='SiteDeployment', blank=True, help_text="Select which sites are allowed to host nodes in this deployment", related_name='sites') |
Siobhan Tully | de5450d | 2013-06-21 11:35:33 -0400 | [diff] [blame] | 113 | tags = generic.GenericRelation(Tag) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 114 | |
| 115 | def __unicode__(self): return u'%s' % (self.name) |
| 116 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 117 | def can_update(self, user): |
Tony Mack | 3428e6e | 2015-02-08 21:38:41 -0500 | [diff] [blame] | 118 | return user.can_update_site(self, allow=['pi']) |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 119 | |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 120 | class SiteRole(PlCoreBase): |
| 121 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 122 | ROLE_CHOICES = (('admin','Admin'),('pi','PI'),('tech','Tech'),('billing','Billing')) |
Tony Mack | 50e1221 | 2015-03-09 13:03:56 -0400 | [diff] [blame] | 123 | role = StrippedCharField(choices=ROLE_CHOICES, unique=True, max_length=30) |
Siobhan Tully | bfd11dc | 2013-09-03 12:59:24 -0400 | [diff] [blame] | 124 | |
| 125 | def __unicode__(self): return u'%s' % (self.role) |
| 126 | |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 127 | class SitePrivilege(PlCoreBase): |
| 128 | |
Sapan Bhatia | 6bfa2ca | 2014-11-11 21:47:45 -0500 | [diff] [blame] | 129 | user = models.ForeignKey('User', related_name='siteprivileges') |
| 130 | site = models.ForeignKey('Site', related_name='siteprivileges') |
| 131 | role = models.ForeignKey('SiteRole',related_name='siteprivileges') |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 132 | |
| 133 | def __unicode__(self): return u'%s %s %s' % (self.site, self.user, self.role) |
| 134 | |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 135 | def save(self, *args, **kwds): |
Tony Mack | a6928d6 | 2015-03-29 09:29:12 -0400 | [diff] [blame] | 136 | if not self.user.is_active: |
| 137 | raise PermissionDenied, "Cannot modify role(s) of a disabled user" |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 138 | super(SitePrivilege, self).save(*args, **kwds) |
| 139 | |
| 140 | def delete(self, *args, **kwds): |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 141 | super(SitePrivilege, self).delete(*args, **kwds) |
| 142 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 143 | def can_update(self, user): |
Tony Mack | 3428e6e | 2015-02-08 21:38:41 -0500 | [diff] [blame] | 144 | return user.can_update_site(self, allow=['pi']) |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 145 | |
Tony Mack | 5b06147 | 2014-02-04 07:57:10 -0500 | [diff] [blame] | 146 | @staticmethod |
| 147 | def select_by_user(user): |
| 148 | if user.is_admin: |
| 149 | qs = SitePrivilege.objects.all() |
| 150 | else: |
| 151 | sp_ids = [sp.id for sp in SitePrivilege.objects.filter(user=user)] |
| 152 | qs = SitePrivilege.objects.filter(id__in=sp_ids) |
| 153 | return qs |
| 154 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 155 | class Deployment(PlCoreBase): |
Tony Mack | 06c8e47 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 156 | #objects = Controllermanager() |
Tony Mack | 51c4a7d | 2014-11-30 15:33:35 -0500 | [diff] [blame] | 157 | #deleted_objects = DeploymentDeletionManager() |
Tony Mack | 50e1221 | 2015-03-09 13:03:56 -0400 | [diff] [blame] | 158 | name = StrippedCharField(max_length=200, unique=True, help_text="Name of the Deployment") |
| 159 | #admin_user = StrippedCharField(max_length=200, null=True, blank=True, help_text="Username of an admin user at this deployment") |
| 160 | #admin_password = StrippedCharField(max_length=200, null=True, blank=True, help_text="Password of theadmin user at this deployment") |
| 161 | #admin_tenant = StrippedCharField(max_length=200, null=True, blank=True, help_text="Name of the tenant the admin user belongs to") |
| 162 | #auth_url = StrippedCharField(max_length=200, null=True, blank=True, help_text="Auth url for the deployment") |
| 163 | #backend_type = StrippedCharField(max_length=200, null=True, blank=True, help_text="Type of deployment, e.g. EC2, OpenStack, or OpenStack version") |
| 164 | #availability_zone = StrippedCharField(max_length=200, null=True, blank=True, help_text="OpenStack availability zone") |
Scott Baker | 5380c52 | 2014-06-06 14:49:43 -0700 | [diff] [blame] | 165 | |
| 166 | # smbaker: the default of 'allow all' is intended for evolutions of existing |
| 167 | # deployments. When new deployments are created via the GUI, they are |
| 168 | # given a default of 'allow site <site_of_creator>' |
| 169 | accessControl = models.TextField(max_length=200, blank=False, null=False, default="allow all", |
| 170 | help_text="Access control list that specifies which sites/users may use nodes in this deployment") |
Sapan Bhatia | e464c9c | 2015-10-07 17:31:58 +0200 | [diff] [blame] | 171 | def __init__(self, *args, **kwargs): |
| 172 | super(Deployment, self).__init__(*args, **kwargs) |
| 173 | self.no_sync=True |
Scott Baker | 5380c52 | 2014-06-06 14:49:43 -0700 | [diff] [blame] | 174 | |
| 175 | def get_acl(self): |
| 176 | return AccessControlList(self.accessControl) |
| 177 | |
| 178 | def test_acl(self, slice=None, user=None): |
| 179 | potential_users=[] |
| 180 | |
| 181 | if user: |
| 182 | potential_users.append(user) |
| 183 | |
| 184 | if slice: |
| 185 | potential_users.append(slice.creator) |
Sapan Bhatia | d2d5dd8 | 2014-11-11 21:10:07 -0500 | [diff] [blame] | 186 | for priv in slice.sliceprivileges.all(): |
Scott Baker | 5380c52 | 2014-06-06 14:49:43 -0700 | [diff] [blame] | 187 | if priv.user not in potential_users: |
| 188 | potential_users.append(priv.user) |
| 189 | |
| 190 | acl = self.get_acl() |
| 191 | for user in potential_users: |
| 192 | if acl.test(user) == "allow": |
| 193 | return True |
| 194 | |
| 195 | return False |
| 196 | |
Scott Baker | cb95fde | 2014-06-06 16:09:51 -0700 | [diff] [blame] | 197 | @staticmethod |
| 198 | def select_by_acl(user): |
| 199 | ids = [] |
Scott Baker | 5380c52 | 2014-06-06 14:49:43 -0700 | [diff] [blame] | 200 | for deployment in Deployment.objects.all(): |
Scott Baker | cb95fde | 2014-06-06 16:09:51 -0700 | [diff] [blame] | 201 | acl = deployment.get_acl() |
Scott Baker | 01a4cd0 | 2014-06-09 13:12:40 -0700 | [diff] [blame] | 202 | if acl.test(user) == "allow": |
Scott Baker | cb95fde | 2014-06-06 16:09:51 -0700 | [diff] [blame] | 203 | ids.append(deployment.id) |
| 204 | |
| 205 | return Deployment.objects.filter(id__in=ids) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 206 | |
Tony Mack | cf29cfa | 2015-02-05 06:13:04 -0500 | [diff] [blame] | 207 | def can_update(self, user): |
S.Çağlar Onur | b9cf323 | 2015-02-09 14:53:40 -0500 | [diff] [blame] | 208 | return user.can_update_deployment(self) |
Tony Mack | 3428e6e | 2015-02-08 21:38:41 -0500 | [diff] [blame] | 209 | |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 210 | def __unicode__(self): return u'%s' % (self.name) |
| 211 | |
Tony Mack | 68a1e42 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 212 | class DeploymentRole(PlCoreBase): |
| 213 | #objects = DeploymentLinkManager() |
| 214 | #deleted_objects = DeploymentLinkDeletionManager() |
| 215 | ROLE_CHOICES = (('admin','Admin'),) |
Tony Mack | 50e1221 | 2015-03-09 13:03:56 -0400 | [diff] [blame] | 216 | role = StrippedCharField(choices=ROLE_CHOICES, unique=True, max_length=30) |
Tony Mack | 68a1e42 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 217 | |
| 218 | def __unicode__(self): return u'%s' % (self.role) |
| 219 | |
| 220 | class DeploymentPrivilege(PlCoreBase): |
| 221 | #objects = DeploymentLinkManager() |
| 222 | #deleted_objects = DeploymentLinkDeletionManager() |
| 223 | |
| 224 | user = models.ForeignKey('User', related_name='deploymentprivileges') |
| 225 | deployment = models.ForeignKey('Deployment', related_name='deploymentprivileges') |
| 226 | role = models.ForeignKey('DeploymentRole',related_name='deploymentprivileges') |
Tony Mack | 5d93a9e | 2015-04-11 12:17:59 -0400 | [diff] [blame] | 227 | class Meta: |
| 228 | unique_together = ('user', 'deployment', 'role') |
Tony Mack | 68a1e42 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 229 | |
| 230 | def __unicode__(self): return u'%s %s %s' % (self.deployment, self.user, self.role) |
| 231 | |
| 232 | def can_update(self, user): |
S.Çağlar Onur | b9cf323 | 2015-02-09 14:53:40 -0500 | [diff] [blame] | 233 | return user.can_update_deployment(self) |
Tony Mack | 68a1e42 | 2014-12-08 16:43:02 -0500 | [diff] [blame] | 234 | |
| 235 | @staticmethod |
| 236 | def select_by_user(user): |
| 237 | if user.is_admin: |
| 238 | qs = DeploymentPrivilege.objects.all() |
| 239 | else: |
| 240 | dpriv_ids = [dp.id for dp in DeploymentPrivilege.objects.filter(user=user)] |
| 241 | qs = DeploymentPrivilege.objects.filter(id__in=dpriv_ids) |
| 242 | return qs |
| 243 | |
Tony Mack | 51c4a7d | 2014-11-30 15:33:35 -0500 | [diff] [blame] | 244 | class ControllerRole(PlCoreBase): |
Tony Mack | 06c8e47 | 2014-11-30 15:53:08 -0500 | [diff] [blame] | 245 | #objects = ControllerLinkManager() |
| 246 | #deleted_objects = ControllerLinkDeletionManager() |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 247 | |
| 248 | ROLE_CHOICES = (('admin','Admin'),) |
Tony Mack | 50e1221 | 2015-03-09 13:03:56 -0400 | [diff] [blame] | 249 | role = StrippedCharField(choices=ROLE_CHOICES, unique=True, max_length=30) |
Siobhan Tully | cf04fb6 | 2014-01-11 11:25:57 -0500 | [diff] [blame] | 250 | |
| 251 | def __unicode__(self): return u'%s' % (self.role) |
| 252 | |
Tony Mack | d14d48f | 2014-12-05 17:13:08 -0500 | [diff] [blame] | 253 | class Controller(PlCoreBase): |
| 254 | |
Tony Mack | 51c4a7d | 2014-11-30 15:33:35 -0500 | [diff] [blame] | 255 | objects = ControllerManager() |
| 256 | deleted_objects = ControllerDeletionManager() |
Sapan Bhatia | 51ddecd | 2014-09-22 14:54:56 -0400 | [diff] [blame] | 257 | |
Tony Mack | 50e1221 | 2015-03-09 13:03:56 -0400 | [diff] [blame] | 258 | name = StrippedCharField(max_length=200, unique=True, help_text="Name of the Controller") |
| 259 | backend_type = StrippedCharField(max_length=200, help_text="Type of compute controller, e.g. EC2, OpenStack, or OpenStack version") |
| 260 | version = StrippedCharField(max_length=200, help_text="Controller version") |
| 261 | auth_url = StrippedCharField(max_length=200, null=True, blank=True, help_text="Auth url for the compute controller") |
| 262 | admin_user = StrippedCharField(max_length=200, null=True, blank=True, help_text="Username of an admin user at this controller") |
| 263 | admin_password = StrippedCharField(max_length=200, null=True, blank=True, help_text="Password of theadmin user at this controller") |
| 264 | admin_tenant = StrippedCharField(max_length=200, null=True, blank=True, help_text="Name of the tenant the admin user belongs to") |
| 265 | domain = StrippedCharField(max_length=200, null=True, blank=True, help_text="Name of the domain this controller belongs to") |
svavilap | af91108 | 2015-10-13 23:50:03 -0400 | [diff] [blame] | 266 | rabbit_host = StrippedCharField(max_length=200, null=True, blank=True, help_text="IP address of rabbitmq server at this controller") |
| 267 | rabbit_user = StrippedCharField(max_length=200, null=True, blank=True, help_text="Username of rabbitmq server at this controller") |
| 268 | rabbit_password = StrippedCharField(max_length=200, null=True, blank=True, help_text="Password of rabbitmq server at this controller") |
Tony Mack | 5817cb4 | 2015-02-16 19:54:24 -0500 | [diff] [blame] | 269 | deployment = models.ForeignKey(Deployment,related_name='controllerdeployments') |
Sapan Bhatia | e464c9c | 2015-10-07 17:31:58 +0200 | [diff] [blame] | 270 | |
| 271 | def __init__(self, *args, **kwargs): |
| 272 | super(Controller, self).__init__(*args, **kwargs) |
| 273 | self.no_sync=True |
Tony Mack | 51c4a7d | 2014-11-30 15:33:35 -0500 | [diff] [blame] | 274 | |
Tony Mack | 625e10e | 2014-12-26 12:15:42 -0500 | [diff] [blame] | 275 | def __unicode__(self): return u'%s %s %s' % (self.name, self.backend_type, self.version) |
Tony Mack | 51c4a7d | 2014-11-30 15:33:35 -0500 | [diff] [blame] | 276 | |
Tony Mack | ba6de70 | 2015-09-13 23:59:47 +0000 | [diff] [blame] | 277 | @property |
| 278 | def auth_url_v3(self): |
| 279 | if self.auth_url and self.auth_url[-1] == '/': |
| 280 | return '{}/v3/'.format('/'.join(self.auth_url.split('/')[:-2])) |
| 281 | else: |
| 282 | return '{}/v3/'.format('/'.join(self.auth_url.split('/')[:-1])) |
| 283 | |
Tony Mack | 78fc136 | 2015-02-18 11:41:36 -0500 | [diff] [blame] | 284 | @staticmethod |
| 285 | def select_by_user(user): |
| 286 | |
| 287 | if user.is_admin: |
| 288 | qs = Controller.objects.all() |
| 289 | else: |
| 290 | deployments = [dp.deployment for dp in DeploymentPrivilege.objects.filter(user=user, role__role__in=['Admin', 'admin'])] |
| 291 | qs = Controller.objects.filter(deployment__in=deployments) |
Tony Mack | f8e8cd2 | 2015-02-18 13:54:58 -0500 | [diff] [blame] | 292 | return qs |
Tony Mack | 78fc136 | 2015-02-18 11:41:36 -0500 | [diff] [blame] | 293 | |
Tony Mack | 3066a95 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 294 | class SiteDeployment(PlCoreBase): |
Tony Mack | 51c4a7d | 2014-11-30 15:33:35 -0500 | [diff] [blame] | 295 | objects = ControllerLinkManager() |
Tony Mack | d14d48f | 2014-12-05 17:13:08 -0500 | [diff] [blame] | 296 | deleted_objects = ControllerLinkDeletionManager() |
Tony Mack | 51c4a7d | 2014-11-30 15:33:35 -0500 | [diff] [blame] | 297 | |
Tony Mack | 30dfcd7 | 2015-01-10 23:08:10 -0500 | [diff] [blame] | 298 | site = models.ForeignKey(Site,related_name='sitedeployments') |
| 299 | deployment = models.ForeignKey(Deployment,related_name='sitedeployments') |
| 300 | controller = models.ForeignKey(Controller, null=True, blank=True, related_name='sitedeployments') |
Tony Mack | 50e1221 | 2015-03-09 13:03:56 -0400 | [diff] [blame] | 301 | availability_zone = StrippedCharField(max_length=200, null=True, blank=True, help_text="OpenStack availability zone") |
Tony Mack | d14d48f | 2014-12-05 17:13:08 -0500 | [diff] [blame] | 302 | |
Tony Mack | 5d93a9e | 2015-04-11 12:17:59 -0400 | [diff] [blame] | 303 | class Meta: |
| 304 | unique_together = ('site', 'deployment', 'controller') |
Tony Mack | c8836df | 2015-03-09 17:13:14 -0400 | [diff] [blame] | 305 | |
Tony Mack | 81ad09e | 2015-01-03 17:26:06 -0500 | [diff] [blame] | 306 | def __unicode__(self): return u'%s %s' % (self.deployment, self.site) |
Tony Mack | 3066a95 | 2015-01-05 22:48:11 -0500 | [diff] [blame] | 307 | |
| 308 | class ControllerSite(PlCoreBase): |
| 309 | |
| 310 | site = models.ForeignKey(Site,related_name='controllersite') |
| 311 | controller = models.ForeignKey(Controller, null=True, blank=True, related_name='controllersite') |
Tony Mack | 50e1221 | 2015-03-09 13:03:56 -0400 | [diff] [blame] | 312 | tenant_id = StrippedCharField(null=True, blank=True, max_length=200, db_index=True, help_text="Keystone tenant id") |
Sapan Bhatia | 5b2ec27 | 2016-02-10 17:51:26 +0100 | [diff] [blame] | 313 | |
| 314 | def delete(self, *args, **kwds): |
Sapan Bhatia | 5b2ec27 | 2016-02-10 17:51:26 +0100 | [diff] [blame] | 315 | super(ControllerSite, self).delete(*args, **kwds) |
| 316 | |
Tony Mack | c8836df | 2015-03-09 17:13:14 -0400 | [diff] [blame] | 317 | |
Tony Mack | 5d93a9e | 2015-04-11 12:17:59 -0400 | [diff] [blame] | 318 | class Meta: |
| 319 | unique_together = ('site', 'controller') |
Sapan Bhatia | bcff59f | 2016-03-24 07:56:38 +0100 | [diff] [blame] | 320 | |
| 321 | class Diag(PlCoreBase): |
| 322 | name = StrippedCharField(max_length=200, help_text="Name of the synchronizer") |
| 323 | |
| 324 | @property |
| 325 | def enacted(self): |
| 326 | return None |