Added support for Generic Tags. Tags can be applied to Node, Site, Slice, Sliver...
[plstackapi.git] / planetstack / core / models / slice.py
1 import os
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
12 # Create your models here.
13
14 class Slice(PlCoreBase):
15     tenant_id = models.CharField(max_length=200, help_text="Keystone tenant id")
16     name = models.CharField(unique=True, help_text="The Name of the Slice", max_length=80)
17     enabled = models.BooleanField(default=True, help_text="Status for this Slice")
18     omf_friendly = models.BooleanField()
19     description=models.TextField(blank=True,help_text="High level description of the slice and expected activities", max_length=1024)
20     slice_url = models.URLField(blank=True, max_length=512)
21     site = models.ForeignKey(Site, related_name='slices', help_text="The Site this Node belongs too")
22     network_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum network")
23     router_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum router id")
24     subnet_id = models.CharField(null=True, blank=True, max_length=256, help_text="Quantum subnet id")
25
26     tags = generic.GenericRelation(Tag)
27
28     serviceClass = models.ForeignKey(ServiceClass, related_name = "slices", null=True, default=ServiceClass.get_default)
29     creator = models.ForeignKey(User, related_name='slices', blank=True, null=True)
30
31     def __unicode__(self):  return u'%s' % (self.name)
32
33     def save(self, *args, **kwds):
34         if self.serviceClass is None:
35             # We allowed None=True for serviceClass because Django evolution
36             # will fail unless it is allowed. But, we we really don't want it to
37             # ever save None, so fix it up here.
38             self.serviceClass = ServiceClass.get_default()
39         if not self.creator and hasattr(self, 'caller'):
40             self.creator = self.caller
41         super(Slice, self).save(*args, **kwds)
42
43 class SliceMembership(PlCoreBase):
44     user = models.ForeignKey('User', related_name='slice_memberships')
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
50     def save(self, *args, **kwds):
51         super(SliceMembership, self).save(*args, **kwds)
52
53     def delete(self, *args, **kwds):
54         super(SliceMembership, self).delete(*args, **kwds)