blob: 72ad66d382bdf5e7e68173e6e9f0e74abf2558b7 [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 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')
Tony Mackb0d97422013-06-10 09:57:45 -040019 #key = models.ForeignKey(Key, related_name='slivers')
20 creator = models.ForeignKey(User, related_name='slivers', blank=True, null=True)
Tony Mack771f4b92013-04-12 01:49:57 -040021 slice = models.ForeignKey(Slice, related_name='slivers')
22 node = models.ForeignKey(Node, related_name='slivers')
Siobhan Tullybf1153a2013-05-27 20:53:48 -040023 deploymentNetwork = models.ForeignKey(Deployment, verbose_name='deployment', related_name='sliver_deploymentNetwork')
smbakerddc21c72013-05-05 13:58:52 -070024 numberCores = models.IntegerField(verbose_name="Number of Cores", help_text="Number of cores for sliver", default=0)
Siobhan Tully231f4c82013-05-02 05:47:24 -040025
Siobhan Tully4bc09f22013-04-10 21:15:21 -040026
Siobhan Tully30fd4292013-05-10 08:59:56 -040027 def __unicode__(self): return u'%s' % (self.instance_name)
Siobhan Tully4bc09f22013-04-10 21:15:21 -040028
Tony Mackcdec0902013-04-15 00:38:49 -040029 def save(self, *args, **kwds):
Tony Mack10082022013-05-06 17:15:00 -040030 if not self.name:
31 self.name = self.slice.name
Siobhan Tully73291342013-05-10 10:50:08 -040032 if not hasattr(self, 'os_manager'):
Tony Mack89f70f12013-05-10 20:20:03 -040033 from openstack.manager import OpenStackManager
Siobhan Tully73291342013-05-10 10:50:08 -040034 setattr(self, 'os_manager', OpenStackManager())
Tony Mack89f70f12013-05-10 20:20:03 -040035 self.os_manager.save_sliver(self)
Tony Mackcdec0902013-04-15 00:38:49 -040036 super(Sliver, self).save(*args, **kwds)
37
38 def delete(self, *args, **kwds):
Siobhan Tully73291342013-05-10 10:50:08 -040039 if not hasattr(self, 'os_manager'):
Tony Mack89f70f12013-05-10 20:20:03 -040040 from openstack.manager import OpenStackManager
Siobhan Tully73291342013-05-10 10:50:08 -040041 setattr(self, 'os_manager', OpenStackManager())
Tony Mack89f70f12013-05-10 20:20:03 -040042 self.os_manager.delete_sliver(self)
Tony Mackcdec0902013-04-15 00:38:49 -040043 super(Sliver, self).delete(*args, **kwds)