blob: e584c075a2f79368b855e01a1ef035c612b7e3d3 [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 Site
5from core.models import User
6from core.models import Role
Siobhan Tullybf1153a2013-05-27 20:53:48 -04007from core.models import Deployment
Scott Bakere8d596f2013-05-13 23:17:13 -07008from core.models import ServiceClass
Siobhan Tullyde5450d2013-06-21 11:35:33 -04009from core.models import Tag
10from django.contrib.contenttypes import generic
Siobhan Tully4bc09f22013-04-10 21:15:21 -040011
12# Create your models here.
13
14class Slice(PlCoreBase):
Tony Mackcdec0902013-04-15 00:38:49 -040015 tenant_id = models.CharField(max_length=200, help_text="Keystone tenant id")
Tony Mack48952032013-04-12 11:49:34 -040016 name = models.CharField(unique=True, help_text="The Name of the Slice", max_length=80)
Siobhan Tully4bc09f22013-04-10 21:15:21 -040017 enabled = models.BooleanField(default=True, help_text="Status for this Slice")
Siobhan Tully4bc09f22013-04-10 21:15:21 -040018 omf_friendly = models.BooleanField()
19 description=models.TextField(blank=True,help_text="High level description of the slice and expected activities", max_length=1024)
20 slice_url = models.URLField(blank=True, max_length=512)
21 site = models.ForeignKey(Site, related_name='slices', help_text="The Site this Node belongs too")
Tony Mack85d18832013-05-09 17:02:31 -040022 network_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum network")
23 router_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum router id")
24 subnet_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum subnet id")
Siobhan Tully4bc09f22013-04-10 21:15:21 -040025
Siobhan Tullyde5450d2013-06-21 11:35:33 -040026 tags = generic.GenericRelation(Tag)
27
Scott Bakere8d596f2013-05-13 23:17:13 -070028 serviceClass = models.ForeignKey(ServiceClass, related_name = "slices", null=True, default=ServiceClass.get_default)
Tony Mack2bd5b412013-06-11 21:05:06 -040029 creator = models.ForeignKey(User, related_name='slices', blank=True, null=True)
Siobhan Tully231f4c82013-05-02 05:47:24 -040030
Siobhan Tully4bc09f22013-04-10 21:15:21 -040031 def __unicode__(self): return u'%s' % (self.name)
32
Tony Mack62bc59a2013-04-14 23:27:12 -040033 def save(self, *args, **kwds):
Scott Bakere8d596f2013-05-13 23:17:13 -070034 if self.serviceClass is None:
35 # We allowed None=True for serviceClass because Django evolution
36 # will fail unless it is allowed. But, we we really don't want it to
37 # ever save None, so fix it up here.
38 self.serviceClass = ServiceClass.get_default()
Tony Mack2bd5b412013-06-11 21:05:06 -040039 if not self.creator and hasattr(self, 'caller'):
40 self.creator = self.caller
Tony Mack62bc59a2013-04-14 23:27:12 -040041 super(Slice, self).save(*args, **kwds)
42
Siobhan Tullybfd11dc2013-09-03 12:59:24 -040043class SliceRole(PlCoreBase):
44 ROLE_CHOICES = (('admin','Admin'),('default','Default'))
45
46 role = models.CharField(choices=ROLE_CHOICES, unique=True, max_length=30)
47
48 def __unicode__(self): return u'%s' % (self.role)
49
50class SlicePrivilege(PlCoreBase):
51 user = models.ForeignKey('User', related_name='slice_privileges')
52 slice = models.ForeignKey('Slice', related_name='slice_privileges')
53 role = models.ForeignKey('SliceRole')
Siobhan Tully4bc09f22013-04-10 21:15:21 -040054
55 def __unicode__(self): return u'%s %s %s' % (self.slice, self.user, self.role)