blob: db4b1ef49bde3718c1656b82e96d8c317b3f08bc [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 Tullybf1153a2013-05-27 20:53:48 -04004from core.models import Deployment
Siobhan Tully4bc09f22013-04-10 21:15:21 -04005
6class Site(PlCoreBase):
7
Tony Mack85d18832013-05-09 17:02:31 -04008 tenant_id = models.CharField(null=True, blank=True, max_length=200, help_text="Keystone tenant id")
Siobhan Tully4bc09f22013-04-10 21:15:21 -04009 name = models.CharField(max_length=200, help_text="Name for this Site")
10 site_url = models.URLField(null=True, blank=True, max_length=512, help_text="Site's Home URL Page")
11 enabled = models.BooleanField(default=True, help_text="Status for this Site")
12 longitude = models.FloatField(null=True, blank=True)
13 latitude = models.FloatField(null=True, blank=True)
14 login_base = models.CharField(max_length=50, unique=True, help_text="Prefix for Slices associated with this Site")
15 is_public = models.BooleanField(default=True, help_text="Indicates the visibility of this site to other members")
16 abbreviated_name = models.CharField(max_length=80)
17
Siobhan Tullybf1153a2013-05-27 20:53:48 -040018 deployments = models.ManyToManyField(Deployment, blank=True, related_name='sites')
Siobhan Tully4bc09f22013-04-10 21:15:21 -040019
20 def __unicode__(self): return u'%s' % (self.name)
21
Tony Mackd9b46072013-04-14 13:51:19 -040022 def save(self, *args, **kwds):
Siobhan Tully73291342013-05-10 10:50:08 -040023 if not hasattr(self, 'os_manager'):
Tony Mack89f70f12013-05-10 20:20:03 -040024 from openstack.manager import OpenStackManager
Siobhan Tully73291342013-05-10 10:50:08 -040025 setattr(self, 'os_manager', OpenStackManager())
Tony Mack89f70f12013-05-10 20:20:03 -040026 self.os_manager.save_site(self)
Tony Mackd9b46072013-04-14 13:51:19 -040027 super(Site, self).save(*args, **kwds)
28
29
30 def delete(self, *args, **kwds):
Siobhan Tully73291342013-05-10 10:50:08 -040031 if not hasattr(self, 'os_manager'):
Tony Mack89f70f12013-05-10 20:20:03 -040032 from openstack.manager import OpenStackManager
Siobhan Tully73291342013-05-10 10:50:08 -040033 setattr(self, 'os_manager', OpenStackManager())
Tony Mack89f70f12013-05-10 20:20:03 -040034 self.os_manager.delete_site(self)
Tony Mackd9b46072013-04-14 13:51:19 -040035 super(Site, self).delete(*args, **kwds)
36
37
Siobhan Tully4bc09f22013-04-10 21:15:21 -040038class SitePrivilege(PlCoreBase):
39
Siobhan Tully30fd4292013-05-10 08:59:56 -040040 user = models.ForeignKey('User', related_name='site_privileges')
Siobhan Tully4bc09f22013-04-10 21:15:21 -040041 site = models.ForeignKey('Site', related_name='site_privileges')
42 role = models.ForeignKey('Role')
43
44 def __unicode__(self): return u'%s %s %s' % (self.site, self.user, self.role)
45
Tony Mack00d361f2013-04-28 10:28:42 -040046 def save(self, *args, **kwds):
Siobhan Tully73291342013-05-10 10:50:08 -040047 if not hasattr(self, 'os_manager'):
Tony Mack89f70f12013-05-10 20:20:03 -040048 from openstack.manager import OpenStackManager
Siobhan Tully73291342013-05-10 10:50:08 -040049 setattr(self, 'os_manager', OpenStackManager())
50 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 -040051 super(SitePrivilege, self).save(*args, **kwds)
52
53 def delete(self, *args, **kwds):
Siobhan Tully73291342013-05-10 10:50:08 -040054 if not hasattr(self, 'os_manager'):
Tony Mack89f70f12013-05-10 20:20:03 -040055 from openstack.manager import OpenStackManager
Siobhan Tully73291342013-05-10 10:50:08 -040056 setattr(self, 'os_manager', OpenStackManager())
57 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 -040058 super(SitePrivilege, self).delete(*args, **kwds)
59
Siobhan Tully4bc09f22013-04-10 21:15:21 -040060