Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1 | import os |
| 2 | from django.db import models |
| 3 | from plstackapi.core.models import PlCoreBase |
| 4 | from plstackapi.core.models import Site |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 5 | from plstackapi.core.models import PLUser |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 6 | from plstackapi.core.models import Role |
| 7 | from plstackapi.core.models import DeploymentNetwork |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 8 | # Create your models here. |
| 9 | |
| 10 | class Slice(PlCoreBase): |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 11 | tenant_id = models.CharField(max_length=200, help_text="Keystone tenant id") |
Tony Mack | 4895203 | 2013-04-12 11:49:34 -0400 | [diff] [blame] | 12 | name = models.CharField(unique=True, help_text="The Name of the Slice", max_length=80) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 13 | enabled = models.BooleanField(default=True, help_text="Status for this Slice") |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 14 | omf_friendly = models.BooleanField() |
| 15 | description=models.TextField(blank=True,help_text="High level description of the slice and expected activities", max_length=1024) |
| 16 | slice_url = models.URLField(blank=True, max_length=512) |
| 17 | site = models.ForeignKey(Site, related_name='slices', help_text="The Site this Node belongs too") |
| 18 | network_id = models.CharField(max_length=256, help_text="Quantum network") |
| 19 | router_id = models.CharField(max_length=256, help_text="Quantum router id") |
Tony Mack | f77b859 | 2013-05-07 11:09:24 -0400 | [diff] [blame^] | 20 | subnet_id = models.CharField(max_length=256, help_text="Quantum subnet id") |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 21 | |
Siobhan Tully | 231f4c8 | 2013-05-02 05:47:24 -0400 | [diff] [blame] | 22 | 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 Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 26 | def __unicode__(self): return u'%s' % (self.name) |
| 27 | |
Tony Mack | f77b859 | 2013-05-07 11:09:24 -0400 | [diff] [blame^] | 28 | |
| 29 | |
Tony Mack | 62bc59a | 2013-04-14 23:27:12 -0400 | [diff] [blame] | 30 | def save(self, *args, **kwds): |
Tony Mack | 93048c2 | 2013-05-02 11:20:26 -0400 | [diff] [blame] | 31 | self.os_manager.save_slice(self) |
Tony Mack | 62bc59a | 2013-04-14 23:27:12 -0400 | [diff] [blame] | 32 | super(Slice, self).save(*args, **kwds) |
| 33 | |
| 34 | def delete(self, *args, **kwds): |
Tony Mack | 93048c2 | 2013-05-02 11:20:26 -0400 | [diff] [blame] | 35 | self.os_manager.delete_slice(self) |
Tony Mack | 62bc59a | 2013-04-14 23:27:12 -0400 | [diff] [blame] | 36 | super(Slice, self).delete(*args, **kwds) |
| 37 | |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 38 | class SliceMembership(PlCoreBase): |
Siobhan Tully | 5343728 | 2013-04-26 19:30:27 -0400 | [diff] [blame] | 39 | user = models.ForeignKey('PLUser', related_name='slice_memberships') |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 40 | slice = models.ForeignKey('Slice', related_name='slice_memberships') |
| 41 | role = models.ForeignKey('Role') |
| 42 | |
| 43 | def __unicode__(self): return u'%s %s %s' % (self.slice, self.user, self.role) |
| 44 | |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 45 | def save(self, *args, **kwds): |
Tony Mack | 93048c2 | 2013-05-02 11:20:26 -0400 | [diff] [blame] | 46 | self.os_manager.driver.add_user_role(self.user.user_id, self.slice.tenant_id, self.role.role_type) |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 47 | super(SliceMembership, self).save(*args, **kwds) |
| 48 | |
| 49 | def delete(self, *args, **kwds): |
Tony Mack | 93048c2 | 2013-05-02 11:20:26 -0400 | [diff] [blame] | 50 | self.os_manager.driver.delete_user_role(self.user.user_id, self.slice.tenant_id, self.role.role_type) |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 51 | super(SliceMembership, self).delete(*args, **kwds) |