blob: 52420dfc255a4590b94cea6f27b4474c6f9ac56d [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 Tully4bc09f22013-04-10 21:15:21 -04004from plstackapi.core.models import PlCoreBase
Siobhan Tully4bc09f22013-04-10 21:15:21 -04005from plstackapi.core.models import Image
6from plstackapi.core.models import Key
7from plstackapi.core.models import Slice
8from plstackapi.core.models import Node
9from plstackapi.core.models import Site
10from plstackapi.core.models import DeploymentNetwork
Siobhan Tully4bc09f22013-04-10 21:15:21 -040011
12# Create your models here.
13class Sliver(PlCoreBase):
14 instance_id = models.CharField(max_length=200, help_text="Nova instance id")
15 name = models.CharField(max_length=200, help_text="Sliver name")
Tony Mack38119372013-04-30 18:17:38 -040016 instance_name = models.CharField(blank=True, null=True, max_length=200, help_text="OpenStack generated name")
Tony Mack1eeeae92013-04-16 23:04:44 -040017 ip = models.GenericIPAddressField(help_text="Sliver ip address", blank=True, null=True)
Tony Mack771f4b92013-04-12 01:49:57 -040018 image = models.ForeignKey(Image, related_name='slivers')
19 key = models.ForeignKey(Key, related_name='slivers')
20 slice = models.ForeignKey(Slice, related_name='slivers')
21 node = models.ForeignKey(Node, related_name='slivers')
Siobhan Tully53437282013-04-26 19:30:27 -040022 deploymentNetwork = models.ForeignKey(DeploymentNetwork, verbose_name='deployment', related_name='sliver_deploymentNetwork')
smbakerddc21c72013-05-05 13:58:52 -070023 numberCores = models.IntegerField(verbose_name="Number of Cores", help_text="Number of cores for sliver", default=0)
Siobhan Tully231f4c82013-05-02 05:47:24 -040024
Siobhan Tully4bc09f22013-04-10 21:15:21 -040025
Tony Mack29c287f2013-04-11 21:07:16 -040026 def __unicode__(self): return u'%s::%s' % (self.slice, self.deploymentNetwork)
Siobhan Tully4bc09f22013-04-10 21:15:21 -040027
Tony Mackcdec0902013-04-15 00:38:49 -040028 def save(self, *args, **kwds):
Tony Mack8e92dc52013-04-16 21:58:39 -040029 if not self.slice.subnet.exists():
Tony Mack2b241cf2013-04-16 21:57:55 -040030 raise exceptions.ValidationError, "Slice %s has no subnet" % self.slice.name
31
Tony Mack951dab42013-05-02 19:51:45 -040032 self.os_manager.save_sliver(self)
Tony Mackcdec0902013-04-15 00:38:49 -040033 super(Sliver, self).save(*args, **kwds)
34
35 def delete(self, *args, **kwds):
Tony Mack951dab42013-05-02 19:51:45 -040036 self.os_manager.delete_sliver(self)
Tony Mackcdec0902013-04-15 00:38:49 -040037 super(Sliver, self).delete(*args, **kwds)