blob: 9c00cee7de332234877ab00dbde70fce97aa6af5 [file] [log] [blame]
Siobhan Tully4bc09f22013-04-10 21:15:21 -04001import os
2from django.db import models
Tony Mack2b241cf2013-04-16 21:57:55 -04003from django.core import exceptions
Siobhan Tully30fd4292013-05-10 08:59:56 -04004from core.models import PlCoreBase
5from core.models import Image
Siobhan Tully30fd4292013-05-10 08:59:56 -04006from core.models import Slice
7from core.models import Node
8from core.models import Site
Siobhan Tullybf1153a2013-05-27 20:53:48 -04009from core.models import Deployment
Tony Mackb0d97422013-06-10 09:57:45 -040010from core.models import User
Siobhan Tullyde5450d2013-06-21 11:35:33 -040011from core.models import Tag
12from django.contrib.contenttypes import generic
Siobhan Tully4bc09f22013-04-10 21:15:21 -040013
14# Create your models here.
15class Sliver(PlCoreBase):
Tony Mack85d18832013-05-09 17:02:31 -040016 instance_id = models.CharField(null=True, blank=True, max_length=200, help_text="Nova instance id")
Siobhan Tully4bc09f22013-04-10 21:15:21 -040017 name = models.CharField(max_length=200, help_text="Sliver name")
Tony Mack38119372013-04-30 18:17:38 -040018 instance_name = models.CharField(blank=True, null=True, max_length=200, help_text="OpenStack generated name")
Tony Mack1eeeae92013-04-16 23:04:44 -040019 ip = models.GenericIPAddressField(help_text="Sliver ip address", blank=True, null=True)
Tony Mack771f4b92013-04-12 01:49:57 -040020 image = models.ForeignKey(Image, related_name='slivers')
Tony Mackb0d97422013-06-10 09:57:45 -040021 #key = models.ForeignKey(Key, related_name='slivers')
22 creator = models.ForeignKey(User, related_name='slivers', blank=True, null=True)
Tony Mack771f4b92013-04-12 01:49:57 -040023 slice = models.ForeignKey(Slice, related_name='slivers')
24 node = models.ForeignKey(Node, related_name='slivers')
Siobhan Tullybf1153a2013-05-27 20:53:48 -040025 deploymentNetwork = models.ForeignKey(Deployment, verbose_name='deployment', related_name='sliver_deploymentNetwork')
smbakerddc21c72013-05-05 13:58:52 -070026 numberCores = models.IntegerField(verbose_name="Number of Cores", help_text="Number of cores for sliver", default=0)
Siobhan Tullyde5450d2013-06-21 11:35:33 -040027 tags = generic.GenericRelation(Tag)
Siobhan Tully4bc09f22013-04-10 21:15:21 -040028
Scott Baker3015c762013-08-23 10:28:07 -070029 def __unicode__(self):
30 if self.instance_name:
31 return u'%s' % (self.instance_name)
32 elif self.id:
33 return u'uninstantiated-%s' % str(self.id)
34 elif self.slice:
35 return u'unsaved-sliver on %s' % self.slice.name
36 else:
37 return u'unsaved-sliver'
38
Siobhan Tully4bc09f22013-04-10 21:15:21 -040039
Tony Mackcdec0902013-04-15 00:38:49 -040040 def save(self, *args, **kwds):
Tony Mack10082022013-05-06 17:15:00 -040041 if not self.name:
42 self.name = self.slice.name
Tony Mack2bd5b412013-06-11 21:05:06 -040043 if not self.creator and hasattr(self, 'caller'):
44 self.creator = self.caller
Tony Mackcdec0902013-04-15 00:38:49 -040045 super(Sliver, self).save(*args, **kwds)