blob: 65d965b4033eb61c83e0838831690e9e9a3c1893 [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
Siobhan Tullycf04fb62014-01-11 11:25:57 -05004#from core.models import Deployment
Siobhan Tullyde5450d2013-06-21 11:35:33 -04005from core.models import Tag
6from django.contrib.contenttypes import generic
Siobhan Tully567e3e62013-06-21 18:03:16 -04007from geoposition.fields import GeopositionField
Siobhan Tully4bc09f22013-04-10 21:15:21 -04008
9class Site(PlCoreBase):
Siobhan Tullycf04fb62014-01-11 11:25:57 -050010 """
11 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.
12 """
Tony Mack85d18832013-05-09 17:02:31 -040013 tenant_id = models.CharField(null=True, blank=True, max_length=200, help_text="Keystone tenant id")
Siobhan Tully4bc09f22013-04-10 21:15:21 -040014 name = models.CharField(max_length=200, help_text="Name for this Site")
15 site_url = models.URLField(null=True, blank=True, max_length=512, help_text="Site's Home URL Page")
16 enabled = models.BooleanField(default=True, help_text="Status for this Site")
Siobhan Tully567e3e62013-06-21 18:03:16 -040017 location = GeopositionField()
Siobhan Tully4bc09f22013-04-10 21:15:21 -040018 longitude = models.FloatField(null=True, blank=True)
19 latitude = models.FloatField(null=True, blank=True)
20 login_base = models.CharField(max_length=50, unique=True, help_text="Prefix for Slices associated with this Site")
21 is_public = models.BooleanField(default=True, help_text="Indicates the visibility of this site to other members")
22 abbreviated_name = models.CharField(max_length=80)
23
Siobhan Tully320b4622014-01-17 15:11:14 -050024 deployments = models.ManyToManyField('Deployment', blank=True, related_name='sites')
Siobhan Tullycf04fb62014-01-11 11:25:57 -050025 #deployments = models.ManyToManyField('Deployment', through='SiteDeployments', blank=True)
Siobhan Tullyde5450d2013-06-21 11:35:33 -040026 tags = generic.GenericRelation(Tag)
Siobhan Tully4bc09f22013-04-10 21:15:21 -040027
28 def __unicode__(self): return u'%s' % (self.name)
29
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040030class SiteRole(PlCoreBase):
31
Siobhan Tullycf04fb62014-01-11 11:25:57 -050032 ROLE_CHOICES = (('admin','Admin'),('pi','PI'),('tech','Tech'),('billing','Billing'))
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040033 role = models.CharField(choices=ROLE_CHOICES, unique=True, max_length=30)
34
35 def __unicode__(self): return u'%s' % (self.role)
36
Siobhan Tully4bc09f22013-04-10 21:15:21 -040037class SitePrivilege(PlCoreBase):
38
Siobhan Tully30fd4292013-05-10 08:59:56 -040039 user = models.ForeignKey('User', related_name='site_privileges')
Siobhan Tully4bc09f22013-04-10 21:15:21 -040040 site = models.ForeignKey('Site', related_name='site_privileges')
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040041 role = models.ForeignKey('SiteRole')
Siobhan Tully4bc09f22013-04-10 21:15:21 -040042
43 def __unicode__(self): return u'%s %s %s' % (self.site, self.user, self.role)
44
Tony Mack00d361f2013-04-28 10:28:42 -040045 def save(self, *args, **kwds):
Tony Mack00d361f2013-04-28 10:28:42 -040046 super(SitePrivilege, self).save(*args, **kwds)
47
48 def delete(self, *args, **kwds):
Tony Mack00d361f2013-04-28 10:28:42 -040049 super(SitePrivilege, self).delete(*args, **kwds)
50
Siobhan Tullycf04fb62014-01-11 11:25:57 -050051class Deployment(PlCoreBase):
52 name = models.CharField(max_length=200, unique=True, help_text="Name of the Deployment")
53 #sites = models.ManyToManyField('Site', through='SiteDeployments', blank=True)
54
55 def __unicode__(self): return u'%s' % (self.name)
56
57
58class DeploymentRole(PlCoreBase):
59
60 ROLE_CHOICES = (('admin','Admin'),)
61 role = models.CharField(choices=ROLE_CHOICES, unique=True, max_length=30)
62
63 def __unicode__(self): return u'%s' % (self.role)
64
65class DeploymentPrivilege(PlCoreBase):
66
67 user = models.ForeignKey('User', related_name='deployment_privileges')
68 deployment = models.ForeignKey('Deployment', related_name='deployment_privileges')
69 role = models.ForeignKey('DeploymentRole')
70
71 def __unicode__(self): return u'%s %s %s' % (self.deployment, self.user, self.role)
72
73class SiteDeployments(PlCoreBase):
74 site = models.ForeignKey(Site)
75 deployment = models.ForeignKey(Deployment)
76
77 class Meta:
78 db_table = 'site_deployments'
79 #auto_created = Site
Siobhan Tully4bc09f22013-04-10 21:15:21 -040080