2 from django.db import models
3 from core.models import PlCoreBase
4 from core.models import Site
5 from core.models import User
6 from core.models import Role
7 from core.models import Deployment
8 from core.models import ServiceClass
9 from core.models import Tag
10 from django.contrib.contenttypes import generic
11 from core.models import Service
13 # Create your models here.
15 class Slice(PlCoreBase):
16 tenant_id = models.CharField(max_length=200, help_text="Keystone tenant id")
17 name = models.CharField(unique=True, help_text="The Name of the Slice", max_length=80)
18 enabled = models.BooleanField(default=True, help_text="Status for this Slice")
19 omf_friendly = models.BooleanField()
20 description=models.TextField(blank=True,help_text="High level description of the slice and expected activities", max_length=1024)
21 slice_url = models.URLField(blank=True, max_length=512)
22 site = models.ForeignKey(Site, related_name='slices', help_text="The Site this Slice belongs to")
23 network_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum network")
24 router_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum router id")
25 subnet_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum subnet id")
26 service = models.ForeignKey(Service, related_name='service', null=True, blank=True)
28 tags = generic.GenericRelation(Tag)
30 serviceClass = models.ForeignKey(ServiceClass, related_name = "slices", null=True, default=ServiceClass.get_default)
31 creator = models.ForeignKey(User, related_name='slices', blank=True, null=True)
33 def __unicode__(self): return u'%s' % (self.name)
35 def save(self, *args, **kwds):
36 if self.serviceClass is None:
37 # We allowed None=True for serviceClass because Django evolution
38 # will fail unless it is allowed. But, we we really don't want it to
39 # ever save None, so fix it up here.
40 self.serviceClass = ServiceClass.get_default()
41 if not self.creator and hasattr(self, 'caller'):
42 self.creator = self.caller
43 super(Slice, self).save(*args, **kwds)
45 class SliceRole(PlCoreBase):
46 ROLE_CHOICES = (('admin','Admin'),('default','Default'))
48 role = models.CharField(choices=ROLE_CHOICES, unique=True, max_length=30)
50 def __unicode__(self): return u'%s' % (self.role)
52 class SlicePrivilege(PlCoreBase):
53 user = models.ForeignKey('User', related_name='slice_privileges')
54 slice = models.ForeignKey('Slice', related_name='slice_privileges')
55 role = models.ForeignKey('SliceRole')
57 def __unicode__(self): return u'%s %s %s' % (self.slice, self.user, self.role)