blob: edbe824493600f556341158e51cb412294fd5eb8 [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
7from 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")
Tony Mack85d18832013-05-09 17:02:31 -040019 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 Tully4bc09f22013-04-10 21:15:21 -040022
Siobhan Tully231f4c82013-05-02 05:47:24 -040023 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 Tully4bc09f22013-04-10 21:15:21 -040027 def __unicode__(self): return u'%s' % (self.name)
28
Tony Mack62bc59a2013-04-14 23:27:12 -040029 def save(self, *args, **kwds):
Siobhan Tully73291342013-05-10 10:50:08 -040030 if not hasattr(self, 'os_manager'):
Tony Mack89f70f12013-05-10 20:20:03 -040031 from openstack.manager import OpenStackManager
Siobhan Tully73291342013-05-10 10:50:08 -040032 setattr(self, 'os_manager', OpenStackManager())
Tony Mack89f70f12013-05-10 20:20:03 -040033 self.os_manager.save_slice(self)
Tony Mack62bc59a2013-04-14 23:27:12 -040034 super(Slice, self).save(*args, **kwds)
35
36 def delete(self, *args, **kwds):
Siobhan Tully73291342013-05-10 10:50:08 -040037 if not hasattr(self, 'os_manager'):
Tony Mack89f70f12013-05-10 20:20:03 -040038 from openstack.manager import OpenStackManager
Siobhan Tully73291342013-05-10 10:50:08 -040039 setattr(self, 'os_manager', OpenStackManager())
Tony Mack89f70f12013-05-10 20:20:03 -040040 self.os_manager.delete_slice(self)
Tony Mack62bc59a2013-04-14 23:27:12 -040041 super(Slice, self).delete(*args, **kwds)
42
Siobhan Tully4bc09f22013-04-10 21:15:21 -040043class SliceMembership(PlCoreBase):
Siobhan Tully30fd4292013-05-10 08:59:56 -040044 user = models.ForeignKey('User', related_name='slice_memberships')
Siobhan Tully4bc09f22013-04-10 21:15:21 -040045 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 Mack00d361f2013-04-28 10:28:42 -040050 def save(self, *args, **kwds):
Siobhan Tully73291342013-05-10 10:50:08 -040051 if not hasattr(self, 'os_manager'):
Tony Mack89f70f12013-05-10 20:20:03 -040052 from openstack.manager import OpenStackManager
Siobhan Tully73291342013-05-10 10:50:08 -040053 setattr(self, 'os_manager', OpenStackManager())
Siobhan Tullyaa1bcd52013-05-10 12:43:09 -040054 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 Mack00d361f2013-04-28 10:28:42 -040056 super(SliceMembership, self).save(*args, **kwds)
57
58 def delete(self, *args, **kwds):
Siobhan Tully73291342013-05-10 10:50:08 -040059 if not hasattr(self, 'os_manager'):
Tony Mack89f70f12013-05-10 20:20:03 -040060 from openstack.manager import OpenStackManager
Siobhan Tully73291342013-05-10 10:50:08 -040061 setattr(self, 'os_manager', OpenStackManager())
Siobhan Tullyaa1bcd52013-05-10 12:43:09 -040062 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 Mack00d361f2013-04-28 10:28:42 -040064 super(SliceMembership, self).delete(*args, **kwds)