Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1 | import os |
| 2 | from django.db import models |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 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 DeploymentNetwork |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 8 | |
| 9 | # Create your models here. |
| 10 | |
| 11 | class Slice(PlCoreBase): |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 12 | tenant_id = models.CharField(max_length=200, help_text="Keystone tenant id") |
Tony Mack | 4895203 | 2013-04-12 11:49:34 -0400 | [diff] [blame] | 13 | 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] | 14 | enabled = models.BooleanField(default=True, help_text="Status for this Slice") |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 15 | 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") |
Tony Mack | 85d1883 | 2013-05-09 17:02:31 -0400 | [diff] [blame] | 19 | network_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum network") |
| 20 | router_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum router id") |
| 21 | subnet_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum subnet id") |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 22 | |
Siobhan Tully | 231f4c8 | 2013-05-02 05:47:24 -0400 | [diff] [blame] | 23 | SVC_CLASS_CHOICES = (('besteffort', 'Best Effort'), ('silver', 'Silver'), ('gold','Gold')) |
| 24 | serviceClass = models.CharField(verbose_name="Service Class",default="besteffort",help_text="The Service Class of this slice", max_length=30, choices=SVC_CLASS_CHOICES) |
| 25 | |
| 26 | |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 27 | def __unicode__(self): return u'%s' % (self.name) |
| 28 | |
Tony Mack | 62bc59a | 2013-04-14 23:27:12 -0400 | [diff] [blame] | 29 | def save(self, *args, **kwds): |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 30 | if not hasattr(self, 'os_manager'): |
Tony Mack | 89f70f1 | 2013-05-10 20:20:03 -0400 | [diff] [blame] | 31 | from openstack.manager import OpenStackManager |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 32 | setattr(self, 'os_manager', OpenStackManager()) |
Tony Mack | 89f70f1 | 2013-05-10 20:20:03 -0400 | [diff] [blame] | 33 | self.os_manager.save_slice(self) |
Tony Mack | 62bc59a | 2013-04-14 23:27:12 -0400 | [diff] [blame] | 34 | super(Slice, self).save(*args, **kwds) |
| 35 | |
| 36 | def delete(self, *args, **kwds): |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 37 | if not hasattr(self, 'os_manager'): |
Tony Mack | 89f70f1 | 2013-05-10 20:20:03 -0400 | [diff] [blame] | 38 | from openstack.manager import OpenStackManager |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 39 | setattr(self, 'os_manager', OpenStackManager()) |
Tony Mack | 89f70f1 | 2013-05-10 20:20:03 -0400 | [diff] [blame] | 40 | self.os_manager.delete_slice(self) |
Tony Mack | 62bc59a | 2013-04-14 23:27:12 -0400 | [diff] [blame] | 41 | super(Slice, self).delete(*args, **kwds) |
| 42 | |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 43 | class SliceMembership(PlCoreBase): |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 44 | user = models.ForeignKey('User', related_name='slice_memberships') |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 45 | slice = models.ForeignKey('Slice', related_name='slice_memberships') |
| 46 | role = models.ForeignKey('Role') |
| 47 | |
| 48 | def __unicode__(self): return u'%s %s %s' % (self.slice, self.user, self.role) |
| 49 | |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 50 | def save(self, *args, **kwds): |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 51 | if not hasattr(self, 'os_manager'): |
Tony Mack | 89f70f1 | 2013-05-10 20:20:03 -0400 | [diff] [blame] | 52 | from openstack.manager import OpenStackManager |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 53 | setattr(self, 'os_manager', OpenStackManager()) |
Siobhan Tully | aa1bcd5 | 2013-05-10 12:43:09 -0400 | [diff] [blame] | 54 | if self.os_manager.driver: |
| 55 | self.os_manager.driver.add_user_role(self.user.kuser_id, self.slice.tenant_id, self.role.role_type) |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 56 | super(SliceMembership, self).save(*args, **kwds) |
| 57 | |
| 58 | def delete(self, *args, **kwds): |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 59 | if not hasattr(self, 'os_manager'): |
Tony Mack | 89f70f1 | 2013-05-10 20:20:03 -0400 | [diff] [blame] | 60 | from openstack.manager import OpenStackManager |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 61 | setattr(self, 'os_manager', OpenStackManager()) |
Siobhan Tully | aa1bcd5 | 2013-05-10 12:43:09 -0400 | [diff] [blame] | 62 | if self.os_manager.driver: |
| 63 | self.os_manager.driver.delete_user_role(self.user.kuser_id, self.slice.tenant_id, self.role.role_type) |
Tony Mack | 00d361f | 2013-04-28 10:28:42 -0400 | [diff] [blame] | 64 | super(SliceMembership, self).delete(*args, **kwds) |