blob: 67257af66e8121966647cf39102f852958ff20c4 [file] [log] [blame]
Siobhan Tully4bc09f22013-04-10 21:15:21 -04001import os
2from django.db import models
3from plstackapi.core.models import PlCoreBase
4from plstackapi.core.models import DeploymentNetwork
Siobhan Tully4bc09f22013-04-10 21:15:21 -04005from plstackapi.openstack.driver import OpenStackDriver
6
7# Create your models here.
8
9
10class Site(PlCoreBase):
11
Tony Mackcdec0902013-04-15 00:38:49 -040012 tenant_id = models.CharField(max_length=200, help_text="Keystone tenant id")
Siobhan Tully4bc09f22013-04-10 21:15:21 -040013 name = models.CharField(max_length=200, help_text="Name for this Site")
14 site_url = models.URLField(null=True, blank=True, max_length=512, help_text="Site's Home URL Page")
15 enabled = models.BooleanField(default=True, help_text="Status for this Site")
16 longitude = models.FloatField(null=True, blank=True)
17 latitude = models.FloatField(null=True, blank=True)
18 login_base = models.CharField(max_length=50, unique=True, help_text="Prefix for Slices associated with this Site")
19 is_public = models.BooleanField(default=True, help_text="Indicates the visibility of this site to other members")
20 abbreviated_name = models.CharField(max_length=80)
21
22 deployments = models.ManyToManyField(DeploymentNetwork, blank=True, related_name='sites')
23
24 def __unicode__(self): return u'%s' % (self.name)
25
Tony Mackd9b46072013-04-14 13:51:19 -040026 def save(self, *args, **kwds):
27 driver = OpenStackDriver()
28 if not self.tenant_id:
29 tenant = driver.create_tenant(tenant_name=self.login_base,
30 description=self.name,
31 enabled=self.enabled)
32 self.tenant_id = tenant.id
33 # update the record
34 if self.id:
35 driver.update_tenant(self.tenant_id,
36 name=self.login_base,
37 description=self.name,
38 enabled=self.enabled)
39
40 super(Site, self).save(*args, **kwds)
41
42
43 def delete(self, *args, **kwds):
44 driver = OpenStackDriver()
45 if self.tenant_id:
46 driver.delete_tenant(self.tenant_id)
47 super(Site, self).delete(*args, **kwds)
48
49
Siobhan Tully4bc09f22013-04-10 21:15:21 -040050class SitePrivilege(PlCoreBase):
51
52 user = models.ForeignKey('User', related_name='site_privileges')
53 site = models.ForeignKey('Site', related_name='site_privileges')
54 role = models.ForeignKey('Role')
55
56 def __unicode__(self): return u'%s %s %s' % (self.site, self.user, self.role)
57
Siobhan Tully4bc09f22013-04-10 21:15:21 -040058