Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 1 | import os |
| 2 | from django.db import models |
Tony Mack | 2b241cf | 2013-04-16 21:57:55 -0400 | [diff] [blame] | 3 | from django.core import exceptions |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 4 | from core.models import PlCoreBase |
| 5 | from core.models import Image |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 6 | from core.models import Slice |
| 7 | from core.models import Node |
| 8 | from core.models import Site |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 9 | from core.models import Deployment |
Tony Mack | b0d9742 | 2013-06-10 09:57:45 -0400 | [diff] [blame] | 10 | from core.models import User |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 11 | |
| 12 | # Create your models here. |
| 13 | class Sliver(PlCoreBase): |
Tony Mack | 85d1883 | 2013-05-09 17:02:31 -0400 | [diff] [blame] | 14 | instance_id = models.CharField(null=True, blank=True, max_length=200, help_text="Nova instance id") |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 15 | name = models.CharField(max_length=200, help_text="Sliver name") |
Tony Mack | 3811937 | 2013-04-30 18:17:38 -0400 | [diff] [blame] | 16 | instance_name = models.CharField(blank=True, null=True, max_length=200, help_text="OpenStack generated name") |
Tony Mack | 1eeeae9 | 2013-04-16 23:04:44 -0400 | [diff] [blame] | 17 | ip = models.GenericIPAddressField(help_text="Sliver ip address", blank=True, null=True) |
Tony Mack | 771f4b9 | 2013-04-12 01:49:57 -0400 | [diff] [blame] | 18 | image = models.ForeignKey(Image, related_name='slivers') |
Tony Mack | b0d9742 | 2013-06-10 09:57:45 -0400 | [diff] [blame] | 19 | #key = models.ForeignKey(Key, related_name='slivers') |
| 20 | creator = models.ForeignKey(User, related_name='slivers', blank=True, null=True) |
Tony Mack | 771f4b9 | 2013-04-12 01:49:57 -0400 | [diff] [blame] | 21 | slice = models.ForeignKey(Slice, related_name='slivers') |
| 22 | node = models.ForeignKey(Node, related_name='slivers') |
Siobhan Tully | bf1153a | 2013-05-27 20:53:48 -0400 | [diff] [blame] | 23 | deploymentNetwork = models.ForeignKey(Deployment, verbose_name='deployment', related_name='sliver_deploymentNetwork') |
smbaker | ddc21c7 | 2013-05-05 13:58:52 -0700 | [diff] [blame] | 24 | numberCores = models.IntegerField(verbose_name="Number of Cores", help_text="Number of cores for sliver", default=0) |
Siobhan Tully | 231f4c8 | 2013-05-02 05:47:24 -0400 | [diff] [blame] | 25 | |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 26 | |
Siobhan Tully | 30fd429 | 2013-05-10 08:59:56 -0400 | [diff] [blame] | 27 | def __unicode__(self): return u'%s' % (self.instance_name) |
Siobhan Tully | 4bc09f2 | 2013-04-10 21:15:21 -0400 | [diff] [blame] | 28 | |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 29 | def save(self, *args, **kwds): |
Tony Mack | 1008202 | 2013-05-06 17:15:00 -0400 | [diff] [blame] | 30 | if not self.name: |
| 31 | self.name = self.slice.name |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 32 | if not hasattr(self, 'os_manager'): |
Tony Mack | 89f70f1 | 2013-05-10 20:20:03 -0400 | [diff] [blame] | 33 | from openstack.manager import OpenStackManager |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 34 | setattr(self, 'os_manager', OpenStackManager()) |
Tony Mack | 89f70f1 | 2013-05-10 20:20:03 -0400 | [diff] [blame] | 35 | self.os_manager.save_sliver(self) |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 36 | super(Sliver, self).save(*args, **kwds) |
| 37 | |
| 38 | def delete(self, *args, **kwds): |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 39 | if not hasattr(self, 'os_manager'): |
Tony Mack | 89f70f1 | 2013-05-10 20:20:03 -0400 | [diff] [blame] | 40 | from openstack.manager import OpenStackManager |
Siobhan Tully | 7329134 | 2013-05-10 10:50:08 -0400 | [diff] [blame] | 41 | setattr(self, 'os_manager', OpenStackManager()) |
Tony Mack | 89f70f1 | 2013-05-10 20:20:03 -0400 | [diff] [blame] | 42 | self.os_manager.delete_sliver(self) |
Tony Mack | cdec090 | 2013-04-15 00:38:49 -0400 | [diff] [blame] | 43 | super(Sliver, self).delete(*args, **kwds) |