Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1 | import os |
| 2 | from django.db import models |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 3 | from core.models import PlCoreBase |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 4 | from core.models import Deployment |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 5 | |
| 6 | class Site(PlCoreBase): |
| 7 | |
Tony Mack | 85d1883 | 2013-05-09 17:02:31 -0400 | [diff] [blame] | 8 | tenant_id = models.CharField(null=True, blank=True, max_length=200, help_text="Keystone tenant id") |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 9 | 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 Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 18 | deployments = models.ManyToManyField(Deployment, blank=True, related_name='sites') |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 19 | |
| 20 | def __unicode__(self): return u'%s' % (self.name) |
| 21 | |
Tony Mack | d9b4607 | 2013-04-14 13:51:19 -0400 | [diff] [blame] | 22 | def save(self, *args, **kwds): |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 23 | if not hasattr(self, 'os_manager'): |
Tony Mack | 89f70f1 | 2013-05-10 20:20:03 -0400 | [diff] [blame] | 24 | from openstack.manager import OpenStackManager |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 25 | setattr(self, 'os_manager', OpenStackManager()) |
Tony Mack | 89f70f1 | 2013-05-10 20:20:03 -0400 | [diff] [blame] | 26 | self.os_manager.save_site(self) |
Tony Mack | d9b4607 | 2013-04-14 13:51:19 -0400 | [diff] [blame] | 27 | super(Site, self).save(*args, **kwds) |
| 28 | |
| 29 | |
| 30 | def delete(self, *args, **kwds): |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 31 | if not hasattr(self, 'os_manager'): |
Tony Mack | 89f70f1 | 2013-05-10 20:20:03 -0400 | [diff] [blame] | 32 | from openstack.manager import OpenStackManager |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 33 | setattr(self, 'os_manager', OpenStackManager()) |
Tony Mack | 89f70f1 | 2013-05-10 20:20:03 -0400 | [diff] [blame] | 34 | self.os_manager.delete_site(self) |
Tony Mack | d9b4607 | 2013-04-14 13:51:19 -0400 | [diff] [blame] | 35 | super(Site, self).delete(*args, **kwds) |
| 36 | |
| 37 | |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 38 | class SitePrivilege(PlCoreBase): |
| 39 | |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 40 | user = models.ForeignKey('User', related_name='site_privileges') |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 41 | 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 Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 46 | def save(self, *args, **kwds): |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 47 | if not hasattr(self, 'os_manager'): |
Tony Mack | 89f70f1 | 2013-05-10 20:20:03 -0400 | [diff] [blame] | 48 | from openstack.manager import OpenStackManager |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 49 | 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 Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 51 | super(SitePrivilege, self).save(*args, **kwds) |
| 52 | |
| 53 | def delete(self, *args, **kwds): |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 54 | if not hasattr(self, 'os_manager'): |
Tony Mack | 89f70f1 | 2013-05-10 20:20:03 -0400 | [diff] [blame] | 55 | from openstack.manager import OpenStackManager |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 56 | 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 Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 58 | super(SitePrivilege, self).delete(*args, **kwds) |
| 59 | |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 60 | |