blob: ebf2ab93f25f8ec712a85204e9a5d348e6be902f [file] [log] [blame]
Siobhan Tully4bc09f22013-04-10 21:15:21 -04001import os
2from django.db import models
Siobhan Tully30fd4292013-05-10 08:59:56 -04003from core.models import PlCoreBase
4from core.models import DeploymentNetwork
Siobhan Tully4bc09f22013-04-10 21:15:21 -04005
6
7class Site(PlCoreBase):
8
Tony Mackcdec0902013-04-15 00:38:49 -04009 tenant_id = models.CharField(max_length=200, help_text="Keystone tenant id")
Siobhan Tully4bc09f22013-04-10 21:15:21 -040010 name = models.CharField(max_length=200, help_text="Name for this Site")
11 site_url = models.URLField(null=True, blank=True, max_length=512, help_text="Site's Home URL Page")
12 enabled = models.BooleanField(default=True, help_text="Status for this Site")
13 longitude = models.FloatField(null=True, blank=True)
14 latitude = models.FloatField(null=True, blank=True)
15 login_base = models.CharField(max_length=50, unique=True, help_text="Prefix for Slices associated with this Site")
16 is_public = models.BooleanField(default=True, help_text="Indicates the visibility of this site to other members")
17 abbreviated_name = models.CharField(max_length=80)
18
19 deployments = models.ManyToManyField(DeploymentNetwork, blank=True, related_name='sites')
20
21 def __unicode__(self): return u'%s' % (self.name)
22
Tony Mackd9b46072013-04-14 13:51:19 -040023 def save(self, *args, **kwds):
Tony Mack60722062013-05-02 10:57:04 -040024 self.os_manager.save_site(self)
Tony Mackd9b46072013-04-14 13:51:19 -040025 super(Site, self).save(*args, **kwds)
26
27
28 def delete(self, *args, **kwds):
Tony Mack60722062013-05-02 10:57:04 -040029 self.os_manager.delete_site(self)
Tony Mackd9b46072013-04-14 13:51:19 -040030 super(Site, self).delete(*args, **kwds)
31
32
Siobhan Tully4bc09f22013-04-10 21:15:21 -040033class SitePrivilege(PlCoreBase):
34
Siobhan Tully30fd4292013-05-10 08:59:56 -040035 user = models.ForeignKey('User', related_name='site_privileges')
Siobhan Tully4bc09f22013-04-10 21:15:21 -040036 site = models.ForeignKey('Site', related_name='site_privileges')
37 role = models.ForeignKey('Role')
38
39 def __unicode__(self): return u'%s %s %s' % (self.site, self.user, self.role)
40
Tony Mack00d361f2013-04-28 10:28:42 -040041 def save(self, *args, **kwds):
Siobhan Tully30fd4292013-05-10 08:59:56 -040042 self.os_manager.driver.add_user_role(self.user.kuser_id, self.site.tenant_id, self.role.role_type)
Tony Mack00d361f2013-04-28 10:28:42 -040043 super(SitePrivilege, self).save(*args, **kwds)
44
45 def delete(self, *args, **kwds):
Siobhan Tully30fd4292013-05-10 08:59:56 -040046 self.os_manager.driver.delete_user_role(self.user.kuser_id, self.site.tenant_id, self.role.role_type)
Tony Mack00d361f2013-04-28 10:28:42 -040047 super(SitePrivilege, self).delete(*args, **kwds)
48
Siobhan Tully4bc09f22013-04-10 21:15:21 -040049