blob: ff074a6b90b5a8f2680c87561dbbe9d484e7dbd4 [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
6from core.models import Key
7from core.models import Slice
8from core.models import Node
9from core.models import Site
10from core.models import DeploymentNetwork
Siobhan Tully4bc09f22013-04-10 21:15:21 -040011
12# Create your models here.
13class Sliver(PlCoreBase):
Tony Mack85d18832013-05-09 17:02:31 -040014 instance_id = models.CharField(null=True, blank=True, max_length=200, help_text="Nova instance id")
Siobhan Tully4bc09f22013-04-10 21:15:21 -040015 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
Siobhan Tully30fd4292013-05-10 08:59:56 -040026 def __unicode__(self): return u'%s' % (self.instance_name)
Siobhan Tully4bc09f22013-04-10 21:15:21 -040027
Tony Mackcdec0902013-04-15 00:38:49 -040028 def save(self, *args, **kwds):
Tony Mack10082022013-05-06 17:15:00 -040029 if not self.name:
30 self.name = self.slice.name
Siobhan Tully73291342013-05-10 10:50:08 -040031 if not hasattr(self, 'os_manager'):
Tony Mack89f70f12013-05-10 20:20:03 -040032 from openstack.manager import OpenStackManager
Siobhan Tully73291342013-05-10 10:50:08 -040033 setattr(self, 'os_manager', OpenStackManager())
Tony Mack89f70f12013-05-10 20:20:03 -040034 self.os_manager.save_sliver(self)
Tony Mackcdec0902013-04-15 00:38:49 -040035 super(Sliver, self).save(*args, **kwds)
36
37 def delete(self, *args, **kwds):
Siobhan Tully73291342013-05-10 10:50:08 -040038 if not hasattr(self, 'os_manager'):
Tony Mack89f70f12013-05-10 20:20:03 -040039 from openstack.manager import OpenStackManager
Siobhan Tully73291342013-05-10 10:50:08 -040040 setattr(self, 'os_manager', OpenStackManager())
Tony Mack89f70f12013-05-10 20:20:03 -040041 self.os_manager.delete_sliver(self)
Tony Mackcdec0902013-04-15 00:38:49 -040042 super(Sliver, self).delete(*args, **kwds)