blob: 712216702e07ff8e2745f48b08fee222c96f205d [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 Site
Siobhan Tully53437282013-04-26 19:30:27 -04005from plstackapi.core.models import PLUser
Siobhan Tully4bc09f22013-04-10 21:15:21 -04006from plstackapi.core.models import Role
7from plstackapi.core.models import DeploymentNetwork
Siobhan Tully4bc09f22013-04-10 21:15:21 -04008
9# Create your models here.
10
11class Slice(PlCoreBase):
Tony Mackcdec0902013-04-15 00:38:49 -040012 tenant_id = models.CharField(max_length=200, help_text="Keystone tenant id")
Tony Mack48952032013-04-12 11:49:34 -040013 name = models.CharField(unique=True, help_text="The Name of the Slice", max_length=80)
Siobhan Tully4bc09f22013-04-10 21:15:21 -040014 enabled = models.BooleanField(default=True, help_text="Status for this Slice")
Siobhan Tully4bc09f22013-04-10 21:15:21 -040015 omf_friendly = models.BooleanField()
16 description=models.TextField(blank=True,help_text="High level description of the slice and expected activities", max_length=1024)
17 slice_url = models.URLField(blank=True, max_length=512)
18 site = models.ForeignKey(Site, related_name='slices', help_text="The Site this Node belongs too")
19 network_id = models.CharField(max_length=256, help_text="Quantum network")
20 router_id = models.CharField(max_length=256, help_text="Quantum router id")
21
Siobhan Tully231f4c82013-05-02 05:47:24 -040022 SVC_CLASS_CHOICES = (('besteffort', 'Best Effort'), ('silver', 'Silver'), ('gold','Gold'))
23 serviceClass = models.CharField(verbose_name="Service Class",default="besteffort",help_text="The Service Class of this slice", max_length=30, choices=SVC_CLASS_CHOICES)
24
25
Siobhan Tully4bc09f22013-04-10 21:15:21 -040026 def __unicode__(self): return u'%s' % (self.name)
27
Tony Mack62bc59a2013-04-14 23:27:12 -040028 def save(self, *args, **kwds):
Tony Mack93048c22013-05-02 11:20:26 -040029 self.os_manager.save_slice(self)
Tony Mack62bc59a2013-04-14 23:27:12 -040030 super(Slice, self).save(*args, **kwds)
31
32 def delete(self, *args, **kwds):
Tony Mack93048c22013-05-02 11:20:26 -040033 self.os_manager.delete_slice(self)
Tony Mack62bc59a2013-04-14 23:27:12 -040034 super(Slice, self).delete(*args, **kwds)
35
Siobhan Tully4bc09f22013-04-10 21:15:21 -040036class SliceMembership(PlCoreBase):
Siobhan Tully53437282013-04-26 19:30:27 -040037 user = models.ForeignKey('PLUser', related_name='slice_memberships')
Siobhan Tully4bc09f22013-04-10 21:15:21 -040038 slice = models.ForeignKey('Slice', related_name='slice_memberships')
39 role = models.ForeignKey('Role')
40
41 def __unicode__(self): return u'%s %s %s' % (self.slice, self.user, self.role)
42
Tony Mack00d361f2013-04-28 10:28:42 -040043 def save(self, *args, **kwds):
Tony Mack93048c22013-05-02 11:20:26 -040044 self.os_manager.driver.add_user_role(self.user.user_id, self.slice.tenant_id, self.role.role_type)
Tony Mack00d361f2013-04-28 10:28:42 -040045 super(SliceMembership, self).save(*args, **kwds)
46
47 def delete(self, *args, **kwds):
Tony Mack93048c22013-05-02 11:20:26 -040048 self.os_manager.driver.delete_user_role(self.user.user_id, self.slice.tenant_id, self.role.role_type)
Tony Mack00d361f2013-04-28 10:28:42 -040049 super(SliceMembership, self).delete(*args, **kwds)